Beispiel #1
0
        private static bool AddSaleOrder(DataRow dr, SaleOder so, string userId, ref string error)
        {
            //要求交期、行号、客户产成品编号、版本、数量、是否是原材料
            string leadTime = "";
            string sql      = "";
            // string materialNumber = "";
            string version = dr["版本"].ToString() == "" ? "WU" : dr["版本"].ToString().ToUpper();
            string customerProductNumber = dr["客户产成品编号"].ToString();
            string productNumber         = "";

            try
            {
                leadTime = Convert.ToDateTime(dr["要求交期"]).ToString("yyyy-MM-dd");
            }
            catch (Exception ex)
            {
                error = string.Format("要求交期:{0},不是正规的日期格式‘yyyy-MM-dd’", dr["要求交期"]);
                return(false);
            }
            if (dr["是否是原材料"].ToString().Equals("是"))
            {
                sql           = string.Format(@" select 产成品编号 from
V_TradingQuoteDetailReport_New where 客户物料编号='{0}' and 客户名称='{1}'", customerProductNumber, so.CustomerName);
                productNumber = SqlHelper.GetScalar(sql);
                if (string.IsNullOrEmpty(productNumber))
                {
                    error = string.Format(" 系统不存在该客户物料编号:{0} 的报价信息,客户{1}", customerProductNumber, so.CustomerName);
                    return(false);
                }
                sql           = string.Format(@"
select MaterialNumber from MaterialCustomerProperty 
where CustomerMaterialNumber='{0}' and CustomerId='{1}'", customerProductNumber, so.CustomerId);
                productNumber = SqlHelper.GetScalar(sql);
                if (string.IsNullOrEmpty(productNumber))
                {
                    error = string.Format(" 系统不存在该客户物料编号:{0} 的原材料编号,客户{1}", customerProductNumber, so.CustomerName);
                    return(false);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(version))
                {
                    version = SellManager.GetMostNewVersion(customerProductNumber);
                }



                sql = string.Format(@"select 产成品编号 from V_FindLastNewPriceForMachineQuoteDeatil 
where 客户产成品编号='{0}' and 版本='{1}' and 客户名称='{2}'",
                                    customerProductNumber, version, so.CustomerName);
                productNumber = SqlHelper.GetScalar(sql);
                if (string.IsNullOrEmpty(productNumber))
                {
                    error = string.Format("系统不存在该客户产成品编号:{0},版本:{1}的报价信息,客户{2}", customerProductNumber, version, so.CustomerName);
                    return(false);
                }

                sql           = string.Format(@"
select ProductNumber from  ProductCustomerProperty 
 where CustomerProductNumber='{0}' and Version='{1}' and CustomerId='{2}'", customerProductNumber, version, so.CustomerId);
                productNumber = SqlHelper.GetScalar(sql);
                if (string.IsNullOrEmpty(productNumber))
                {
                    error = string.Format("系统不存在该客户产成品编号:{0},版本:{1}的产成品编号,客户{2}", customerProductNumber, version, so.CustomerName);
                    return(false);
                }

                if (!ProductManager.HasBOM(productNumber, version))
                {
                    error = string.Format("该产成品编号和版本找不到BOM信息,请先录入BOM!客户产成品编号:{0},产成品编号:{1},版本:{2}", customerProductNumber, productNumber, version);
                    return(false);
                }
            }


            sql = string.Format(" select count(*) from  T_ImpSaleOder_Temp where userId='{0}' and RowNumber='{1}'", userId, dr["行号"]);
            if (!SqlHelper.GetScalar(sql).Equals("0"))
            {
                error = string.Format("已存在相同行号:{0}", dr["行号"]);
                return(false);
            }
            //            if (dr["是否是原材料"].ToString().Equals("是"))
            //            {
            //                sql = string.Format(@" select count(*) from T_ImpSaleOder_Temp where ProductNumber='{0}' and LeadTime='{1}'
            //  and  IsMateriNumber='是'", productNumber, leadTime);
            //                if (!SqlHelper.GetScalar(sql).Equals("0"))
            //                {
            //                    error = string.Format("已存在相同交期的贸易销售订单明细!重复行: 客户物料号{0},交期{1}", customerProductNumber, leadTime);
            //                    return false;
            //                }
            //            }

            sql = string.Format(@" insert into T_ImpSaleOder_Temp (ProductNumber,version,
CustomerProductNumber,RowNumber,LeadTime,Qty,IsMateriNumber,UserId)
values('{0}','{1}','{2}','{3}','{4}',{5},'{6}','{7}')", productNumber, version, customerProductNumber, dr["行号"], leadTime
                                , dr["数量"], dr["是否是原材料"], userId);
            return(SqlHelper.ExecuteSql(sql, ref error));
        }
Beispiel #2
0
        /// <summary>
        /// 批量导入销售订单
        /// </summary>
        /// <param name="so"></param>
        /// <param name="FU_Excel"></param>
        /// <param name="server"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        public static bool BacthAddSaleOrder(SaleOder so, FileUpload FU_Excel, HttpServerUtility server, ref string error)
        {
            bool    result = false;
            DataSet ds     = ToolManager.ImpExcel(FU_Excel, server);

            if (ds == null)
            {
                error = "选择的文件为空或不是标准的Excel文件!";
                return(false);
            }
            DataTable dt = ds.Tables[0];

            if (so.ProductType.Equals("贸易"))
            {
                if (!dt.Columns.Contains("客户物料编号"))
                {
                    error = "导入模板与生产类型不一致!";
                    return(false);
                }
            }
            else
            {
                if (!dt.Columns.Contains("客户产成品编号"))
                {
                    error = "导入模板与生产类型不一致!";
                    return(false);
                }
            }

            //插入主表信息
            string sql = string.Format(@"insert into SaleOder (OdersNumber ,OrdersDate
,OdersType ,ProductType ,MakeCollectionsMode,CustomerId 
,ContactId ,CreateTime ,Remark ,CustomerOrderNumber,KhddH )
values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')", so.OrdersNumber, so.OrdersDate, so.OdersType
                                       , so.ProductType, so.MakeCollectionsMode, so.CustomerId, so.ContactId, so.CreateTime, so.Remark, so.CustomerOrderNumber, so.KhddH);

            SqlHelper.ExecuteSql(sql, ref error);
            //按照生产类型分别批量添加
            if (so.ProductType.Equals("贸易"))
            {
                List <TradingOrderDetail> tods = new List <TradingOrderDetail>();
                foreach (DataRow dr in dt.Rows)
                {
                    TradingOrderDetail tod = new TradingOrderDetail();
                    tod.OrdersNumber           = so.OrdersNumber;
                    tod.SN                     = dr["序号"].ToString();
                    tod.RowNumber              = dr["行号"].ToString();
                    tod.Delivery               = GetLeadTime(dr["交期"].ToString());
                    tod.CustomerMaterialNumber = dr["客户物料编号"].ToString();
                    tod.Quantity               = dr["订单数量"].ToString();
                    tod.Remark                 = dr["备注"].ToString();
                    tod.CustomerId             = so.CustomerId;

                    tods.Add(tod);
                }
                result = BacthAddTradingOrderDetail(tods, ref error);
            }
            else  // 序号	行号	交期	客户产成品编号	订单数量
            {
                List <MachineOderDetail> mods = new List <MachineOderDetail>();
                foreach (DataRow dr in dt.Rows)
                {
                    MachineOderDetail mod = new MachineOderDetail();
                    mod.OrdersNumber          = so.OrdersNumber;
                    mod.SN                    = dr["序号"].ToString();
                    mod.RowNumber             = dr["行号"].ToString();
                    mod.LeadTime              = GetLeadTime(dr["交期"].ToString());
                    mod.CustomerProductNumber = dr["客户产成品编号"].ToString();
                    mod.Qty                   = dr["订单数量"].ToString();
                    mod.CustomerId            = so.CustomerId;
                    mod.Version               = dr["版本"].ToString().ToUpper();
                    if (mod.Version.Equals(""))
                    {
                        mod.Version = SellManager.GetMostNewVersion(dr["客户产成品编号"].ToString());
                    }
                    else if (mod.Version.Equals("OO"))
                    {
                        mod.Version = "00";
                    }
                    mods.Add(mod);
                }
                result = BacthAddMachineOderDetail(mods, ref error);
            }
            return(result);
        }