/// <summary> /// 用品领用确认 /// </summary> /// <returns>领用是否成功 false:失败,true:成功</returns> public static bool ConfirmAll(string OfficeThingsUsedSql, string OfficeThingsUsedInfos, string ApplyNo, string CompanyCD, string UserID, SqlParameter[] paramgas) { try { OfficeThingsUsedDetailModel OfficeThingsUsedDetailM = new OfficeThingsUsedDetailModel(); string[] OfficeThingsUsedArrary = OfficeThingsUsedInfos.Split('|'); SqlCommand[] comms = new SqlCommand[OfficeThingsUsedArrary.Length]; //申明cmd数组(主表,明细表,每条明细生成一条库存记录) SqlCommand OfficeThingsUsedCom = new SqlCommand(OfficeThingsUsedSql.ToString()); OfficeThingsUsedCom.Parameters.AddRange(paramgas); comms[0] = OfficeThingsUsedCom; string recorditems = ""; string[] gasfield = null; for (int i = 1; i < OfficeThingsUsedArrary.Length; i++) //循环数组 { recorditems = OfficeThingsUsedArrary[i].ToString(); gasfield = recorditems.Split(','); string ThingNo = gasfield[0].ToString();//用品编号 string BuyCount = gasfield[1].ToString();//领用数量 OfficeThingsUsedDetailM.ThingNo = ThingNo; OfficeThingsUsedDetailM.Count = Convert.ToDecimal(BuyCount); OfficeThingsUsedDetailM.ModifiedDate = System.DateTime.Now; OfficeThingsUsedDetailM.ModifiedUserID = UserID; OfficeThingsUsedDetailM.CompanyCD = CompanyCD; OfficeThingsStorageModel OfficeThingsStorageM = new OfficeThingsStorageModel(); #region 拼写更新入库库存信息sql语句 StringBuilder OfficeThingsStorageSql = new StringBuilder(); OfficeThingsStorageSql.AppendLine("UPDATE officedba.OfficeThingsStorage"); OfficeThingsStorageSql.AppendLine("SET SurplusCount=SurplusCount-@ApplyCount"); OfficeThingsStorageSql.AppendLine(",UsedCount=UsedCount+@ApplyCount1 "); OfficeThingsStorageSql.AppendLine(",ModifiedDate=@ModifiedDate"); OfficeThingsStorageSql.AppendLine(",ModifiedUserID=@ModifiedUserID"); OfficeThingsStorageSql.AppendLine(" WHERE ThingNo=@ThingNo AND CompanyCD=@CompanyCD "); #endregion #region 设置参数 SqlParameter[] OfficeThingsStorageParams = new SqlParameter[6]; OfficeThingsStorageParams[0] = SqlHelper.GetParameter("@ApplyCount", OfficeThingsUsedDetailM.Count); OfficeThingsStorageParams[1] = SqlHelper.GetParameter("@ApplyCount1", OfficeThingsUsedDetailM.Count); OfficeThingsStorageParams[2] = SqlHelper.GetParameter("@ModifiedDate", OfficeThingsUsedDetailM.ModifiedDate); OfficeThingsStorageParams[3] = SqlHelper.GetParameter("@ModifiedUserID", OfficeThingsUsedDetailM.ModifiedUserID); OfficeThingsStorageParams[4] = SqlHelper.GetParameter("@ThingNo", OfficeThingsUsedDetailM.ThingNo); OfficeThingsStorageParams[5] = SqlHelper.GetParameter("@CompanyCD", OfficeThingsUsedDetailM.CompanyCD); #endregion SqlCommand OfficeThingsStorageComInfo = new SqlCommand(OfficeThingsStorageSql.ToString()); OfficeThingsStorageComInfo.Parameters.AddRange(OfficeThingsStorageParams); comms[i] = OfficeThingsStorageComInfo; } //执行 SqlHelper.ExecuteTransForList(comms); return SqlHelper.Result.OprateCount > 0 ? true : false; } catch { return false; } }
/// <summary> /// 入库确认 /// </summary> /// <returns>添加是否成功 false:失败,true:成功</returns> public static bool ConfirmAll(string OfficeThingsBuySql, string OfficeThingsInStorageInfos, string BuyRecordNo, string CompanyCD, string UserID, SqlParameter[] paramgas) { try { ArrayList listADD = new ArrayList(); OfficeThingsBuyDetailModel OfficeThingsBuyDetailM = new OfficeThingsBuyDetailModel(); string[] OfficeThingsInStorageArrary = OfficeThingsInStorageInfos.Split('|'); SqlCommand[] comms = new SqlCommand[OfficeThingsInStorageArrary.Length]; //申明cmd数组(主表,明细表,每条明细生成一条库存记录) SqlCommand OfficeThingsBuyCom = new SqlCommand(OfficeThingsBuySql.ToString()); OfficeThingsBuyCom.Parameters.AddRange(paramgas); //comms[0] = OfficeThingsBuyCom; listADD.Add(OfficeThingsBuyCom); string recorditems = ""; string[] gasfield = null; for (int i = 1; i < OfficeThingsInStorageArrary.Length; i++) //循环数组 { recorditems = OfficeThingsInStorageArrary[i].ToString(); gasfield = recorditems.Split(','); string ThingNo = gasfield[0].ToString();//用品编号 string BuyCount = gasfield[1].ToString();//采购数量 string UnitPrice = gasfield[2].ToString();//采购单价 string BuyMoney = gasfield[3].ToString();//采购金额 string Provider = gasfield[4].ToString();//供应商 string FromBillID = gasfield[5].ToString();//采购金额 string FromSortNo = gasfield[6].ToString();//供应商 OfficeThingsBuyDetailM.BuyCount = Convert.ToDecimal(BuyCount); OfficeThingsBuyDetailM.BuyMoney = Convert.ToDecimal(BuyMoney); OfficeThingsBuyDetailM.BuyRecordNo = BuyRecordNo; OfficeThingsBuyDetailM.CompanyCD = CompanyCD; OfficeThingsBuyDetailM.ModifiedDate = System.DateTime.Now; OfficeThingsBuyDetailM.ModifiedUserID = UserID; OfficeThingsBuyDetailM.Provider = Provider; OfficeThingsBuyDetailM.ThingNo = ThingNo; OfficeThingsBuyDetailM.UnitPrice = Convert.ToDecimal(UnitPrice); int RetOfficeThingsVal = OfficeThingsStorageIsExist(ThingNo, CompanyCD);//库存是否有此用品编号的记录,有更新库存,无插入新的库存记录 OfficeThingsStorageModel OfficeThingsStorageM = new OfficeThingsStorageModel(); if (RetOfficeThingsVal == 0)//无此编号的库存,插入库存信息 { #region 拼写添加入库库存信息sql语句 StringBuilder OfficeThingsStorageSql = new StringBuilder(); OfficeThingsStorageSql.AppendLine("INSERT INTO officedba.OfficeThingsStorage"); OfficeThingsStorageSql.AppendLine("(CompanyCD"); OfficeThingsStorageSql.AppendLine(",ThingNo "); OfficeThingsStorageSql.AppendLine(",TotalCount"); OfficeThingsStorageSql.AppendLine(",SurplusCount "); OfficeThingsStorageSql.AppendLine(",UsedCount "); OfficeThingsStorageSql.AppendLine(",ModifiedDate"); OfficeThingsStorageSql.AppendLine(",ModifiedUserID)"); OfficeThingsStorageSql.AppendLine(" values "); OfficeThingsStorageSql.AppendLine("(@CompanyCD"); OfficeThingsStorageSql.AppendLine(",@ThingNo "); OfficeThingsStorageSql.AppendLine(",@TotalCount"); OfficeThingsStorageSql.AppendLine(",@SurplusCount "); OfficeThingsStorageSql.AppendLine(",@UsedCount "); OfficeThingsStorageSql.AppendLine(",@ModifiedDate"); OfficeThingsStorageSql.AppendLine(",@ModifiedUserID)"); #endregion #region 设置参数 SqlParameter[] OfficeThingsStorageParams = new SqlParameter[7]; OfficeThingsStorageParams[0] = SqlHelper.GetParameter("@CompanyCD", OfficeThingsBuyDetailM.CompanyCD); OfficeThingsStorageParams[1] = SqlHelper.GetParameter("@ThingNo", OfficeThingsBuyDetailM.ThingNo); OfficeThingsStorageParams[2] = SqlHelper.GetParameter("@TotalCount", OfficeThingsBuyDetailM.BuyCount); OfficeThingsStorageParams[3] = SqlHelper.GetParameter("@SurplusCount", OfficeThingsBuyDetailM.BuyCount); OfficeThingsStorageParams[4] = SqlHelper.GetParameter("@UsedCount", 0); OfficeThingsStorageParams[5] = SqlHelper.GetParameter("@ModifiedDate", OfficeThingsBuyDetailM.ModifiedDate); OfficeThingsStorageParams[6] = SqlHelper.GetParameter("@ModifiedUserID", OfficeThingsBuyDetailM.ModifiedUserID); #endregion SqlCommand OfficeThingsStorageComInfo = new SqlCommand(OfficeThingsStorageSql.ToString()); OfficeThingsStorageComInfo.Parameters.AddRange(OfficeThingsStorageParams); //comms[i] = OfficeThingsStorageComInfo; listADD.Add(OfficeThingsStorageComInfo); } else //有此编号,更新库存信息 { #region 拼写添加入库库存信息sql语句 StringBuilder OfficeThingsStorageSql = new StringBuilder(); OfficeThingsStorageSql.AppendLine("UPDATE officedba.OfficeThingsStorage"); OfficeThingsStorageSql.AppendLine("SET TotalCount=TotalCount+@TotalCount"); OfficeThingsStorageSql.AppendLine(",SurplusCount=SurplusCount+@TotalCount1 "); OfficeThingsStorageSql.AppendLine(",ModifiedDate=@ModifiedDate"); OfficeThingsStorageSql.AppendLine(",ModifiedUserID=@ModifiedUserID"); OfficeThingsStorageSql.AppendLine(" WHERE ThingNo=@ThingNo AND CompanyCD=@CompanyCD "); #endregion #region 设置参数 SqlParameter[] OfficeThingsStorageParams = new SqlParameter[6]; OfficeThingsStorageParams[0] = SqlHelper.GetParameter("@TotalCount", OfficeThingsBuyDetailM.BuyCount); OfficeThingsStorageParams[1] = SqlHelper.GetParameter("@TotalCount1", OfficeThingsBuyDetailM.BuyCount); OfficeThingsStorageParams[2] = SqlHelper.GetParameter("@ModifiedDate", OfficeThingsBuyDetailM.ModifiedDate); OfficeThingsStorageParams[3] = SqlHelper.GetParameter("@ModifiedUserID", OfficeThingsBuyDetailM.ModifiedUserID); OfficeThingsStorageParams[4] = SqlHelper.GetParameter("@ThingNo", OfficeThingsBuyDetailM.ThingNo); OfficeThingsStorageParams[5] = SqlHelper.GetParameter("@CompanyCD", OfficeThingsBuyDetailM.CompanyCD); #endregion SqlCommand OfficeThingsStorageComInfo = new SqlCommand(OfficeThingsStorageSql.ToString()); OfficeThingsStorageComInfo.Parameters.AddRange(OfficeThingsStorageParams); // comms[i] = OfficeThingsStorageComInfo; listADD.Add(OfficeThingsStorageComInfo); } if (Convert .ToInt32 ( FromBillID) >0)// 回写信息 { #region 拼写添加入库库存信息sql语句 StringBuilder OfficeThingsStorageSql = new StringBuilder(); OfficeThingsStorageSql.AppendLine("UPDATE officedba.OfficeThingsPurchaseApplyDetail "); OfficeThingsStorageSql.AppendLine("SET InCount=isnull(InCount,0)+@InCount "); OfficeThingsStorageSql.AppendLine(" WHERE ID=@FromBillID AND CompanyCD=@CompanyCD "); #endregion #region 设置参数 SqlParameter[] OfficeThingsStorageParams = new SqlParameter[3]; OfficeThingsStorageParams[0] = SqlHelper.GetParameter("@FromBillID", FromBillID); OfficeThingsStorageParams[1] = SqlHelper.GetParameter("@InCount", OfficeThingsBuyDetailM.BuyCount); OfficeThingsStorageParams[2] = SqlHelper.GetParameter("@CompanyCD", OfficeThingsBuyDetailM.CompanyCD); #endregion SqlCommand OfficeThingsStorageComInfo = new SqlCommand(OfficeThingsStorageSql.ToString()); OfficeThingsStorageComInfo.Parameters.AddRange(OfficeThingsStorageParams); // comms[(i+1)] = OfficeThingsStorageComInfo; listADD.Add(OfficeThingsStorageComInfo); } } //执行 // SqlHelper.ExecuteTransForList(comms); SqlHelper.ExecuteTransWithArrayList(listADD); return SqlHelper.Result.OprateCount > 0 ? true : false; } catch { return false; } }