/// <summary> /// 添加与编辑RECEIVABLES01记录 /// </summary> /// <param name="page">当前页面指针</param> /// <param name="model">RECEIVABLES01表实体</param> /// <param name="content">更新说明</param> /// <param name="isCache">是否更新缓存</param> /// <param name="isAddUseLog">是否添加用户操作日志</param> public void Save(Page page, RECEIVABLES01 model, string content = null, bool isCache = true, bool isAddUseLog = true) { try { //保存 model.Save(); //判断是否启用缓存 if (CommonBll.IsUseCache() && isCache) { SetModelForCache(model); } if (isAddUseLog) { if (string.IsNullOrEmpty(content)) { content = "{0}" + (model.Id == 0 ? "添加" : "编辑") + "RECEIVABLES01记录成功,ID为【" + model.Id + "】"; } //添加用户访问记录 UseLogBll.GetInstence().Save(page, content); } } catch (Exception e) { var result = "执行RECEIVABLES01Bll.Save()函数出错!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } }
///// <summary> ///// 更换分店事件 ///// </summary> ///// <param name="sender"></param> ///// <param name="e"></param> //protected void shopIdDropdown_SelectedIndexChanged(object sender, EventArgs e) //{ // LoadData(); //} /// <summary> /// 汇整出货单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Archive_Click(object sender, EventArgs e) { archiveWindow.Hidden = true; //获取登录用户 var OlUser = OnlineUsersBll.GetInstence().GetModelForCache(x => x.UserHashKey == Session[OnlineUsersTable.UserHashKey].ToString()); //登录名 string userId = OlUser.Manager_LoginName; //获取用户所属shop shopId = OlUser.SHOP_ID; DatePicker dpStart = archiveWindow.FindControl("archiveDatePanel").FindControl("outStartDate") as DatePicker; DatePicker dpEnd = archiveWindow.FindControl("archiveDatePanel").FindControl("outEndDate") as DatePicker; //拼接查询条件 List <ConditionFun.SqlqueryCondition> conditionList = QueryOutListCondition(shopId, dpStart.Text, dpEnd.Text); //1.查询总部出货表 // 1)出货单状态为 2=核准 // 2)SHOP_ID = 当前登录用户的总部编号 // 3)在指定日期范围内 //2.遍历结果 //3.更新出货单状态为5=月结(关单), 并且锁定出货单(LOCKED=1) //4.更新成功后查询出货单明细更新到应收明细表 //5.保存应收主信息 //6.保存应收明细 int total = 0; //循环查询 while (true) { //1.查询满足条件的出货单 DataTable dataTable = OUT00Bll.GetInstence().GetDataTable(false, 100, null, 0, 100, conditionList, null); if (dataTable == null || dataTable.Rows.Count == 0) { break; } //2.遍历查询结果 foreach (DataRow row in dataTable.Rows) { try { //3.更新出货单状态为5=月结(关单) int retValue = updaterHelper.Update(string.Format("update OUT00 set STATUS = 5, LOCKED = 1 where id = {0} and STATUS = 2", row["Id"])); //更新成功 汇整出货单 if (retValue == 1) { //4.查询出货单明细 //明细查询条件 List <ConditionFun.SqlqueryCondition> itemConditionList = new List <ConditionFun.SqlqueryCondition>(); itemConditionList.Add(new ConditionFun.SqlqueryCondition(ConstraintType.Where, "SHOP_ID", Comparison.Equals, row["SHOP_ID"], false, false)); itemConditionList.Add(new ConditionFun.SqlqueryCondition(ConstraintType.And, "OUT_ID", Comparison.Equals, row["OUT_ID"], false, false)); //执行查询 List <OUT01> outItemList = selectHelper.Select <OUT01>(false, 0, null, itemConditionList, new List <string>() { "SNo" }).ExecuteTypedList <OUT01>(); if (outItemList == null || outItemList.Count == 0) { CommonBll.WriteLog(string.Format("出货单{0}未查询到明细", row["OUT_ID"]), null); continue; } //出货价格 decimal price = 0; //出货成本 decimal cost = 0; //遍历出货单明细插入 foreach (OUT01 item in outItemList) { //累加出货价 price += item.STD_PRICE; //累加成本 cost += item.COST; //应收明细 RECEIVABLES01 receiveItem = new RECEIVABLES01(); //出货批号 receiveItem.BAT_NO = item.BAT_NO; //出货成本 receiveItem.COST = item.COST; //明细备注 receiveItem.MEMO = item.MEMO; //出货单ID receiveItem.OUT_ID = item.OUT_ID; //商品编号 receiveItem.PROD_ID = item.PROD_ID; //验收量 receiveItem.QUAN1 = item.QUAN1; //取消量 receiveItem.QUAN2 = item.QUAN2; //总店编号 receiveItem.SHOP_ID = item.SHOP_ID; //明细序号 receiveItem.SNo = item.SNo; //出货价格 receiveItem.STD_PRICE = item.STD_PRICE; //出货量 receiveItem.STD_QUAN = item.STD_QUAN; //出货单位 receiveItem.STD_UNIT = item.STD_UNIT; //6.保存明细 receiveItem.Save(); } RECEIVABLES00 receiveMain = new RECEIVABLES00(); //receiveMain.APP_DATETIME //receiveMain.APP_USER = ""; //建档时间 receiveMain.CRT_DATETIME = DateTime.Now; //建档人员 receiveMain.CRT_USER_ID = userId; //出货单日期 receiveMain.INPUT_DATE = (DateTime)row["INPUT_DATE"]; //分店编号 receiveMain.IN_SHOP = row["IN_SHOP"].ToString(); //最后修改日期 receiveMain.LAST_UPDATE = DateTime.Now; //备注 receiveMain.MEMO = row["Memo"].ToString(); //修改时间 receiveMain.MOD_DATETIME = DateTime.Now; //修改人 receiveMain.MOD_USER_ID = userId; //出货单号 receiveMain.OUT_ID = row["OUT_ID"].ToString(); //总店编号 receiveMain.SHOP_ID = row["SHOP_ID"].ToString(); //新建存档状态 receiveMain.STATUS = 1; //出货单的建单人 receiveMain.USER_ID = row["USER_ID"].ToString(); //出货总价 receiveMain.BILL_AMOUNT = price; //出货总成本 receiveMain.BILL_COST = cost; //5.保存应收账单 receiveMain.Save(); total++; } } catch (Exception ex) { CommonBll.WriteLog(string.Format("汇整出货单{0}发生错误。", row["OUT_ID"]), ex); } } //已处理到最后一页 if (dataTable.Rows.Count < 100) { break; } //等待2秒 Thread.Sleep(2000); } Thread.Sleep(5000); Alert.Show(string.Format("汇整完成,共汇整{0}条出货单.", total)); }