private void bt_OK_Click(object sender, EventArgs e)
        {
            if (cb_db_Type.SelectedItem == cb_db_Type.Items[0])
            {
                if (this.tx_db_IP.Text.Trim() != "")
                {
                    ConnectString = @"Data Source = " + this.tx_db_IP.Text + ",1433; Initial Catalog = " + this.tb_DBName.Text + ";";
                }
                else
                {
                    ConnectString = @"Server = " + this.tb_DBServer.Text + "; Database = " + this.tb_DBName.Text + "; Trusted_Connection = false;";
                }
            }
            else
            {
                ConnectString = "Data Source = .\\SQLEXPRESS; AttachDbFilename =\"" + tx_db_FilePath.Text + "\"; Integrated Security = True; Connect Timeout = 30;";
            }
            if (tx_db_UserName.Text != "" && tx_db_Password.Text != "")
            {
                ConnectString += "User ID = " + tx_db_UserName.Text + "; Password = "******";";
            }

            if (DBHelper.GetDBHelper(DatabaseType).TestDBConnect(ConnectString))
            {
                CommonConfigurationManager.UpdateAppConfig("ConnectString", AES.GetEncryptConnectString(ConnectString));
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show(DBHelper.GetDBHelper().GetErrorMesasge());
            }
        }
        private void cb_db_Type_SelectedIndexChanged(object sender, EventArgs e)
        {
            ConnectString = AES.GetDecryptConnectString(CommonConfigurationManager.GetAppConfig("ConnectString"));
            string[] sqlStrArray = null;
            if (ConnectString != null && ConnectString.Contains(";"))
            {
                sqlStrArray = ConnectString.Split(';');
            }
            if (cb_db_Type.Text == cb_db_Type.Items[0].ToString())
            {
                tlp_SQL_File.Visible   = false;
                tlp_SQL_Server.Visible = true;
                DatabaseType           = EnumDatabaseType.SqlServer;
                if (sqlStrArray != null && sqlStrArray.All(str => !str.Contains("AttachDbFilename")))
                {
                    string serverName = sqlStrArray.Where(cs => cs.Contains("Data Source")).FirstOrDefault();
                    if (serverName != null)
                    {
                        serverName    = serverName.Substring(serverName.IndexOf('=') + 1);
                        tx_db_IP.Text = serverName.Trim();
                    }
                }
            }
            else
            {
                tlp_SQL_File.Visible   = true;
                tlp_SQL_Server.Visible = false;
                DatabaseType           = EnumDatabaseType.SqlFile;
                if (sqlStrArray != null)
                {
                    string filePath = sqlStrArray.Where(cs => cs.Contains("AttachDbFilename")).FirstOrDefault();
                    if (filePath != null)
                    {
                        filePath            = filePath.Substring(filePath.IndexOf('=') + 1);
                        tx_db_FilePath.Text = filePath.Trim();
                    }
                }
            }
            if (sqlStrArray != null)
            {
                string userId = sqlStrArray.Where(cs => cs.Contains("User ID")).FirstOrDefault();
                if (userId != null)
                {
                    userId = userId.Substring(userId.IndexOf('=') + 1);
                    tx_db_UserName.Text = userId.Trim();
                }

                string password = sqlStrArray.Where(cs => cs.Contains("Password")).FirstOrDefault();
                if (password != null)
                {
                    password            = password.Substring(password.IndexOf('=') + 1);
                    tx_db_Password.Text = password.Trim();
                }
            }
        }
