/// <summary> /// 更新计时工资项信息 /// </summary> /// <param name="model">计时工资项信息</param> /// <returns></returns> private static SqlCommand UpdateTimeSalaryInfo(TimeSalaryModel model) { #region SQL文拼写 StringBuilder updateSql = new StringBuilder(); updateSql.AppendLine(" UPDATE officedba.TimeSalary "); updateSql.AppendLine(" SET TimeCount = @TimeCount "); updateSql.AppendLine(" ,SalaryMoney = @SalaryMoney "); updateSql.AppendLine(" ,ModifiedDate = getdate() "); updateSql.AppendLine(" ,ModifiedUserID = @ModifiedUserID "); updateSql.AppendLine(" WHERE "); updateSql.AppendLine(" CompanyCD = @CompanyCD "); updateSql.AppendLine(" AND TimeNo = @TimeNo "); updateSql.AppendLine(" AND EmployeeID = @EmployeeID "); updateSql.AppendLine(" AND CONVERT(VARCHAR(10),TimeDate,21) = CONVERT(VARCHAR(10),@TimeDate,21) "); #endregion //定义更新基本信息的命令 SqlCommand comm = new SqlCommand(); comm.CommandText = updateSql.ToString(); //参数 SetSaveParameter(comm, model); //执行更新 return(comm); }
/// <summary> /// 保存计时工资项信息 /// </summary> /// <param name="lstEdit">计时工资项信息</param> /// <param name="companyCD">公司代码</param> /// <param name="modifyUserID">最后修改用户</param> /// <returns></returns> public static bool SaveTimeSalaryInfo(ArrayList lstEdit, string companyCD, string modifyUserID) { //定义返回变量 bool isSucc = true; //信息存在时,进行操作 if (lstEdit != null && lstEdit.Count > 0) { //保存库列表 ArrayList lstSave = new ArrayList(); //遍历所有计时工资项,进行增删改操作 for (int i = 0; i < lstEdit.Count; i++) { //获取值 TimeSalaryModel model = (TimeSalaryModel)lstEdit[i]; //设置公司代码 model.CompanyCD = companyCD; //最后修改人 model.ModifiedUserID = modifyUserID; //更新 if ("1".Equals(model.EditFlag)) { //执行更新操作 lstSave.Add(UpdateTimeSalaryInfo(model)); } //插入 else if ("0".Equals(model.EditFlag)) { //执行插入操作 lstSave.Add(InsertTimeSalaryInfo(model)); } //删除 else { //执行删除操作 lstSave.Add(DeleteTimeSalaryInfo(model.ID)); } } //执行保存操作 isSucc = SqlHelper.ExecuteTransWithArrayList(lstSave); //获取插入数据的ID for (int j = 0; j < lstEdit.Count; j++) { //获取值 TimeSalaryModel model = (TimeSalaryModel)lstEdit[j]; //插入时 if ("0".Equals(model.EditFlag)) { //获取插入的命令 SqlCommand comm = (SqlCommand)lstSave[j]; //设置计时工资项编号 model.ID = comm.Parameters["@SalaryID"].Value.ToString(); } } } return(isSucc); }
/// <summary> /// 保存时参数设置 /// </summary> /// <param name="comm">命令</param> /// <param name="model">人才代理信息</param> private static void SetSaveParameter(SqlCommand comm, TimeSalaryModel model) { comm.Parameters.Add(SqlHelper.GetParameterFromString("@CompanyCD", model.CompanyCD)); //公司代码 comm.Parameters.Add(SqlHelper.GetParameterFromString("@EmployeeID", model.EmployeeID)); //员工ID comm.Parameters.Add(SqlHelper.GetParameterFromString("@TimeNo", model.TimeNo)); //计时工资项编号 comm.Parameters.Add(SqlHelper.GetParameterFromString("@TimeDate", model.TimeDate)); //计时工资项日期 comm.Parameters.Add(SqlHelper.GetParameterFromString("@TimeCount", model.TimeCount)); //时长 comm.Parameters.Add(SqlHelper.GetParameterFromString("@SalaryMoney", model.SalaryMoney)); //金额 comm.Parameters.Add(SqlHelper.GetParameterFromString("@ModifiedUserID", model.ModifiedUserID)); //最后修改人 }
/// <summary> /// 新建计时工资项信息 /// </summary> /// <param name="model">计时工资项信息</param> /// <returns></returns> private static SqlCommand InsertTimeSalaryInfo(TimeSalaryModel model) { #region 登陆SQL文 StringBuilder insertSql = new StringBuilder(); insertSql.AppendLine(" INSERT INTO "); insertSql.AppendLine(" officedba.TimeSalary "); insertSql.AppendLine(" (CompanyCD "); insertSql.AppendLine(" ,EmployeeID "); insertSql.AppendLine(" ,TimeDate "); insertSql.AppendLine(" ,TimeNo "); insertSql.AppendLine(" ,TimeCount "); insertSql.AppendLine(" ,SalaryMoney "); insertSql.AppendLine(" ,ModifiedDate "); insertSql.AppendLine(" ,ModifiedUserID) "); insertSql.AppendLine(" VALUES "); insertSql.AppendLine(" (@CompanyCD "); insertSql.AppendLine(" ,@EmployeeID "); insertSql.AppendLine(" ,@TimeDate "); insertSql.AppendLine(" ,@TimeNo "); insertSql.AppendLine(" ,@TimeCount "); insertSql.AppendLine(" ,@SalaryMoney "); insertSql.AppendLine(" ,getdate() "); insertSql.AppendLine(" ,@ModifiedUserID) "); insertSql.AppendLine(" SET @SalaryID= @@IDENTITY "); #endregion //定义更新基本信息的命令 SqlCommand comm = new SqlCommand(); //设置存储过程名 comm.CommandText = insertSql.ToString(); //设置保存的参数 SetSaveParameter(comm, model); //添加返回参数 comm.Parameters.Add(SqlHelper.GetOutputParameter("@SalaryID", SqlDbType.Int)); //执行插入并返回插入结果 return(comm); }