Beispiel #1
0
        /// <summary>
        /// 从DataTable中获取实体列表
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        private List <DAL.StockIn> GetModelFromDataTable(DataTable dt, out string msg)
        {
            try
            {
                List <DAL.StockIn> list = new List <DAL.StockIn>();
                msg = "";

                //接口协议文档中定义的字段
                Dictionary <string, string> dataFieldNameDic = new Dictionary <string, string>();
                dataFieldNameDic.Add("BillCode", "其他入库单号");
                dataFieldNameDic.Add("BillDate", "日期");
                dataFieldNameDic.Add("InCategory", "收发类别");
                dataFieldNameDic.Add("Supplier", "供货单位");
                dataFieldNameDic.Add("BusinessDepartmentName", "业务部门");
                dataFieldNameDic.Add("Operator", "业务员姓名");
                dataFieldNameDic.Add("WHName", "仓库名称");
                dataFieldNameDic.Add("StoreKeeper", "库管员");
                dataFieldNameDic.Add("Comment", "备注");
                dataFieldNameDic.Add("TotalNumber", "合计数量");
                dataFieldNameDic.Add("WareHouseKeeper", "仓管");
                dataFieldNameDic.Add("Checker", "验收");

                if (dt == null || dt.Rows.Count == 0)
                {
                    msg = "用友系统返回数据集中无数据!";
                    return(new List <StockIn>());
                }

                StringBuilder errorColName = new StringBuilder();
                //检查数据集中是否存在指定字段
                foreach (KeyValuePair <string, string> kvp in dataFieldNameDic)
                {
                    if (dt.Columns.Contains(kvp.Key) == false)
                    {
                        errorColName.Append(Environment.NewLine);
                        errorColName.Append(kvp.Value);
                        errorColName.Append("-");
                        errorColName.Append(kvp.Key);
                    }
                }
                if (errorColName.Length > 0)
                {
                    errorColName.Insert(0, "用友系统返回的数据集中未包含如下字段,不能进行有效解析!");
                    msg = errorColName.ToString();
                    return(new List <StockIn>());;
                }

                //遍历数据集创建实体
                foreach (DataRow dr in dt.Rows)
                {
                    StockIn newModel = new StockIn();
                    //newModel.SICode = KeyGenerator.Instance.GetStockInKey();
                    newModel.FromBillNo = DataCheckHelper.GetCellString(dr["BillCode"]);

                    //日期
                    if (!string.IsNullOrEmpty(DataCheckHelper.GetCellString(dr["BillDate"])))
                    {
                        DateTime d;
                        if (DateTime.TryParse(DataCheckHelper.GetCellString(dr["BillDate"]), out d))
                        {
                            newModel.SIDate = d;
                        }
                    }

                    //收发类别
                    newModel.InCategory = DbCommonMethod.GetInCategory(DataCheckHelper.GetCellString(dr["InCategory"]));

                    newModel.Supplier = DataCheckHelper.GetCellString(dr["Supplier"]);
                    newModel.BusinessDepartmentName = DataCheckHelper.GetCellString(dr["BusinessDepartmentName"]);
                    newModel.Operator = DataCheckHelper.GetCellString(dr["Operator"]);

                    //仓库
                    newModel.WHName = DataCheckHelper.GetCellString(dr["WHName"]);
                    newModel.WHCode = DbCommonMethod.ParsingWarehouse(newModel.WHName);
                    if (string.IsNullOrEmpty(newModel.WHCode))
                    {
                        throw new ApplicationException("单号" + newModel.FromBillNo + ",仓库不存在:" + newModel.WHName);
                    }

                    newModel.StoreKeeper = DataCheckHelper.GetCellString(dr["StoreKeeper"]);
                    newModel.Comment     = DataCheckHelper.GetCellString(dr["Comment"]);

                    //合计数量
                    if (!string.IsNullOrEmpty(DataCheckHelper.GetCellString(dr["TotalNumber"])))
                    {
                        double d;
                        if (double.TryParse(DataCheckHelper.GetCellString(dr["TotalNumber"]), out d))
                        {
                            newModel.TotalNumber = d;
                        }
                    }

                    //newModel = DataCheckHelper.GetCellString(dr["WareHouseKeeper"]);
                    newModel.Checker = DataCheckHelper.GetCellString(dr["Checker"]);

                    newModel.SIStatus     = 1;    //已保存
                    newModel.FromBillType = "23"; //21采购入库单、22调拨入库单、23其他入库单
                    newModel.SIType       = CommonConvert.GetSIOTypeCode("其他入库单");
                    newModel.FromType     = CommonConvert.GetFromTypeCode("源于Excel导入的入库单");

                    List <StockIn> existStockIn = (from r in list where r.FromBillNo == newModel.FromBillNo select r).ToList <StockIn>();
                    if (existStockIn == null || existStockIn.Count == 0)//过滤重复数据
                    {
                        list.Add(newModel);
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return(new List <StockIn>());;
            }
        }
Beispiel #2
0
        //保存数据
        public override string SaveData()
        {
            if (string.IsNullOrEmpty(_stockIn.SIType))
            {
                _stockIn.SIType = "22";//调拨入库单
            }
            if (string.IsNullOrEmpty(_stockIn.FromType))
            {
                _stockIn.FromType = CommonConvert.GetFromTypeCode("源于Excel导入的入库单");
            }

            _stockIn.SIStatus     = 1;    //已保存
            _stockIn.FromBillType = "22"; //21采购入库单、22调拨入库单、23其他入库单
            _stockIn.EditStatus   = 0;    //无人编辑

            StringBuilder sb = new StringBuilder();

            using (var edm = new Gold.DAL.GoldEntities())
            {
                try
                {
                    var tmp = edm.StockIn.SingleOrDefault(o => o.SICode == _stockIn.SICode);
                    if (tmp == null)
                    {
                        edm.StockIn.AddObject(_stockIn);
                    }
                    else
                    {
                        if (tmp.SIStatus == 2)
                        {
                            throw new Exception("此入库单(" + tmp.SICode + ")已提交,不允许再次上传!");
                        }
                        else if (tmp.SIStatus == 5)
                        {
                            throw new Exception("此入库单(" + tmp.SICode + ")正在撤销中,不允许再次上传!");
                        }
                        else if (tmp.SIStatus == 3)
                        {
                            throw new Exception("此入库单(" + tmp.SICode + ")入库已完成,不允许再次上传!");
                        }
                        else if (tmp.SIStatus == 4)//已撤销,则默认是全部撤销,用户可重新上传而不是覆盖
                        {
                            //_stockIn.SICode = KeyGenerator.Instance.GetStockInKey();
                            //foreach (StockDetail sd in _stockIn.StockDetail)
                            //{
                            //    sd.BillCode = _stockIn.SICode;
                            //    sd.SOCode = _stockIn.SICode;
                            //}
                            //edm.StockIn.AddObject(_stockIn);
                            throw new Exception("此入库单(" + tmp.SICode + ")已完成撤销,不允许再次上传!");
                        }
                        else
                        {
                            List <StockDetail> lstDetail = new List <StockDetail>();
                            foreach (StockDetail oldDetail in tmp.StockDetail)
                            {
                                lstDetail.Add(oldDetail);

                                //如果实收数量为0,则直接删除
                                if (oldDetail.NumActual == 0)
                                {
                                    continue;
                                }
                                else
                                {
                                    bool isExist = false;//是否新旧订单都有此商品
                                    foreach (StockDetail newDetail in _stockIn.StockDetail)
                                    {
                                        //判断在当前的新excel中是否有此商品,如果有,则保存实收数量
                                        if (newDetail.CargoCode == oldDetail.CargoCode)
                                        {
                                            newDetail.NumActual = oldDetail.NumActual;
                                            isExist             = true;
                                            break;
                                        }
                                    }
                                    if (isExist)
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        //如果当前新excel没有此商品,则直接添加
                                        StockDetail sd = new StockDetail();
                                        sd.BillCode          = oldDetail.BillCode;
                                        sd.BillRowNumber     = oldDetail.BillRowNumber;
                                        sd.BillType          = oldDetail.BillType;
                                        sd.BinCode           = oldDetail.BinCode;
                                        sd.BinName           = oldDetail.BinName;
                                        sd.CargoCode         = oldDetail.CargoCode;
                                        sd.CargoModel        = oldDetail.CargoModel;
                                        sd.CargoName         = oldDetail.CargoName;
                                        sd.CargoSpec         = oldDetail.CargoSpec;
                                        sd.CargoStatus       = oldDetail.CargoStatus;
                                        sd.CargoUnits        = oldDetail.CargoUnits;
                                        sd.Comment           = oldDetail.Comment;
                                        sd.HandSetFinishTime = oldDetail.HandSetFinishTime;
                                        sd.HandSetPersonID   = oldDetail.HandSetPersonID;
                                        sd.HandSetPersonName = oldDetail.HandSetPersonName;
                                        sd.InOutWHCode       = oldDetail.InOutWHCode;
                                        sd.InOutWHName       = oldDetail.InOutWHName;
                                        sd.NumActual         = oldDetail.NumActual;
                                        sd.NumCurrentPlan    = oldDetail.NumCurrentPlan;
                                        sd.NumOriginalPlan   = oldDetail.NumOriginalPlan;
                                        sd.ReleaseYear       = oldDetail.ReleaseYear;
                                        sd.Reserve1          = oldDetail.Reserve1;
                                        sd.Reserve2          = oldDetail.Reserve2;
                                        sd.RFIDOrderNo       = oldDetail.RFIDOrderNo;
                                        sd.RFIDSubmitTime    = oldDetail.RFIDSubmitTime;
                                        sd.RowTotalMoney     = oldDetail.RowTotalMoney;
                                        sd.SICode            = oldDetail.SICode;
                                        sd.UCOrderNo         = oldDetail.UCOrderNo;

                                        _stockIn.StockDetail.Add(sd);
                                    }
                                }
                            }

                            //由于遍历原数据行项目,导致后续删除无法级联删除。故先删除行项目。
                            foreach (StockDetail detail in lstDetail)
                            {
                                edm.StockDetail.DeleteObject(detail);
                                edm.SaveChanges();
                            }

                            edm.StockIn.DeleteObject(tmp);
                            edm.SaveChanges();
                            edm.StockIn.AddObject(_stockIn);
                        }
                    }

                    edm.SaveChanges();
                    sb.AppendLine("保存成功!");
                }
                catch (Exception ex)
                {
                    sb.Append("保存数据时发生异常:");
                    string msg = Utility.LogHelper.GetExceptionMsg(ex);
                    sb.Append(msg);

                    Utility.LogHelper.WriteLog(Utility.LogHelper.LogLevel.Error, "调拨入库单保存异常", ex);
                }
            }

            return(sb.ToString());
        }
Beispiel #3
0
        /// <summary>
        /// 从DataTable中获取实体列表
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        private List <DAL.StockOut> GetModelFromDataTable(DataTable dt, out string msg)
        {
            try
            {
                List <DAL.StockOut> list = new List <DAL.StockOut>();
                msg = "";

                //接口协议文档中定义的字段
                Dictionary <string, string> dataFieldNameDic = new Dictionary <string, string>();
                dataFieldNameDic.Add("BillCode", "其他出库单号");
                dataFieldNameDic.Add("BillDate", "日期");
                dataFieldNameDic.Add("OutCategory", "收发类别");
                dataFieldNameDic.Add("OutWHName", "发出仓库");
                dataFieldNameDic.Add("Comment", "备注");
                dataFieldNameDic.Add("TotalNumber", "合计数量");
                dataFieldNameDic.Add("LeaderSign", "领导");
                dataFieldNameDic.Add("WareHouseKeeper", "仓管");
                dataFieldNameDic.Add("AccountSign", "财务");
                dataFieldNameDic.Add("BusinessSign", "经办人");
                dataFieldNameDic.Add("EditorSign", "制单人");

                if (dt == null || dt.Rows.Count == 0)
                {
                    msg = "用友系统返回数据集中无数据!";
                    return(new List <StockOut>());
                }

                StringBuilder errorColName = new StringBuilder();
                //检查数据集中是否存在指定字段
                foreach (KeyValuePair <string, string> kvp in dataFieldNameDic)
                {
                    if (dt.Columns.Contains(kvp.Key) == false)
                    {
                        errorColName.Append(Environment.NewLine);
                        errorColName.Append(kvp.Value);
                        errorColName.Append("-");
                        errorColName.Append(kvp.Key);
                    }
                }
                if (errorColName.Length > 0)
                {
                    errorColName.Insert(0, "用友系统返回的数据集中未包含如下字段,不能进行有效解析!");
                    msg = errorColName.ToString();
                    return(new List <StockOut>());;
                }

                //遍历数据集创建实体
                foreach (DataRow dr in dt.Rows)
                {
                    StockOut newModel = new StockOut();
                    //newModel.SOCode = KeyGenerator.Instance.GetStockOutKey();
                    newModel.FromBillNo = DataCheckHelper.GetCellString(dr["BillCode"]);

                    //日期
                    if (!string.IsNullOrEmpty(DataCheckHelper.GetCellString(dr["BillDate"])))
                    {
                        DateTime d;
                        if (DateTime.TryParse(DataCheckHelper.GetCellString(dr["BillDate"]), out d))
                        {
                            newModel.SODate = d;
                        }
                    }

                    //收发类别
                    newModel.OutCategory = DbCommonMethod.GetOutCategory(DataCheckHelper.GetCellString(dr["OutCategory"]));

                    newModel.WHName = DataCheckHelper.GetCellString(dr["OutWHName"]);
                    newModel.WHCode = DbCommonMethod.ParsingWarehouse(newModel.WHName);
                    if (string.IsNullOrEmpty(newModel.WHCode))
                    {
                        throw new ApplicationException("单号" + newModel.FromBillNo + ",仓库不存在:" + newModel.WHName);
                    }

                    newModel.Comment = DataCheckHelper.GetCellString(dr["Comment"]);

                    //合计数量
                    if (!string.IsNullOrEmpty(DataCheckHelper.GetCellString(dr["TotalNumber"])))
                    {
                        decimal d;
                        if (decimal.TryParse(DataCheckHelper.GetCellString(dr["TotalNumber"]), out d))
                        {
                            newModel.TotalMoney = d;
                        }
                    }

                    newModel.LeaderSign    = DataCheckHelper.GetCellString(dr["LeaderSign"]);
                    newModel.WarehouseSign = DataCheckHelper.GetCellString(dr["WareHouseKeeper"]);
                    newModel.AccountSign   = DataCheckHelper.GetCellString(dr["AccountSign"]);
                    newModel.BusinessSign  = DataCheckHelper.GetCellString(dr["BusinessSign"]);
                    newModel.EditorSign    = DataCheckHelper.GetCellString(dr["EditorSign"]);

                    newModel.SOStatus     = 1;    //已保存
                    newModel.FromBillType = "13"; //11-销售出库单、12-调拨出库单、13-其他出库单
                    newModel.EditStatus   = 0;    //无人编辑
                    newModel.SOType       = CommonConvert.GetSIOTypeCode("其他出库单");
                    newModel.FromType     = CommonConvert.GetFromTypeCode("源于Excel导入的出库单");

                    List <StockOut> existStockOut = (from r in list where r.FromBillNo == newModel.FromBillNo select r).ToList <StockOut>();
                    if (existStockOut == null || existStockOut.Count == 0)//过滤重复数据
                    {
                        list.Add(newModel);
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return(new List <StockOut>());;
            }
        }