private void JobDeptChange() { if (dataGridView_Employe.CurrentRow == null) { Prompt.Warning("未选择员工记录!"); return; } string salesID = string.Empty; string salesName = string.Empty; string deptID = string.Empty; string deptName = string.Empty; string changeDate = string.Empty; string jobType = string.Empty; salesID = dataGridView_Employe.CurrentRow.Cells["ColID"].Value.ToString(); salesName = dataGridView_Employe.CurrentRow.Cells["ColSalesName"].Value.ToString(); FrmOrganization destDept = new FrmOrganization(); destDept.Text = "请选择调岗信息"; destDept.FrmMode = FormMode.view; destDept.SalesID = salesID; destDept.DeptID = treeView_Dept.SelectedNode.Name; destDept.JobType = dataGridView_Employe.CurrentRow.Cells["ColJobType"].Value.ToString(); if (destDept.ShowDialog() == System.Windows.Forms.DialogResult.OK) { bool isOnlyTitle = destDept.DeptID == treeView_Dept.SelectedNode.Name; deptID = destDept.DeptID; deptName = destDept.DeptName; changeDate = destDept.ChangeDate; jobType = destDept.JobType; ExecChange(isOnlyTitle, salesID, salesName, changeDate, deptID, deptName, jobType); } }
private void JobTrack(int type = 0) { string changeDate = string.Empty; if (dataGridView_Employe.CurrentRow == null) { Prompt.Warning("未选择员工记录!"); return; } FrmJobChangeDate frmDate = new FrmJobChangeDate(); if (frmDate.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string sql = string.Format("select Convert(varchar(10), BeginDate, 120) from JobTrack where SalesID = {0} and EndDate is null", dataGridView_Employe.CurrentRow.Cells["ColID"].Value.ToString()); object objResult = SqlHelper.ExecuteScalar(sql); if (objResult != null && objResult != System.DBNull.Value) { if (DateTime.Parse(frmDate.ChangeDate) < DateTime.Parse(objResult.ToString())) { Prompt.Warning("调岗日期不能小于当前部门的调入日期!"); return; } else { changeDate = frmDate.ChangeDate; } } } FrmOrganization destDept = new FrmOrganization(); destDept.Text = "请选择调入部门"; if (destDept.ShowDialog() == System.Windows.Forms.DialogResult.OK) { using (SqlConnection connection = SqlHelper.OpenConnection()) { SqlTransaction sqlTran = connection.BeginTransaction(); SqlCommand cmd = connection.CreateCommand(); cmd.Transaction = sqlTran; try { switch (type) { case 0: //调岗 cmd.CommandText = string.Format("update JobTrack set EndDate = '{0}' where SalesID = {1} and DeptID = {2} and EndDate is null", changeDate, dataGridView_Employe.CurrentRow.Cells["ColID"].Value.ToString(), dataGridView_Employe.CurrentRow.Cells["ColDeptID"].Value.ToString()); cmd.ExecuteNonQuery(); cmd.CommandText = string.Format("insert into JobTrack (SalesID, DeptID, DeptName, JobType, BeginDate) values ({0},{1},'{2}','{3}','{4}')", dataGridView_Employe.CurrentRow.Cells["ColID"].Value.ToString(), destDept.DeptID, destDept.DeptName, dataGridView_Employe.CurrentRow.Cells["ColJobType"].Value.ToString(), changeDate); cmd.ExecuteNonQuery(); break; case 1: //调入 cmd.CommandText = string.Format("insert into JobTrack (SalesID, DeptID, DeptName, JobType, BeginDate) values ({0},{1},'{2}','{3}', '{4}')", dataGridView_Employe.CurrentRow.Cells["ColID"].Value.ToString(), destDept.DeptID, destDept.DeptName, dataGridView_Employe.CurrentRow.Cells["ColJobType"].Value.ToString(), changeDate); cmd.ExecuteNonQuery(); break; default: break; } sqlTran.Commit(); if (type == 0) { dataGridView_Employe.Rows.RemoveAt(dataGridView_Employe.CurrentRow.Index); } Prompt.Information("操作成功!"); } catch (Exception ex) { sqlTran.Rollback(); Prompt.Error("操作失败, 错误:" + ex.Message); } } } }