Exemplo n.º 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));
        }