/// <summary>
 /// 注册
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         if (CheckResutOut())
         {
             Dictionary <string, object> dic = new Dictionary <string, object>();
             dic.Add("@username", txtUserName.Text);
             string    sql    = "Select * from Users where enable='1' and  username=@username ";
             DataTable userdt = DbHelperOleDb.Query(sql, dic).Tables[0];
             if (userdt == null || userdt.Rows.Count == 0)
             {
                 Users user = new Users();
                 user.username   = txtUserName.Text;
                 user.password   = DESJiaMi.Encrypt(txtpassword.Text);
                 user.createtime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                 user.enable     = "1";
                 if (DbHelperOleDb.Add(user, "Users", null))
                 {
                     MessageBox.Show("注册成功!\r\n账号:" + user.username + "\r\n密码:" + DESJiaMi.Decrypt(user.password) + "\r\n请牢记登陆账号密码!", "注册", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     this.DialogResult = DialogResult.OK;
                 }
                 else
                 {
                     MessageBox.Show("注册失败!", "注册", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 }
             }
             else
             {
                 MessageBox.Show("该用户名已经存在,请重新输入其他的用户名!", "注册", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
         }
     }
     catch (Exception ee)
     {
         MessageBox.Show("注册失败!\r\n错误信息:\r\n" + ee.Message.ToString(), "注册", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
        /// <summary>
        /// 【保存】
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Save_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(labName.Text))
            {
                if (flowLayoutPanel1.Controls.Count > 0)
                {
                    List <WorkingHours> worktimes = new List <WorkingHours>();
                    foreach (timeInfo item in flowLayoutPanel1.Controls)
                    {
                        string error = "";
                        if (item.CheckResult(out error))
                        {
                            WorkingHours times = item.GetTimeResult();
                            times.workername = DESJiaMi.Encrypt(this.gWorkerName);
                            times.workdate   = dateWorkDate.Value.ToString("yyyy-MM-dd");
                            times.isdelete   = "1";
                            worktimes.Add(times);
                        }
                        else
                        {
                            MessageBox.Show("保存失败!\r\n" + error, "保存", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                    //判断时间段是否存在交叉
                    if (worktimes.Count > 0)
                    {
                        string msg = "";
                        if (ListTimesJiaoCha(worktimes, out msg))
                        {
                            #region 判断添加的是否已经存在

                            string    selectStr = "Select * from WorkingHours where workername='" + DESJiaMi.Encrypt(this.gWorkerName) + "' and workdate='" + dateWorkDate.Value.ToString("yyyy-MM-dd") + "' and isdelete='1' ;";
                            DataTable dt        = DbHelperOleDb.Query(selectStr, new Dictionary <string, object>()).Tables[0];
                            if (dt != null && dt.Rows.Count > 0)
                            {
                                if (MessageBox.Show("该工作人员在" + dateWorkDate.Value.ToString("yyyy-MM-dd") + "已经存在工作记录。是否覆盖添加???", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
                                {
                                    return;
                                }

                                //删除该人员当天的已经添加的数据
                                try
                                {
                                    string deleteSql = " Delete from WorkingHours where workername='" + DESJiaMi.Encrypt(this.gWorkerName) + "' and workdate='" + dateWorkDate.Value.ToString("yyyy-MM-dd") + "' and isdelete='1'  ;";
                                    DbHelperOleDb.ExecuteSql(deleteSql, new Dictionary <string, object>());
                                }
                                catch (Exception)
                                {
                                }
                            }
                            #endregion

                            foreach (WorkingHours item in worktimes)
                            {
                                item.createtime     = DateTime.Now.ToString();
                                item.createusername = UserInfo.userName;
                                if (!DbHelperOleDb.Add(item, "WorkingHours", null))
                                {
                                    MessageBox.Show("保存失败", "保存", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                    return;
                                }
                            }
                            MessageBox.Show("保存完成", "保存", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            isAddSuccess = true;
                            if (checkLianxu.Checked)
                            {
                                //清空
                                btn_Clearn_Click(null, null);
                            }
                            else
                            {
                                this.Close();
                            }
                        }
                        else
                        {
                            MessageBox.Show(msg + "\r\n保存失败!!!", "保存", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("未添加待保存的时间信息,保存失败!!!", "保存", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show("姓名信息错误,保存失败!!!", "保存", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        /// <summary>
        /// 新增信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Add_Click(object sender, EventArgs e)
        {
            if (btn_Add.Text == "新 增")
            {
                //设置按钮状态
                SetButtonStatus(false, false, true);

                btn_Add.Text = "保 存";

                //清空数据
                ClearnNeiRong();
                //可编辑状态
                IsAddNeiRong(true);
                //创建时间
                labCreateTime.Text = DateTime.Now.ToString("yyyy-MM-dd  HH:mm:ss");
            }
            else  //(btn_Add.Text == "保存")
            {
                if (!string.IsNullOrEmpty(txtName.Text.Trim()))
                {
                    //判断姓名是否重复
                    string    sql        = "Select * from Personnel where enable='1' and name='" + DESJiaMi.Encrypt(txtName.Text.Trim()) + "';";
                    DataTable userUpdate = DbHelperOleDb.Query(sql, new Dictionary <string, object>()).Tables[0];
                    if (userUpdate != null && userUpdate.Rows.Count > 0)
                    {
                        MessageBox.Show("该姓名信息已经存在,不能重复添加!", "保存", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    else
                    {
                        //执行更新
                        Personnel personnel = new Personnel();
                        personnel.name           = DESJiaMi.Encrypt(txtName.Text.Trim());
                        personnel.gender         = cboxGender.Text != "" ? DESJiaMi.Encrypt(cboxGender.Text.Trim()) : "";
                        personnel.lxdh           = txtLxdh.Text != "" ? DESJiaMi.Encrypt(txtLxdh.Text.Trim()) : "";
                        personnel.mainwork       = richMainjob.Text;
                        personnel.createtime     = labCreateTime.Text;
                        personnel.createusername = UserInfo.userName;
                        personnel.enable         = "1";

                        if (DbHelperOleDb.Add(personnel, "Personnel", null))
                        {
                            updateORAddSuccess = true;
                            MessageBox.Show("保存成功!", "修改", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ClearnNeiRong();                        //清空内容
                            SetButtonStatus(true, true, true);      //重置按钮状态
                            LoadPersonelInfo();                     //重新加载职工列表
                            btn_Update.Text = "新 增";
                        }
                        else
                        {
                            MessageBox.Show("保存失败!", "修改", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("请先输入有效的“姓名”信息!!!", "保存", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }