Newer
Older
EMS_SZ / PAS_Forms / F_PASProjedit.cs
root on 21 Mar 2016 7 KB first
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;

namespace Cyberpipe.PAS_Forms
{
    public partial class F_PASProjedit : Office2007Form
    {
        public F_PASProjedit()
        {
            InitializeComponent();
        }

        #region  公共变量
        PAS_logicfile.PAS_Affair PASAClass = new Cyberpipe.PAS_logicfile.PAS_Affair();//实例化ModuleClass文件夹下的FrmAffairClass公共类
        //PAS_logicfile.PAS_Database PAS_dataclass = new Cyberpipe.PAS_logicfile.PAS_Database();//实例化ModuleClass文件夹下的DataClass公共类
        public string Imadir = "";
        public string L_Name = "";
        string Odir = "";
        //string Sdir = "";
        //int mark = 0;
        #endregion      

        private void OK_Click(object sender, EventArgs e)
        {
            string Bsql = "";
            string dir = "";
            string str = "";
            int PID = 0;
            int nType = 0;
            if (PAS_logicfile.PAS_Affair.Redact_T == "T")
                nType = 2;
            if (PAS_logicfile.PAS_Affair.Redact_T == "F")
                nType = 1;
            Odir = PAS_logicfile.PAS_Affair.Redact_D;
            int n = 0;
            if (int.Parse(this.Tag.ToString()) == 0 || int.Parse(this.Tag.ToString()) == 1)
            {
                if (TB_ProjName.Text == "")
                {
                    MessageBox.Show(L_Name + "名称不能为空。");
                    return;
                }
            }
            switch (int.Parse(this.Tag.ToString()))
            {
                case 0:
                    {
                        if (PAS_logicfile.PAS_Affair.Redact_T == "T")
                        {
                            //Odir = Imadir + "\\Files\\" + PAS_logicfile.PAS_Affair.tablename + "\\" + TB_ProjName.Text.Trim();
                            Odir = TB_ProjName.Text.Trim();
                            PID = 0;
                        }
                        if (PAS_logicfile.PAS_Affair.Redact_T == "F")
                        {
                            //Odir = Imadir + "\\" + PAS_logicfile.PAS_Affair.tablename + "\\" + TB_ProjName.Text.Trim();
                            Odir = TB_ProjName.Text.Trim();
                            PID = int.Parse(PAS_logicfile.PAS_Affair.Redact_M);
                        }

                        Bsql = "insert into " + PAS_logicfile.PAS_Affair.tablename 
                            + " (NODEPID,NODENAME,NODEPATH,NODETYPE,NODESIGN) values("
                            + PID + ",'" + TB_ProjName.Text + "','" + Odir + "'," + nType 
                            + ",'" + Utility.userName + "')";
                        str = L_Name + "创建成功";
                        break;
                    }
                case 1:
                    {
                        //dir = PASAClass.UpAndDown_Dir(PAS_logicfile.PAS_Affair.Redact_D) + "\\" + TB_ProjName.Text.Trim();
                        Odir = PAS_logicfile.PAS_Affair.Redact_D;
                        dir = TB_ProjName.Text.Trim();
                        
                        Bsql = "update " + PAS_logicfile.PAS_Affair.tablename + " set NODENAME='" 
                            + TB_ProjName.Text + "',NODEPATH='" + dir + "' where NODEID='" 
                            + PAS_logicfile.PAS_Affair.Redact_M + "'";
                        str = L_Name + "修改成功";
                        break;
                    }
                case 2:
                    {
                        dir = PAS_logicfile.PAS_Affair.Redact_D;
                        Odir = dir; 
                        Bsql = "delete  " + PAS_logicfile.PAS_Affair.tablename + " where NODEID=" 
                            + PAS_logicfile.PAS_Affair.Redact_M;
                        str = L_Name + "删除成功";
                        break;
                    }
            }

            //n = PASAClass.Folder_Handle(Application.StartupPath + "\\Files\\" + PAS_logicfile.PAS_Affair.tablename + "\\" + Odir, "", 
            //    TB_ProjName.Text.Trim(), int.Parse(this.Tag.ToString()));
            //创建文件夹
            udfiles.UpDownFile upfolder = new udfiles.UpDownFile(Utility.udserviceurl);
            n = upfolder.Folder_Handle(Utility.uploadpath + "\\" + PAS_logicfile.PAS_Affair.tablename + "\\" + Odir, "",
                TB_ProjName.Text.Trim(), int.Parse(this.Tag.ToString()));

            if (n == 1)
            {
                DialogResult = DialogResult.Cancel;//将当前窗体的对话框返回值设为Cancel
                MessageBox.Show("文件添加失败!");
            }
            else if (n == 0)
                {
                    OledbHelper.getsqlcom(Bsql);
                    if (int.Parse(this.Tag.ToString()) > 0 && n == 0)
                    {
                        PASAClass.DFiles_CleanUp(Odir, dir, int.Parse(this.Tag.ToString()));
                    }
                    if (int.Parse(this.Tag.ToString()) == 0)
                    {
                        DataSet DS = OledbHelper.getDataSet("select max(NODEID) from "
                            + PAS_logicfile.PAS_Affair.tablename, PAS_logicfile.PAS_Affair.tablename);
                        PAS_logicfile.PAS_Affair.Redact_M = DS.Tables[0].Rows[0][0].ToString();
                        PAS_logicfile.PAS_Affair.Redact_N = TB_ProjName.Text.Trim();
                    }
                    if (int.Parse(this.Tag.ToString()) == 1)
                        PAS_logicfile.PAS_Affair.Redact_N = TB_ProjName.Text.Trim();
                    DialogResult = DialogResult.OK;//将当前窗体的对话框返回值设为OK
                }
                else
                { ;}
            if (n == 2)
                MessageBox.Show("该文件夹已存在,请修改文件名!");
            else
            { ;}
            Close();
        }

        private void F_PASProjedit_Load(object sender, EventArgs e)
        {
            
            Imadir = PASAClass.UpAndDown_Dir(System.AppDomain.CurrentDomain.BaseDirectory);
            Imadir = PASAClass.UpAndDown_Dir(Imadir);
            Imadir = PASAClass.UpAndDown_Dir(Imadir);

           
            if (PAS_logicfile.PAS_Affair.Redact_T == "F")
                Imadir = PAS_logicfile.PAS_Affair.Redact_D;
            if (PAS_logicfile.PAS_Affair.Redact_T == "T")
                L_Name = "项目";
            else
                L_Name = "文件";
            switch (int.Parse(this.Tag.ToString()))
            {
                case 0:
                    {
                        LB_ProjName.Text = L_Name + "名称:";
                        TB_ProjName.Visible = true;
                        TB_ProjName.Clear();
                        break;
                    }
                case 1:
                    {
                        LB_ProjName.Text = L_Name + "名称:";
                        TB_ProjName.Visible = true;
                        TB_ProjName.Text = PAS_logicfile.PAS_Affair.Redact_N;
                        break;
                    }
                case 2:
                    {
                        LB_ProjName.Text = L_Name + "可能包含多个子文件夹及文件,\n是否还要删除。";
                        TB_ProjName.Visible = false;
                        break;
                    }
            }
        }

        private void Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void F_PASProjedit_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (PASAClass.Files_NameChar(e) == 0)
                e.Handled = true;
            if (e.KeyChar == '\r')
                OK_Click(sender, e);
        }
        }
    }