Esempio n. 3
0
        public NewDataForm()
        {
            InitializeComponent();
            tableLayoutPanel1.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(tableLayoutPanel1, true, null);
            tableLayoutPanel2.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(tableLayoutPanel1, true, null);
            tableLayoutPanel3.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(tableLayoutPanel1, true, null);
            tableLayoutPanel4.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(tableLayoutPanel1, true, null);
            flowLayoutPanel1.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(tableLayoutPanel1, true, null);

            this.pictureBox1.Click += (sender, e) =>
            {
                if (this.pictureBox1.Image != null)
                {
                    Form frm = new Form();
                    frm.AutoSize      = true;
                    frm.AutoSizeMode  = AutoSizeMode.GrowAndShrink;
                    frm.ShowIcon      = false;
                    frm.StartPosition = FormStartPosition.CenterScreen;

                    PictureBox pictureBox = new PictureBox();

                    pictureBox.Image    = (Image)pictureBox1.Image.Clone();
                    pictureBox.SizeMode = PictureBoxSizeMode.AutoSize;
                    frm.Controls.Add(pictureBox);
                    frm.ShowDialog();
                }
            };

            this.Load += (sender, e) =>
            {
                this.bt_CreateDetail.Text = this.Text + "详细";
                if (GoalTables.Contains(TableName) && RecordID != "")
                {
                    this.bt_CreateDetail.Visible = true;
                }
            };

            #region 读取报表配置
            string GoalTableString = Common.CommonConfigurationManager.GetAppConfig("评价报表");
            if (GoalTableString == "")
            {
                GoalTables = new string[] {
                    "施工单位安全生产条件核查表",
                    "施工单位平安工地考核评价表"
                };
                GoalTableString = string.Join(",", GoalTables);
                CommonConfigurationManager.UpdateAppConfig("评价报表", GoalTableString);
            }
            else
            {
                GoalTables = GoalTableString.Split(',');
            }
            #endregion
        }
        public static bool CheckSystemCode()
        {
            string systemCode = CommonConfigurationManager.GetAppConfig("SystemCode");

            if (systemCode.Trim() == "")
            {
                return(false);
            }
            try
            {
                return(AES.AESDecrypt(systemCode).Equals(SystemInformationCode.GetCpuID() + "zhangdahang"));
            }
            catch (Exception ex)
            {
            }
            return(false);
        }
 private void bt_OK_Click(object sender, EventArgs e)
 {
     try
     {
         //string mechineCode = "BFEBFBFF000806EA";
         string mechineCode = SystemInformationCode.GetCpuID();
         if (AES.AESDecrypt(textBox2.Text).Equals(mechineCode + "zhangdahang"))
         {
             CommonConfigurationManager.UpdateAppConfig("SystemCode", textBox2.Text);
             this.DialogResult = DialogResult.OK;
         }
         else
         {
             MessageBox.Show("您输入的注册码不正确,请重新输入!");
         }
     }
     catch
     {
         MessageBox.Show("您输入的注册码不正确,请重新输入!");
     }
 }
