Пример #1
0
        private void confirmBtn_Click(object sender, EventArgs e)
        {
            // 一般性非法输入
            String EmpNo   = textBox1.Text;
            String EmpName = textBox2.Text;
            String EmpSex  = radioMale.Checked == true ? "男" : "女";
            String EmpAge  = textBox3.Text;

            if (EmpNo == "" || EmpName == "" || !(radioFemale.Checked || radioMale.Checked) || EmpAge == "")
            {
                MessageBox.Show("Error", "某些项目没有填写");
                return;
            }

            Regex regex = new Regex(@"^[0-9]{1,3}$");

            if (!(regex.IsMatch(EmpAge) && Convert.ToInt32(EmpAge) > 0))
            {
                MessageBox.Show("年龄填写错误", "Error");
                return;
            }


            if (Intent.dict["FLAG"].ToString() == "ADD")
            {
                sqlString = @"SELECT * FROM [EMPLOYEE]" +
                            " WHERE [EmpNo]='" + EmpNo + "'";
                table = db.GetBySQL(sqlString);

                if (table.Rows.Count != 0)
                {
                    MessageBox.Show("员工号已经存在,请换一个!", "ERROR");
                    return;
                }
            }
            else    //修改
            {
                if (EmpNo != Intent.dict["EmpNo"].ToString())
                {
                    sqlString = @"SELECT * FROM [EMPLOYEE]" +
                                " WHERE [EmpNo]='" + EmpNo + "'";
                    table = db.GetBySQL(sqlString);

                    if (table.Rows.Count != 0)
                    {
                        MessageBox.Show("员工号已经存在,请换一个!", "ERROR");
                        return;
                    }
                }
            }

            Intent.dict["EmpNo"]   = EmpNo;
            Intent.dict["EmpName"] = EmpName;
            Intent.dict["EmpSex"]  = EmpSex;
            Intent.dict["EmpAge"]  = EmpAge;

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Пример #2
0
        // 读取员工表
        private void LoadMainTab()
        {
            listView1.Clear();
            //生成表头
            listView1.Columns.Add("员工号", listView1.Width / 4 - 1, HorizontalAlignment.Left);
            listView1.Columns.Add("员工姓名", listView1.Width / 4 - 1, HorizontalAlignment.Left);
            listView1.Columns.Add("性别", listView1.Width / 4 - 1, HorizontalAlignment.Left);
            listView1.Columns.Add("年龄", listView1.Width / 4 - 1, HorizontalAlignment.Left);

            sqlString = @"SELECT * FROM [EMPLOYEE]";
            DataTable table = db.GetBySQL(sqlString);

            listView1.BeginUpdate();
            FillListView(listView1, table);
            listView1.EndUpdate();
        }