/// <summary> /// 修改产品供应商信息 /// </summary> /// <param name="stock"></param> /// <param name="user_id"></param> /// <returns></returns> public ERROR_CODE UpdateProductStock(ivt_warehouse_product stock, long user_id) { var user = UserInfoBLL.GetUserInfo(user_id); if (user == null) { // 查询不到用户,用户丢失 return(ERROR_CODE.USER_NOT_FIND); } stock.update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); stock.update_user_id = user.id; var old = Getwarehouse_product(stock.id); if (!(new ivt_warehouse_product_dal().Update(stock))) { return(ERROR_CODE.ERROR); } //操作日志 var add_log = new sys_oper_log() { user_cate = "用户", user_id = (int)user.id, name = user.name, phone = user.mobile == null ? "" : user.mobile, oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.WAREHOUSE_PRODUCT, // oper_object_id = stock.id, // 操作对象id oper_type_id = (int)OPER_LOG_TYPE.UPDATE, oper_description = new ivt_warehouse_product_dal().CompareValue(old, stock), remark = "修改产品库存信息" }; // 创建日志 new sys_oper_log_dal().Insert(add_log); // 插入日志 return(ERROR_CODE.SUCCESS); }
/// <summary> /// 删除库存产品 /// </summary> /// <param name="id"></param> /// <param name="userId"></param> /// <returns></returns> public bool DeleteIvtProduct(long id, long userId) { var pdtInfo = GetIvtProductEdit(id); if (pdtInfo == null) { return(false); } if (int.Parse(pdtInfo.picked) > 0 || int.Parse(pdtInfo.on_order) > 0) { return(false); } ivt_warehouse_product product = dal.FindById(id); string sql = $"update ivt_warehouse_product_sn set delete_user_id={userId},delete_time={Tools.Date.DateHelper.ToUniversalTimeStamp()} where warehouse_product_id={id} and delete_time=0"; dal.ExecuteSQL(sql); product.delete_time = Tools.Date.DateHelper.ToUniversalTimeStamp(); product.delete_user_id = userId; dal.Update(product); OperLogBLL.OperLogDelete <ivt_warehouse_product>(product, id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM, "删除库存产品"); if (int.Parse(pdtInfo.reserved_picked) - int.Parse(pdtInfo.picked) > 0) // 有预留库存产品,删除之 { sql = $"update ivt_reserve set delete_user_id={userId},delete_time={Tools.Date.DateHelper.ToUniversalTimeStamp()} where warehouse_id={product.warehouse_id} and delete_time=0 and quote_item_id in(select id from crm_quote_item where object_id={product.id} and delete_time=0)"; dal.ExecuteSQL(sql); } return(true); }
protected void Page_Load(object sender, EventArgs e) { id = Convert.ToInt32(Request.QueryString["id"]); //修改时,获取库存id product_id = Convert.ToInt32(Request.QueryString["pid"]); //产品id productname = Convert.ToString(Request.QueryString["pname"]); //产品名称 if (!IsPostBack) { if (id > 0)//修改 { ware = probll.Getwarehouse_product(id); if (ware == null) { //获取相关信息失败 Response.Write("<script>alert('获取库存信息失败,无法修改,返回上一级!');window.close();</script>"); } else { if (ware.warehouse_id != null && !string.IsNullOrEmpty(ware.warehouse_id.ToString())) { string name = probll.Getwarehouse(Convert.ToInt64(ware.warehouse_id)).name; this.warehouse_id.Items.Insert(0, new ListItem() { Value = "0", Text = name, Selected = true }); this.warehouse_id.Enabled = false; } product_id = ware.product_id; productname = probll.GetProduct(product_id).name; this.quantity_minimum.Text = ware.quantity_minimum.ToString(); this.quantity_maximum.Text = ware.quantity_maximum.ToString(); this.quantity.Text = ware.quantity.ToString(); if (ware.bin != null && !string.IsNullOrEmpty(ware.bin.ToString())) { this.bin.Text = ware.bin.ToString(); } if (ware.reference_number != null && !string.IsNullOrEmpty(ware.reference_number.ToString())) { this.reference_number.Text = ware.reference_number.ToString(); } } } if (product_id > 0 && id <= 0) { var list = probll.GetNoWarehouseDownList(product_id); this.warehouse_id.DataTextField = "value"; this.warehouse_id.DataValueField = "key"; this.warehouse_id.DataSource = list; this.warehouse_id.DataBind(); if (list.Count <= 0) { Response.Write("<script>alert('已存在的仓库都存储该产品,请选择修改库存数量!');window.close();</script>"); } } } }
/// <summary> /// 编辑库存产品 /// </summary> /// <param name="pdt"></param> /// <param name="sn"></param> /// <param name="userId"></param> /// <returns></returns> public bool EditIvtProduct(ivt_warehouse_product pdt, string sn, long userId) { ivt_warehouse_product product = dal.FindById(pdt.id); ivt_warehouse_product productOld = dal.FindById(pdt.id); if (product == null) { return(false); } product.reference_number = pdt.reference_number; product.bin = pdt.bin; product.quantity_minimum = pdt.quantity_minimum; product.quantity_maximum = pdt.quantity_maximum; product.quantity = pdt.quantity; product.update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(); product.update_user_id = userId; string desc = OperLogBLL.CompareValue <ivt_warehouse_product>(productOld, product); if (!string.IsNullOrEmpty(desc)) { dal.Update(product); OperLogBLL.OperLogUpdate(desc, product.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM, "修改库存产品"); } if (product.quantity != productOld.quantity) // 修改库存数量记录库存转移 { var transferDal = new ivt_transfer_dal(); var trsf = new ivt_transfer(); trsf.id = dal.GetNextIdCom(); trsf.create_time = Tools.Date.DateHelper.ToUniversalTimeStamp(); trsf.create_user_id = userId; trsf.update_time = trsf.create_time; trsf.update_user_id = userId; trsf.quantity = product.quantity - productOld.quantity; trsf.type_id = (int)DicEnum.INVENTORY_TRANSFER_TYPE.MANUAL; trsf.product_id = product.product_id; trsf.from_warehouse_id = (long)product.warehouse_id; trsf.notes = ""; transferDal.Insert(trsf); OperLogBLL.OperLogAdd <ivt_transfer>(trsf, trsf.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM_TRANSFER, "新增库存转移"); } //OperLogBLL.OperLogUpdate<ivt_warehouse_product>(product, productOld, product.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM, "修改库存产品"); string sql = $"update ivt_warehouse_product_sn set delete_user_id={userId},delete_time={Tools.Date.DateHelper.ToUniversalTimeStamp()} where warehouse_product_id={product.id}"; dal.ExecuteSQL(sql); SaveProductSn(sn, product.id, userId); return(true); }
private void save_deal() { if (id > 0) { ware = probll.Getwarehouse_product(id); } ware.warehouse_id = Convert.ToInt64(warehouse_id.SelectedValue.ToString()); ware.reference_number = reference_number.Text.ToString(); ware.bin = bin.Text.ToString(); ware.quantity_minimum = quantity_minimum.Text.ToString().Length > 0 ? Convert.ToInt32(quantity_minimum.Text.ToString()) : 0; ware.quantity_maximum = quantity_maximum.Text.ToString().Length > 0 ? Convert.ToInt32(quantity_maximum.Text.ToString()) : 0; ware.quantity = quantity.Text.ToString().Length > 0 ? Convert.ToInt32(quantity.Text.ToString()) : 0; if (id > 0) { var result = probll.UpdateProductStock(ware, GetLoginUserId()); switch (result) { case ERROR_CODE.EXIST: Response.Write("<script>alert(\"该仓库已经存在产品,请修改后保存!\");</script>"); break; //存在相同名称产品 case ERROR_CODE.ERROR: Response.Write("<script>alert(\"保存失败!\");</script>"); break; //操作失败 case ERROR_CODE.USER_NOT_FIND: Response.Write("<script>alert('查询不到用户,请重新登陆');</script>"); Response.Redirect("../Login.aspx");; break; //获取操作者信息失败 case ERROR_CODE.SUCCESS: Response.Write("<script>alert(\"库存信息修改成功!\");</script>"); break; //成功 default: Response.Write("<script>alert('异常错误,返回上一级!');window.close();self.opener.location.reload();</script>");; break; //失败 } } else { ware.product_id = product_id; var result = probll.InsertProductStock(ware, GetLoginUserId()); switch (result) { case ERROR_CODE.EXIST: Response.Write("<script>alert(\"该仓库已经存在产品,请修改后保存!\");</script>"); break; //存在相同名称产品 case ERROR_CODE.ERROR: Response.Write("<script>alert(\"保存失败!\");</script>"); break; //操作失败 case ERROR_CODE.USER_NOT_FIND: Response.Write("<script>alert('查询不到用户,请重新登陆');</script>"); Response.Redirect("../Login.aspx");; break; //获取操作者信息失败 case ERROR_CODE.SUCCESS: Response.Write("<script>alert(\"库存信息新增成功!\");</script>"); break; //成功 default: Response.Write("<script>alert('异常错误,返回上一级!');window.close();self.opener.location.reload();</script>");; break; //失败 } } }
/// <summary> /// 新增产品 /// </summary> /// <param name="pdt"></param> /// <param name="sn">序列化产品的序列号</param> /// <param name="userId"></param> /// <returns></returns> public bool AddIvtProduct(ivt_warehouse_product pdt, string sn, long userId) { pdt.id = dal.GetNextIdCom(); pdt.create_time = Tools.Date.DateHelper.ToUniversalTimeStamp(); pdt.create_user_id = userId; pdt.update_time = pdt.create_time; pdt.update_user_id = userId; dal.Insert(pdt); OperLogBLL.OperLogAdd <ivt_warehouse_product>(pdt, pdt.id, userId, DTO.DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM, "新增库存产品"); SaveProductSn(sn, pdt.id, userId); return(true); }
/// <summary> ///新增产品库存信息 /// </summary> /// <param name="stock"></param> /// <param name="user_id"></param> /// <returns></returns> public ERROR_CODE InsertProductStock(ivt_warehouse_product stock, long user_id) { var user = UserInfoBLL.GetUserInfo(user_id); if (user == null) { // 查询不到用户,用户丢失 return(ERROR_CODE.USER_NOT_FIND); } //唯一性校验 ivt_warehouse_product_dal kk = new ivt_warehouse_product_dal(); var re = kk.FindSignleBySql <ivt_warehouse_product>($"select * from ivt_warehouse_product where product_id={stock.product_id} and warehouse_id={stock.warehouse_id} and delete_time=0"); if (re != null) { return(ERROR_CODE.EXIST); } stock.id = (int)(_dal.GetNextIdCom()); stock.create_time = stock.update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); stock.create_user_id = stock.update_user_id = user_id; kk.Insert(stock); //操作日志 var add_log = new sys_oper_log() { user_cate = "用户", user_id = (int)user.id, name = user.name, phone = user.mobile == null ? "" : user.mobile, oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.WAREHOUSE_PRODUCT, // oper_object_id = stock.id, // 操作对象id oper_type_id = (int)OPER_LOG_TYPE.ADD, oper_description = _dal.AddValue(stock), remark = "新增产品库存信息" }; // 创建日志 new sys_oper_log_dal().Insert(add_log); // 插入日志 return(ERROR_CODE.SUCCESS); }
/// <summary> /// 库存产品转移 /// </summary> /// <param name="ivtProductId">库存产品id</param> /// <param name="targetLocation">目标仓库id</param> /// <param name="count">转移数</param> /// <param name="sns">序列号</param> /// <param name="note">备注</param> /// <param name="userId"></param> /// <returns></returns> public bool TransferProduct(long ivtProductId, long targetLocation, int count, string sns, string note, long userId) { var ivtPdtSource = dal.FindById(ivtProductId); // 转移的源仓库库存产品 if (count <= 0 || count > ivtPdtSource.quantity) { return(false); } // 修改源库存产品 var ivtPdtSourceOld = dal.FindById(ivtProductId); ivtPdtSource.quantity = ivtPdtSource.quantity - count; ivtPdtSource.update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(); ivtPdtSource.update_user_id = userId; string desc = OperLogBLL.CompareValue <ivt_warehouse_product>(ivtPdtSourceOld, ivtPdtSource); dal.Update(ivtPdtSource); OperLogBLL.OperLogUpdate(desc, ivtPdtSource.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM, "库存转移减少库存"); // 修改或新增目标库存产品 var ivtPdtTarget = dal.FindSignleBySql <ivt_warehouse_product>( $"select * from ivt_warehouse_product where product_id={ivtPdtSource.product_id} and warehouse_id={targetLocation} and delete_time=0"); // 转移的目标仓库库存产品 if (ivtPdtTarget == null) { ivtPdtTarget = new ivt_warehouse_product(); ivtPdtTarget.id = dal.GetNextIdCom(); ivtPdtTarget.create_time = Tools.Date.DateHelper.ToUniversalTimeStamp(); ivtPdtTarget.create_user_id = userId; ivtPdtTarget.update_time = ivtPdtTarget.create_time; ivtPdtTarget.update_user_id = userId; ivtPdtTarget.warehouse_id = targetLocation; ivtPdtTarget.product_id = ivtPdtSource.product_id; ivtPdtTarget.quantity_minimum = ivtPdtSource.quantity_minimum; ivtPdtTarget.quantity_maximum = ivtPdtSource.quantity_maximum; ivtPdtTarget.quantity = count; dal.Insert(ivtPdtTarget); OperLogBLL.OperLogAdd <ivt_warehouse_product>(ivtPdtTarget, ivtPdtTarget.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM, "库存转移增加库存"); } else { var ivtPdtTargetOld = dal.FindById(ivtPdtTarget.id); ivtPdtTarget.quantity = ivtPdtTarget.quantity + count; ivtPdtTarget.update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(); ivtPdtTarget.update_user_id = userId; desc = OperLogBLL.CompareValue <ivt_warehouse_product>(ivtPdtTargetOld, ivtPdtTarget); dal.Update(ivtPdtTarget); OperLogBLL.OperLogUpdate(desc, ivtPdtTarget.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM, "库存转移增加库存"); } // 记录库存转移 var transferDal = new ivt_transfer_dal(); var trsf = new ivt_transfer(); trsf.id = dal.GetNextIdCom(); trsf.create_time = Tools.Date.DateHelper.ToUniversalTimeStamp(); trsf.create_user_id = userId; trsf.update_time = trsf.create_time; trsf.update_user_id = userId; trsf.quantity = count; trsf.type_id = (int)DicEnum.INVENTORY_TRANSFER_TYPE.INVENTORY; trsf.product_id = ivtPdtSource.product_id; trsf.from_warehouse_id = (long)ivtPdtSource.warehouse_id; trsf.to_warehouse_id = targetLocation; trsf.notes = note; transferDal.Insert(trsf); OperLogBLL.OperLogAdd <ivt_transfer>(trsf, trsf.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM_TRANSFER, "新增库存转移"); if (!string.IsNullOrEmpty(sns)) // 库存转移序号 { var snTrsfDal = new ivt_transfer_sn_dal(); var snDal = new ivt_warehouse_product_sn_dal(); var snList = snDal.FindListBySql($"select * from ivt_warehouse_product_sn where id in({sns}) and delete_time=0"); if (snList.Count != count) { return(true); } foreach (var psn in snList) { // 修改库存产品序列号所属库存产品 var psnOld = snDal.FindById(psn.id); psn.warehouse_product_id = ivtPdtTarget.id; psn.update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(); psn.update_user_id = userId; snDal.Update(psn); OperLogBLL.OperLogUpdate(OperLogBLL.CompareValue <ivt_warehouse_product_sn>(psnOld, psn), psn.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM_SN, "库存转移修改库存产品序号"); // 移库产品序列号 ivt_transfer_sn tsn = new ivt_transfer_sn(); tsn.id = snTrsfDal.GetNextIdCom(); tsn.create_time = Tools.Date.DateHelper.ToUniversalTimeStamp(); tsn.create_user_id = userId; tsn.update_time = tsn.create_time; tsn.update_user_id = userId; tsn.transfer_id = trsf.id; tsn.sn = psn.sn; snTrsfDal.Insert(tsn); OperLogBLL.OperLogAdd <ivt_transfer_sn>(tsn, tsn.id, userId, DicEnum.OPER_LOG_OBJ_CATE.INVENTORY_ITEM_TRANSFER_SN, "库存转移新增移库产品序列号"); } } return(true); }