Beispiel #1
0
        /// <summary>
        /// 从DataTable中获取采购订单明细实体列表
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        private List <DAL.StockDetail> GetModelDetailFromDataTable(DataTable dt, out string msg, string SICode, string WHCode)
        {
            try
            {
                List <DAL.StockDetail> list = new List <DAL.StockDetail>();
                msg = "";

                //接口协议文档中定义的字段
                Dictionary <string, string> dataFieldNameDic = new Dictionary <string, string>();
                dataFieldNameDic.Add("BillCode", "其他入库单号");
                dataFieldNameDic.Add("DetailRowNumber", "行号");
                dataFieldNameDic.Add("CargoCode", "商品编码");
                dataFieldNameDic.Add("CargoName", "商品名称");
                dataFieldNameDic.Add("CargoSpec", "规格");
                dataFieldNameDic.Add("CargoModel", "型号");
                dataFieldNameDic.Add("CargoUnits", "单位");
                dataFieldNameDic.Add("NumOriginalPlan", "数量");
                dataFieldNameDic.Add("Remark", "备注");

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

                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 <StockDetail>());;
                }

                //遍历数据集创建实体
                foreach (DataRow dr in dt.Rows)
                {
                    StockDetail newModel = new StockDetail();

                    //newModel.BillCode= DataCheckHelper.GetCellString(dr["BillCode"]);
                    newModel.BillRowNumber = DataCheckHelper.GetCellString(dr["DetailRowNumber"]);
                    //商品编码
                    newModel.CargoCode = DataCheckHelper.GetCellString(dr["CargoCode"]);
                    string cargoCode = DbCommonMethod.ParsingCargoCode(newModel.CargoCode);
                    if (string.IsNullOrEmpty(cargoCode))
                    {
                        throw new ApplicationException("单号" + DataCheckHelper.GetCellString(dr["BillCode"]) + ",商品不存在:" + newModel.CargoCode);
                    }

                    newModel.CargoName  = DataCheckHelper.GetCellString(dr["CargoName"]);
                    newModel.CargoSpec  = DataCheckHelper.GetCellString(dr["CargoSpec"]);
                    newModel.CargoModel = DataCheckHelper.GetCellString(dr["CargoModel"]);
                    newModel.CargoUnits = DataCheckHelper.GetCellString(dr["CargoUnits"]);

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

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

                    newModel.NumCurrentPlan = newModel.NumOriginalPlan; //订单数量=应收数量,默认值
                    newModel.CargoStatus    = 0;                        //手持机未完成
                    newModel.SICode         = SICode;
                    newModel.BillCode       = newModel.SICode;
                    newModel.BillType       = CommonConvert.GetBillTypeCode("入库单");
                    newModel.InOutWHCode    = WHCode;

                    string             bill             = DataCheckHelper.GetCellString(dr["BillCode"]);
                    List <StockDetail> existStockDetail = (from r in list where r.BillCode == bill && r.BillRowNumber == newModel.BillRowNumber select r).ToList <StockDetail>();
                    if (existStockDetail == null || existStockDetail.Count == 0)//过滤重复数据
                    {
                        list.Add(newModel);
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return(new List <StockDetail>());;
            }
        }
Beispiel #2
0
        protected override void BindingOrderItem(object[] array)
        {
            if (_order.StockDetail == null)
            {
                _order.StockDetail = new EntityCollection <StockDetail>();
            }

            if (_itemDefine == null)
            {
                throw new ApplicationException("未发现行项目字段定义!");
            }

            if (_itemDefine.Count() == array.Count())
            {
                StockDetail orderItem = new StockDetail();
                for (int i = 0; i < array.Count(); i++)
                {
                    string fieldName  = Regex.Replace(_itemDefine[i].ToString(), @"\s", "");
                    string fieldValue = Regex.Replace(array[i].ToString(), @"\s", "");

                    switch (fieldName)
                    {
                    case "存货编码":
                        orderItem.CargoCode = fieldValue;
                        string cargoCode = DbCommonMethod.ParsingCargoCode(fieldValue);
                        if (string.IsNullOrEmpty(cargoCode))
                        {
                            throw new ApplicationException("商品不存在:" + fieldValue);
                        }
                        break;

                    case "商品名称":
                        orderItem.CargoName = fieldValue;
                        break;

                    case "规格":
                        orderItem.CargoSpec = fieldValue;
                        break;

                    case "型号":
                        //过滤型号值,如果型号是90.000,则去90,去掉小数点后面的0
                        double dou;
                        string strModel = fieldValue;
                        double douModel = 0;
                        if (double.TryParse(fieldValue, out dou))
                        {
                            douModel = dou;
                        }

                        if (douModel != 0 && strModel.Contains("."))
                        {
                            string sdecimal = strModel.Substring(strModel.IndexOf(".") + 1, strModel.Length - strModel.IndexOf(".") - 1);
                            int    istring  = Convert.ToInt32(sdecimal);
                            if (istring == 0)
                            {
                                strModel = fieldValue.Substring(0, fieldValue.IndexOf("."));
                            }
                        }
                        orderItem.CargoModel = strModel;
                        break;

                    case "单位":
                        orderItem.CargoUnits = fieldValue;
                        break;

                    case "数量":
                        if (!string.IsNullOrEmpty(fieldValue))
                        {
                            double d;
                            if (double.TryParse(fieldValue, out d))
                            {
                                orderItem.NumOriginalPlan = d;
                            }
                        }
                        break;

                    //暂留空,因为没看到有字段保存单价信息的(因为系统只管商品,不管金额,所以暂时不用存单价)
                    //case "销售单价":
                    //    if (!string.IsNullOrEmpty(fieldValue))
                    //    {
                    //        decimal d;
                    //        if (decimal.TryParse(fieldValue, out d))
                    //            orderItem.Price = d;
                    //    }
                    //    break;

                    case "销售金额":
                        if (!string.IsNullOrEmpty(fieldValue))
                        {
                            decimal de;
                            if (decimal.TryParse(fieldValue, out de))
                            {
                                orderItem.RowTotalMoney = de;
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
                if (string.IsNullOrEmpty(orderItem.BillRowNumber))
                {
                    orderItem.BillRowNumber = _rowNum.ToString();
                }

                orderItem.NumCurrentPlan = orderItem.NumOriginalPlan; //订单数量=应收数量,默认值
                orderItem.CargoStatus    = 0;                         //手持机未完成
                orderItem.BillCode       = _order.SOCode;
                orderItem.SOCode         = _order.SOCode;
                orderItem.BillType       = CommonConvert.GetBillTypeCode("出库单");
                orderItem.InOutWHCode    = _order.WHCode;
                orderItem.StockOut       = _order;
                IEnumerable <KeyValuePair <string, object> > entityKeyValues =
                    new KeyValuePair <string, object>[] {
                    new KeyValuePair <string, object>("BillCode", orderItem.BillCode),
                    new KeyValuePair <string, object>("BillRowNumber", orderItem.BillRowNumber)
                };
                orderItem.EntityKey = new EntityKey("GoldEntities.StockDetail", entityKeyValues);
                _order.StockDetail.Add(orderItem);
            }
        }