Exemplo n.º 1
0
        private void BT_ok_Click(object sender, EventArgs e)
        {
            try
            {
                if (db.SaveCs8cConfigure() && File.Exists(Application.StartupPath + "\\Txt\\Configure.txt"))
                {
                    File.Copy(Application.StartupPath + "\\Txt\\Configure.txt", Application.StartupPath + "\\Log\\Configure_" +
                              DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString()
                              + DateTime.Now.Second.ToString() + ".txt", true);
                }
            }
            catch
            {
            }


            if (TC_Edit.SelectedTabPageIndex == 0)
            {
                if (TxtData.DataBase.ToolMode < 1 && TxtData.DataBase.Tool == null && TxtData.DataBase.Home == null)
                {
                    MessageBox.Show("下位机通讯异常!");
                    return;
                }

                if (MessageBox.Show("确定需要把下位机数据导入数据库?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                {
                    return;
                }


                if (EditTool)
                {
                    if (!db.EditTool(TxtData.DataBase.Tool))
                    {
                        MessageBox.Show("操作数据库异常!");
                        return;
                    }
                }
                else
                {
                    if (!db.EditHome(TxtData.DataBase.Home))
                    {
                        MessageBox.Show("操作数据库异常!");
                        return;
                    }
                }
            }
            else
            {
                if (CK_CS8C.Checked && TxtData.DataBase.ToolMode < 1)
                {
                    MessageBox.Show("下位机通讯异常");
                    return;
                }
                if (CK_CS8C.Checked && TxtData.DataBase.InterfaceType != 9)
                {
                    MessageBox.Show("下位机不在空闲状态");
                    return;
                }

                double[] data = EditTool ? TxtData.CS8CConfigure.Tool : TxtData.CS8CConfigure.Home;

                double.TryParse(TE_O1.Text, out data[0]);
                double.TryParse(TE_O2.Text, out data[1]);
                double.TryParse(TE_O3.Text, out data[2]);
                double.TryParse(TE_O4.Text, out data[3]);
                double.TryParse(TE_O5.Text, out data[4]);
                double.TryParse(TE_O6.Text, out data[5]);

                if (EditTool)
                {
                    if (!db.EditTool(data))
                    {
                        MessageBox.Show("操作数据库异常!");
                        return;
                    }
                }
                else
                {
                    if (!db.EditHome(data))
                    {
                        MessageBox.Show("操作数据库异常!");
                        return;
                    }
                }
                if (CK_CS8C.Checked)
                {
                    FtpClient ftp = new FtpClient(TxtData.XMLConfigure.IpAddress);
                    if (db.SaveCs8cConfigure() == false || !ftp.UploadConfigure())
                    {
                        MessageBox.Show("发送配置文件异常!");
                        return;
                    }
                    // ;
                }
            }

            this.Close();
        }