private void btnSave_Click(object sender, EventArgs e) { if (CheckInput_EditPwd()) { StringBuilder sSql = new StringBuilder(); sSql.Append("update Users set "); sSql.AppendFormat("LoginPwd='{0}' ", txtNewPwd.Text.Trim()); sSql.AppendFormat("where LoginId='{0}' and LoginPwd='{1}'", Common.UserName, txtOldPwd.Text.Trim()); sqlHelper helper = new sqlHelper(); try { if (helper.ExecuteNonQuery(helper.connectionStr, sSql.ToString()) > 0) { MessageBox.Show("密码修改成功!"); Common.UserPwd = txtNewPwd.Text.Trim(); } else { MessageBox.Show("密码修改失败!"); } } catch (Exception) { MessageBox.Show("系统维护,请稍后再试!", Common.APTION); } } }
private void EditDepart() { StringBuilder sSql = new StringBuilder(); sSql.AppendFormat("update Depart set DeptName= '{0}', ", txtDeptName.Text.Trim()); sSql.AppendFormat(" parentId={0} ", (int)cmbDepartFather.SelectedValue); sSql.AppendFormat(" where DeptId={0}", Convert.ToInt32(txtDepartId.Text.Trim())); sqlHelper helper = new sqlHelper(); try { if (helper.ExecuteNonQuery(helper.connectionStr, sSql.ToString()) > 0) { MessageBox.Show("修改成功!", Common.APTION); fdm.QueryDepart(); this.Close(); } else { MessageBox.Show("修改失败!", Common.APTION); } } catch (Exception) { MessageBox.Show("系统维护,请稍后再试!", Common.APTION); } }
//public void BindAcceptMessage2() //{ // sqlHelper helper = new sqlHelper(); // StringBuilder sSql = new StringBuilder(); // //ssql.Append("select MessageId,DeptName,positionName,EpName,MessageContent,SendTime,"); // //ssql.Append(" case IsRead when 0 then '未读' when 1 then '已读' end as IsRead"); // //ssql.Append(" from(select EpId,EpName,DeptName,positionName,em.DptId as Dept,em.PId as PId "); // //ssql.Append(" from Emploryee em,Depart de,Position po "); // //ssql.Append(" where em.DptId=de.DeptId and em.PId=po.pId) newEm,Message me"); // //ssql.Append(" where newEm.EpId=me.SendEmploryId "); // sSql.AppendFormat(" where AceptEmploryId= {0}", Common.EpId); // if (cmbDept.SelectedValue != null) // { // if ((int)cmbDept.SelectedValue != -1 && (int)cmbDept.SelectedValue != 0) // { // sSql.Append(" and DeptId= "); // sSql.Append(cmbDept.SelectedValue.ToString().Trim()); // try // { // if ((int)helper.ExecuteNonQuery(helper.connectionStr, sSql.ToString()) <= 0) // { // MessageBox.Show("没有您要查询的消息!"); return; // } // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } // } // } // if (cmbPosition.SelectedValue != null) // { // if ((int)cmbPosition.SelectedValue != -1 && (int)cmbPosition.SelectedValue != 0) // { // sSql.AppendFormat(" and em.PId={0} ", cmbPosition.SelectedValue.ToString().Trim()); // } // } // if (txtSendName.Text.Trim() != string.Empty) // { // sSql.AppendFormat(" and EpName like '%{0}%' ", txtSendName.Text.ToString().Trim()); // } // sSql.Append(" order by SendTime desc "); // try // { // DataSet ds = helper.ExecuteDataSet(helper.connectionStr, sSql.ToString(), "AMessage"); // dgvMessage.AutoGenerateColumns = false; // dgvMessage.DataSource = ds.Tables["AMessage"]; // } // catch (Exception ex) // { // MessageBox.Show("电脑已经疯了,请稍后再试!"+"\t"+ex.Message, Common.APTION); // } //} #endregion #region 方法:删除消息 private void DeleteMessage() { StringBuilder sSql = new StringBuilder(); sSql.Append("delete Message where "); sSql.Append(" MessageId in("); foreach (DataGridViewRow row in dgvMessage.SelectedRows) { if (row.Cells[0].Value != null) { sSql.Append(Convert.ToInt32(row.Cells[0].Value)); sSql.Append(","); } } sSql.Remove(sSql.Length - 1, 1); sSql.Append(")"); //sSql.Append(" MessageId =");//删除一条消息 //if (this.dgvMessage.SelectedRows.Count > 0) //{ // sSql.Append(Convert.ToInt32(this.dgvMessage.SelectedRows[0].Cells[0].Value)); //} sqlHelper helper = new sqlHelper(); int number = helper.ExecuteNonQuery(helper.connectionStr, sSql.ToString()); if (number > 0) { MessageBox.Show("成 功 删 除 " + number + " 条 消 息!", Common.APTION); } else { MessageBox.Show("删除失败!"); } }
private void AddDepart() { StringBuilder sSql = new StringBuilder(); sSql.Append("insert into Depart (DeptName,parentId) "); sSql.AppendFormat("values ('{0}',{1})", txtDeptName.Text.Trim(), cmbDepartFather.SelectedValue.ToString().Trim()); sqlHelper helper = new sqlHelper(); try { if (helper.ExecuteNonQuery(helper.connectionStr, sSql.ToString()) > 0) { MessageBox.Show("添加成功!", Common.APTION); fdm.QueryDepart(); this.Close(); } else { MessageBox.Show("添加失败!", Common.APTION); } } catch (Exception) { MessageBox.Show("系统维护,请稍后再试!", Common.APTION); } }
private void btnSend_Click(object sender, EventArgs e) { sqlHelper helper = new sqlHelper(); string[] Ids = EpIds.Split(','); StringBuilder faulsSend = new StringBuilder(); foreach (string Id in Ids) { int res = 0; StringBuilder sSql = new StringBuilder(); sSql.Append("Insert into Message (MessageContent,SendEmploryId,AceptEmploryId,IsRead)"); sSql.AppendFormat(" values ('{0}'", txtContent.Text.Trim()); sSql.AppendFormat(",{0},{1},0)", Common.EpId, Id); res = helper.ExecuteNonQuery(helper.connectionStr, sSql.ToString()); if (res < 1) { faulsSend.Append(Id); faulsSend.Append(","); } } if (faulsSend.Length == 0) { MessageBox.Show(" 全 部 发 送 成 功 !", "提示"); //new FrmReceiveMessage().BindAcceptMessage(); this.Close(); } else { faulsSend.Remove(faulsSend.Length - 1, 1); MessageBox.Show("以下员工发送失败:" + faulsSend); } }
private void FrmShowMessage_FormClosed(object sender, FormClosedEventArgs e) { string sSql = "update Message set IsRead =1 where MessageId=" + currentRow.Cells["MessageId"].Value.ToString().Trim(); sqlHelper helper = new sqlHelper(); helper.ExecuteNonQuery(helper.connectionStr, sSql); //更新状态 frmmessage.BindAcceptMessage(); //加载刷新 }
private void btnDelete_Click(object sender, EventArgs e) { DialogResult delResult = MessageBox.Show("您确定要删除吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (delResult == DialogResult.Yes) { StringBuilder delSb = new StringBuilder(); foreach (DataGridViewRow row in dgvDepart.SelectedRows) { if (row.Cells["deptId"].Value != null) { delSb.Append(row.Cells["deptId"].Value.ToString().Trim()); delSb.Append(","); } } if (delSb.Length == 0) { MessageBox.Show("您还没有选择删除项"); return; } delSb.Remove(delSb.Length - 1, 1); StringBuilder ExitPoxSb = new StringBuilder(); ExitPoxSb.Append(" select dept.DeptName from Position pos inner join Depart dept on pos.DeptId=dept.DeptId"); ExitPoxSb.Append(" where pos.DeptId in ("); ExitPoxSb.Append(delSb.ToString()); ExitPoxSb.Append(")"); ExitPoxSb.Append(" group by dept.DeptName"); sqlHelper helper = new sqlHelper(); SqlDataReader dr = helper.ExecuteRead(helper.connectionStr, ExitPoxSb.ToString()); StringBuilder DeptNameSb = new StringBuilder(); while (dr.Read()) { DeptNameSb.Append(dr["DeptName"].ToString().Trim()); DeptNameSb.Append(","); } if (DeptNameSb.Length > 0) { DeptNameSb.Remove(DeptNameSb.Length - 1, 1); MessageBox.Show("不能删除!一下的部门正在使用" + DeptNameSb.ToString()); return; } delSb.Insert(0, "delete Depart where DeptId in ("); delSb.Append(")"); int result = helper.ExecuteNonQuery(helper.connectionStr, delSb.ToString()); if (result > 0) { MessageBox.Show("删除成功"); QueryDepart(); } else { MessageBox.Show("删除失败"); } } }
private void AddEmploryee() { StringBuilder sSql = new StringBuilder(); sSql.Append("insert Emploryee (EpName,PId,DptId,MobilePhone,officePhone,Address,gender) "); sSql.AppendFormat(" values('{0}',", txtEmploryeeName.Text.Trim()); sSql.AppendFormat("{0},", cmbPosition.SelectedValue); sSql.AppendFormat("{0},", cmbDepart.SelectedValue); sSql.AppendFormat("'{0}',", txtCellPhoneNum.Text.Trim()); sSql.AppendFormat("'{0}',", txtTelephoneNum.Text.Trim()); sSql.AppendFormat("'{0}',", txtAddress.Text.Trim()); if (rbtBoy.Checked) { sSql.AppendFormat("{0}", 1); } else if (rbtGirl.Checked) { sSql.AppendFormat("{0}", 0); } sSql.Append(")"); sqlHelper helper = new sqlHelper(); try { if (helper.ExecuteNonQuery(helper.connectionStr, sSql.ToString()) > 0) { MessageBox.Show("添加成功!"); feb.BindEmploryeeinfo(); this.Close(); } else { MessageBox.Show("添加失败!"); } } catch (Exception) { MessageBox.Show("系统维护!"); } }
private void updataEmploryee() { StringBuilder sSql = new StringBuilder(); sSql.Append("update Emploryee set "); sSql.AppendFormat(" EpName='{0}',", txtEmploryeeName.Text.Trim()); if (rbtBoy.Checked) { sSql.AppendFormat(" gender={0},", 1); } else { sSql.AppendFormat(" gender={0},", 0); } sSql.AppendFormat(" MobilePhone='{0}', ", txtCellPhoneNum.Text.Trim()); sSql.AppendFormat(" officePhone='{0}',", txtTelephoneNum.Text.Trim()); sSql.AppendFormat(" Address='{0}', ", txtAddress.Text.Trim()); sSql.AppendFormat(" DptId={0},", (int)cmbDepart.SelectedValue); sSql.AppendFormat(" PId={0} ", (int)cmbPosition.SelectedValue); sSql.AppendFormat(" where EpId={0} ", EmpId); sqlHelper helper = new sqlHelper(); try { if (helper.ExecuteNonQuery(helper.connectionStr, sSql.ToString()) > 0) { MessageBox.Show("修改保存成功!", Common.APTION); this.Close(); feb.BindEmploryeeinfo(); } else { MessageBox.Show("修改失败!", Common.APTION); } } catch (Exception) { MessageBox.Show("系统维护!"); } }
private void btnDelete_Click(object sender, EventArgs e) { if (dgvEmploryeeInfo.SelectedRows.Count > 0) { DialogResult delResult = MessageBox.Show("您确定要删除吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (delResult == DialogResult.Yes) { //删除语句 StringBuilder delSb = new StringBuilder(); sqlHelper helper = new sqlHelper(); delSb.Append(" UPDATE [hr].[dbo].[Emploryee] SET flag=1 "); delSb.Append(" where EpId in ( "); foreach (DataGridViewRow row in dgvEmploryeeInfo.SelectedRows) { if (row.Cells["EpId"].Value != null) { } delSb.Append(row.Cells["EpId"].Value); delSb.Append(","); } delSb.Remove(delSb.Length - 1, 1); delSb.Append(" )"); int result = helper.ExecuteNonQuery(helper.connectionStr, delSb.ToString()); if (result > 0) { MessageBox.Show("删除成功"); BindEmploryeeinfo(); } else { MessageBox.Show("删除失败"); } } } else { MessageBox.Show("请选择一行"); } }