Newer
Older
GHFX_REFACTOR / PATM_Forms / F_PATMTitle.cs
wxn on 2 Nov 2016 5 KB 提交
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using System.IO;
using System.Windows.Forms.DataVisualization.Charting;

namespace Cyberpipe.PATM_Forms
{
    public partial class F_PATMTitle : Office2007Form
    {
        string tablename = "";
        Image savedimg = null;
        Chart savedchart = null;
        public F_PATMTitle(string type,Image img)
        {
            InitializeComponent();

            //初始化comboBox
            initProjects(type);
            savedimg = img;
        }
        public F_PATMTitle(String type, Chart chart) { 
            InitializeComponent();

            //初始化comboBox
            initProjects(type);
            savedchart = chart;
        }
        public void initProjects(string type)
        {
            //projectLists.Items.Clear();
            if (type == "R")
            {//路由
                tablename = "casic_patm_route";
                //初始化textbox 
                textBoxX1.Text = "路由专题图" + DateTime.Now.ToString("yyyyMMdd");
            }
            else if (type == "F")
            { //配件 
                tablename = "casic_patm_fittings";
                //初始化textbox 
                textBoxX1.Text = "配件专题图" + DateTime.Now.ToString("yyyyMMdd");
            }
            else if (type == "S")
            {//统计图
                tablename = "casic_patm_statistic";
                //初始化textbox 
                textBoxX1.Text = "统计专题图" + DateTime.Now.ToString("yyyyMMdd");
            }
            //string sql = "select " + tablename + ".\"NODENAME\" from " + tablename + " where "
            //    + tablename + ".\"NODEPID\" = 0";
            //DataTable table = OledbHelper.QueryTable(sql);

            //if (table != null)
            //{
            //    for (int i = 0; i < table.Rows.Count; i++)
            //    {
            //        projectLists.Items.Add(table.Rows[i][0].ToString());
            //    }
            //}
        }
        private void buttonX1_Click(object sender, EventArgs e)
        {
            string projectname = "";
            string filename = "";
            //判断是否是新项目,还是已有项目?
            if (projectLists2.Text.Trim() == "")
            {
                MessageBox.Show("项目名称不能为空。");
                return;
            }
            else { 
                projectname = projectLists2.Text;

                int rr = Folder_Handle(projectname);//添加工程
            }
            if (textBoxX1.Text.Trim() == "")
            {
                MessageBox.Show("文件名称不能为空。");
                return;
            }
            else
            {
                filename = textBoxX1.Text;
            }
            if (textBoxX2.Text.Trim() == "")
            {
                MessageBox.Show("输出路径不能为空");
                return;
            }
             
            int result = File_Handle(projectname, filename);//添加文件
              
            if (result == 1)
            {
                MessageBox.Show("保存成功");
            }

            Close();
        }
        //对文件夹的操作
        private int Folder_Handle(string NewName)
        {
            string url = textBoxX2.Text + "\\" + NewName;

            //判断在files下有无newname的文件夹,有则返回1,且检查数据库中有无该文件夹的数据;
            //若没有该文件夹则创建该名称的文件夹并返回0,且数据库中添加该文件夹的数据;
            if (Directory.Exists(url) == true)
            {
                MessageBox.Show("文件夹" + NewName + "已存在,专题图将直接添加。"); 
            }
            else
            {
                Directory.CreateDirectory(url); 
            }
            return 0;

        }

        //对文件的操作
        private int File_Handle(string folderName, string FileName)
        {
            string url = textBoxX2.Text + "\\" + folderName + "\\" + FileName + ".png";
  
            if (File.Exists(url) == true)
            { //文件存在
                MessageBox.Show("文件" + FileName + "已存在,可以另修改文件名后保存。"); 
            }
            else
            {//文件不存在
                if (tablename == "casic_patm_statistic")
                {
                    savedchart.SaveImage(url, System.Drawing.Imaging.ImageFormat.Png);   
                }
                else
                {
                    savedimg.Save(url, System.Drawing.Imaging.ImageFormat.Png);
                }
                return 1;
            }

            return 0;

        }
        //判断是否为已有工程
        private bool checkProject(string projectname) {
            string sql = "select * from "+this.tablename+" where "+tablename+".NODENAME = '"+projectname
                +"'";
            DataTable table = OledbHelper.QueryTable(sql);
            if (table.Rows.Count > 0)
            { 
                return true;
            }
            else { 
                return false;
            } 
        }

        private void buttonX2_Click(object sender, EventArgs e)
        { 
            Close();
        }
        string tempstr = "";
        private void buttonX3_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)                  //打开文件夹对话框
            {
                textBoxX2.Text = folderBrowserDialog1.SelectedPath;
                tempstr = folderBrowserDialog1.SelectedPath;                                                            //执行当前线程

            }
        }

    }
}