Esempio n. 6
0
        private void UserLogin_Load(object sender, EventArgs e)
        {
            SystemSettingForm.DatabaseType = EnumDatabaseType.SqlServer;
            //string connectString = Properties.Settings.Default["DocMngDBConnectionString"].ToString();

            string connectString = AES.GetDecryptConnectString(CommonConfigurationManager.GetAppConfig("ConnectString"));

            if (connectString == null ||
                !DatabaseHelper.DBHelper.GetDBHelper(SystemSettingForm.DatabaseType).TestDBConnect(connectString))
            {
                SystemSettingForm ssf = new SystemSettingForm();
                if (ssf.ShowDialog() == DialogResult.OK)
                {
                    connectString = AES.GetEncryptConnectString(ssf.ConnectString);
                    var str = AES.GetDecryptConnectString(connectString);
                    CommonConfigurationManager.UpdateAppConfig("ConnectString", connectString);
                    Application.Restart();
                }
                else
                {
                    Application.Exit();
                }
            }
            else
            {
                DatabaseHelper.DBHelper.GetDBHelper(SystemSettingForm.DatabaseType).SetDBConnectString(connectString);
            }

            if (!File.Exists("userData.bin"))
            {
                return;
            }
            cmb_UserName.SelectedIndexChanged += (obj, ee) =>
            {
                if (UserDatas.ContainsKey(cmb_UserName.Text))
                {
                    tb_Password.Text = UserDatas[cmb_UserName.Text];
                }
            };
            try
            {
                //读取文件流对象
                FileStream fs = new FileStream("userData.bin", FileMode.OpenOrCreate);
                if (fs.Length > 0)
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    //读出存在Data.bin 里的用户信息
                    UserDatas = bf.Deserialize(fs) as Dictionary <string, string>;
                    if (UserDatas != null)
                    {
                        cmb_UserName.DataSource = UserDatas.Keys.ToList();
                        if (cmb_UserName.Items.Count > 0)
                        {
                            cmb_UserName.SelectedIndex = 0;
                        }
                    }
                    else
                    {
                        File.Delete("userData.bin");
                        cb_Remember.Checked = false;
                    }
                }
                else
                {
                    UserDatas = new Dictionary <string, string>();
                }
                fs.Close();
                fs.Dispose();
                fs = null;
            }
            catch (Exception ex)
            {
                Debug.Assert(false, ex.Message);
            }
        }
 private void SystemSettingForm_Load(object sender, EventArgs e)
 {
     ConnectString            = AES.GetDecryptConnectString(CommonConfigurationManager.GetAppConfig("ConnectString"));
     cb_db_Type.SelectedIndex = 0;
 }
        private void DataEditPanel_Load(object sender, EventArgs e)
        {
            dataGridView1.Visible            = false;
            dataGridView1.DataSourceChanged += (obj, ee) =>
            {
                foreach (DataGridViewColumn col in dataGridView1.Columns)
                {
                    if (col.ValueType == typeof(DateTime))
                    {
                        if (col.HeaderText == "修改时间")
                        {
                            col.DefaultCellStyle.Format = "yyyy/MM/dd HH:mm:ss";
                        }
                        else
                        {
                            col.DefaultCellStyle.Format = "yyyy/MM/dd";
                        }
                    }
                }
                if (dataGridView1.Columns.Contains("ID"))
                {
                    dataGridView1.Columns["ID"].Visible = false;
                }
                if (dataGridView1.Columns.Contains("ShowDoc"))
                {
                    dataGridView1.Columns.Remove("ShowDoc");
                }
                DataGridViewTextBoxColumn colDefault = new DataGridViewTextBoxColumn();
                colDefault.Name                       = "ShowDoc";
                colDefault.HeaderText                 = "      ";
                colDefault.DefaultCellStyle.Font      = new Font(dataGridView1.Font, FontStyle.Underline);
                colDefault.DefaultCellStyle.ForeColor = Color.Blue;
                int colIndex = dataGridView1.Columns.Add(colDefault);
                dataGridView1.Visible = true;
            };

            dataGridView1.CellFormatting += (obj, ee) =>
            {
                if (ee.RowIndex < 0)
                {
                    return;
                }
                if (ee.ColumnIndex >= 0 && dataGridView1.Columns[ee.ColumnIndex].Name == "ShowDoc")
                {
                    dataGridView1.Rows[ee.RowIndex].Cells[ee.ColumnIndex].Value = "浏览";
                }
            };
            dataGridView1.CellContentClick += (obj, ee) =>
            {
                if (ee.ColumnIndex < 0 || ee.RowIndex < 0)
                {
                    return;
                }
                if (dataGridView1.Columns[ee.ColumnIndex].Name == "ShowDoc")
                {
                    DataWorkingState = WorkingStateEnum.Creating;
                    IFieldTable table = GetFieldTable(dataGridView1.Rows[ee.RowIndex]);
                    ShowDocForm ndf   = new ShowDocForm();
                    if (ndf.CreateFromFieldTable(table, DataWorkingState, false))
                    {
                        ndf.TableName = table.TableName;
                        if (ndf.ShowDialog() == DialogResult.OK)
                        {
                            DataSource = DBHelper.GetDBHelper().GetDataFromTable(0, 0, TableName, "");
                        }
                    }
                    this.DataWorkingState = WorkingStateEnum.Search;
                }
            };
            dataGridView1.CellMouseDoubleClick += (obj, ee) =>
            {
                if (ee.RowIndex < 0)
                {
                    return;
                }
                if (!RowReportTables.Contains(this.TableName))
                {
                    if (CreateFromField(dataGridView1.DataSource as DataTable, dataGridView1.Rows[ee.RowIndex], WorkingStateEnum.View, false))
                    {
                        return;
                    }
                }
                dataGridView1.Rows[ee.RowIndex].Selected = true;
                IFieldTable table = GetFieldTable(dataGridView1.SelectedRows[0]);
                CreateFromField(table, dataGridView1.Rows[ee.RowIndex], WorkingStateEnum.View, false);
            };

            tableLayoutPanel1.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(tableLayoutPanel1, true, null);
            tableLayoutPanel2.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(tableLayoutPanel2, true, null);
            this.flp_SearchField.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(flp_SearchField, true, null);

            #region 读取报表配置文件
            string RowReportTableString = Common.CommonConfigurationManager.GetAppConfig("单行报表");
            if (RowReportTableString == "")
            {
                RowReportTables = new string[] {
                    "安全技术交底表",
                    "安全检查记录表",
                    "安全生产会议记录",
                    "安全生产奖励通知单",
                    "安全教育培训记录表",
                    "安全生产违约处理通知单",
                    "安全隐患整改回复单",
                    "安全隐患整改通知单",
                    "应急救援预案演练记录表",
                    "三级安全教育登记卡",
                    "生产管理制度",
                    "设备安全检查记录表"
                };
                RowReportTableString = string.Join(",", RowReportTables);
                CommonConfigurationManager.UpdateAppConfig("单行报表", RowReportTableString);
            }
            else
            {
                RowReportTables = RowReportTableString.Split(',');
            }
            string GoalTableString = Common.CommonConfigurationManager.GetAppConfig("评价报表");
            if (GoalTableString == "")
            {
                GoalTables = new string[] {
                    "施工单位安全生产条件核查表",
                    "施工单位平安工地考核评价表"
                };
                GoalTableString = string.Join(",", GoalTables);
                CommonConfigurationManager.UpdateAppConfig("评价报表", GoalTableString);
            }
            else
            {
                GoalTables = GoalTableString.Split(',');
            }

            string RegulationTableString = Common.CommonConfigurationManager.GetAppConfig("制度方案报表");
            if (RegulationTableString == "")
            {
                RegulationTables = new string[] {
                    "生产管理制度",
                    "工程专项施工方案",
                    "临时用电方案"
                };
                RegulationTableString = string.Join(",", RegulationTables);
                CommonConfigurationManager.UpdateAppConfig("制度方案报表", RegulationTableString);
            }
            else
            {
                RegulationTables = RegulationTableString.Split(',');
            }
            #endregion
        }