示例#1
0
        /// <summary>
        /// 根据合同状态,创建人,签订日期查询合同列表
        /// </summary>
        /// <param name="state">合同状态</param>
        /// <param name="createUID">创建人</param>
        /// <param name="beginSigningDate">开始签订日期</param>
        /// <param name="endSigningDate">结束签订日期</param>
        /// <returns>合同列表</returns>
        public object GetContractListBySearch(int state, string createUID, string beginSigningDate, string endSigningDate, out int recordCount)
        {
            DataTable dt   = dal.GetContractListBySearch(state, createUID, beginSigningDate, endSigningDate, out recordCount);
            var       list = DBHelper.ToEntity.ToList <Contract>(dt);

            if (list == null || !list.Any())
            {
                return(null);
            }

            var classify = SysDataDictService.GetContractClassify();

            var obj = list.Select(c => new
            {
                c.Id,
                c.ContractSN,
                c.State,
                c.Title,
                Version = (c.Version == 1) ? ("新增 v" + c.Version + ".0") : ("续签 v" + c.Version + ".0"),
                c.ClassifyId,
                c.StartDate,
                c.EndDate,
                CreateDT = c.CreateDT.ToString("yyyy-MM-dd"),
                c.CreateUID,
                c.CreateTitle,
                StateTitle = Enum.GetName(typeof(ContractState), c.State),
                c.SupplierTitle,
                ClassifyTitle = GetClassifyTitle(classify, c.ClassifyId),
                c.AttCount,
                c.isExtend
            }).ToList();

            return(obj);
        }
示例#2
0
        /// <summary>
        /// 退换详情
        /// </summary>
        /// <param name="returnId">退换Id</param>
        /// <returns>商品退换详细信息</returns>
        public static object FindByReturnId(int returnId)
        {
            var queryOrderReturn       = BaseService <OrderReturns> .CurrentRepository.QueryEntity;
            var queryOrderList         = BaseService <IndentOrderList> .CurrentRepository.QueryEntity;
            var queryProduct           = BaseService <VwProduct> .CurrentRepository.QueryEntity;
            var queryOrderDistribution = BaseService <OrderDistribution> .CurrentRepository.QueryEntity;
            var queryIndentOrder       = BaseService <VwOrder> .CurrentRepository.QueryEntity;
            var query = from x in queryOrderReturn
                        join y in queryOrderList on new { x.IndentOrderId, x.Barcode } equals new { y.IndentOrderId, y.Barcode }
            join z in queryOrderDistribution on x.DistributionId equals z.DistributionId
            join a in queryProduct on x.Barcode equals a.Barcode into tempProduct
            from h in tempProduct.DefaultIfEmpty()
            join i in queryIndentOrder on y.IndentOrderId equals i.IndentOrderId
            where x.Id == returnId
                select new
            {
                x.Id,
                x.DistributionId,
                h.ProductCode,
                h.Barcode,
                h.Title,
                y.IndentNum,
                h.SubUnit,
                y.DeliveryNum,
                i.CreateDT,                 //订货日期
                y.AcceptNum,
                i.DeliveryDate,             //收货日期
                x.ReturnType,
                x.ReasonId,
                x.ReturnNum
            };

            var list   = query.ToList();
            var reason = SysDataDictService.GetReasonTitle();
            var obj    = list.Select(o => new
            {
                o.Id,
                o.ProductCode,
                o.Barcode,
                o.Title,
                IndentNum = o.IndentNum.ToAutoString(3),
                o.SubUnit,
                DeliveryNum = o.DeliveryNum.ToAutoString(3),
                CreateDT    = o.CreateDT.ToString("yyyy-MM-dd"), //订货日期
                AcceptNum   = o.AcceptNum.ToAutoString(3),
                o.DeliveryDate,                                  //收货日期
                o.ReturnType,
                o.ReasonId,
                ReturnNum = (o.ReturnNum ?? 0).ToAutoString(3),
                ReType    = Enum.GetName(typeof(OrderReturnType), o.ReturnType),
                ReReason  = GetReasonTitle(reason, o.ReasonId)
            }).FirstOrDefault();

            return(obj);
        }
        public static IList <SysDataDictionary> GetDictionaryItems(int psn)
        {
            var pids  = SysDataDictService.CurrentRepository.QueryEntity.Where(o => o.CompanyId == CommonService.CompanyId).Select(o => o.DicPSN).Distinct();
            var items = SysDataDictService.FindList(o => o.DicPSN == psn && o.CompanyId == CommonService.CompanyId);

            IList <SysDataDictionary> dict = new List <SysDataDictionary>();

            if (!items.Exists(o => pids.Contains(o.DicSN)))
            {
                dict = items;
            }

            return(dict);
        }
        public static OpResult Import(ImportSet obj, System.Web.HttpFileCollectionBase httpFiles, string fieldName, string columnName)
        {
            var op    = new OpResult();
            var errLs = new List <string>();
            int count = 0;

            try
            {
                Dictionary <string, char> fieldCols = null;
                DataTable dt = null;
                op = ImportSetService.ImportSet(obj, httpFiles, fieldName, columnName, ref fieldCols, ref dt);
                if (!op.Successed)
                {
                    return(op);
                }
                var brandClass = SysDataDictService.FindList(o => o.DicPSN == (int)DicType.品牌分类 && o.CompanyId == CommonService.CompanyId);
                var otherClass = brandClass.FirstOrDefault(o => o.Title.StartsWith("其"));
                var brands     = GetAllProductBrands(null).ToList();
                var max        = SysDataDictService.GetMaxSN;
                var clsIdx     = Convert.ToInt32(fieldCols["ClassifyId"]) - 65;
                var titleIdx   = Convert.ToInt32(fieldCols["Title"]) - 65;
                count = dt.Rows.Count;
                for (int i = dt.Rows.Count - 1; i >= 0; i--)
                {
                    try
                    {
                        var dr   = dt.Rows[i];
                        var text = dr[clsIdx].ToString();
                        if (text.IsNullOrEmpty())
                        {
                            continue;
                        }
                        var cls = brandClass.FirstOrDefault(o => o.Title == text);
                        if (cls != null)
                        {
                            dr[clsIdx] = cls.DicSN.ToString();
                        }
                        else
                        {
                            if (obj.RefCreate)
                            {
                                var data = new Sys.Entity.SysDataDictionary()
                                {
                                    DicPSN    = (int)DicType.品牌分类,
                                    DicSN     = max++,
                                    Status    = true,
                                    Title     = text,
                                    CompanyId = CommonService.CompanyId
                                };
                                SysDataDictService.Add(data);
                                brandClass.Add(data);
                                dr[clsIdx] = data.DicSN.ToString();
                            }
                            else if (otherClass != null)
                            {
                                dr[clsIdx] = otherClass.DicSN.ToString();
                            }
                            else
                            {
                                errLs.Add("品牌分类[" + text + "]不存在!");
                                dt.Rows.RemoveAt(i);//去除不导入
                                continue;
                            }
                        }
                        text = dr[titleIdx].ToString().Trim();
                        if (brands.Any(o => o.Title == text))
                        {
                            errLs.Add("品牌名称[" + text + "]已存在!");
                            dt.Rows.RemoveAt(i);//去除不导入
                        }
                        else
                        {
                            brands.Add(new ProductBrand()
                            {
                                Title = text
                            });
                        }
                    }
                    catch (Exception e)
                    {
                        throw new Exception("品牌分类处理失败!", e);
                    }
                }
                max = MaxSN;
                StringBuilder sb = new StringBuilder();
                sb.Append("begin tran ");
                foreach (DataRow dr in dt.Rows)
                {
                    sb.Append("insert into ");
                    sb.Append(obj.TableName);
                    sb.Append("(CompanyId,BrandSN,State,");
                    sb.Append(string.Join(",", fieldCols.Keys));
                    sb.Append(") values(");
                    sb.AppendFormat("{0},", obj.CompanyId);
                    sb.AppendFormat("{0},", max++);
                    sb.AppendFormat("1,");
                    foreach (var de in fieldCols)
                    {
                        var index = Convert.ToInt32(de.Value) - 65;
                        try
                        {
                            var text = dr[index].ToString();
                            sb.Append("'" + text + "',");
                        }
                        catch (Exception e)
                        {
                            throw new Exception("列选择超过范围!", e);
                        }
                    }
                    sb = sb.Remove(sb.Length - 1, 1);
                    sb.Append(");");
                }
                sb.Append(" commit tran");
                op.Successed = new Pharos.Logic.DAL.CommonDAL()._db.ExecuteNonQueryText(sb.ToString(), null) > 0;
                Log.WriteInsert("品牌导入", Sys.LogModule.档案管理);
            }
            catch (Exception ex)
            {
                op.Message   = ex.Message;
                op.Successed = false;
                Log.WriteError(ex);
                errLs.Add("导入出现异常!");
            }
            return(CommonService.GenerateImportHtml(errLs, count));
        }
        public static bool HasItems(int psn)
        {
            var pids = SysDataDictService.CurrentRepository.QueryEntity.Select(o => o.DicPSN).Distinct();

            return(SysDataDictService.IsExist(o => o.DicPSN == psn && !pids.Contains(o.DicSN)));
        }
 public static IList <SysDataDictionary> GetDictionaryList(DicType psn = DicType.全部)
 {
     return(SysDataDictService.FindList(o => o.DicPSN == (int)psn && o.CompanyId == CommonService.CompanyId));
 }
示例#7
0
        /// <summary>
        /// 退换管理列表
        /// </summary>
        /// <param name="nvl">查询条件</param>
        /// <param name="recordCount">总记录数</param>
        /// <returns>订货退换列表</returns>
        public static object OrderReturnList(NameValueCollection nvl, out int recordCount)
        {
            var queryOrderReturn = BaseService <OrderReturns> .CurrentRepository.QueryEntity.Where(o => o.CompanyId == CommonService.CompanyId);

            var queryOrderList = BaseService <IndentOrderList> .CurrentRepository.QueryEntity;
            var queryProduct   = BaseService <VwProduct> .CurrentRepository.QueryEntity.Where(o => o.CompanyId == CommonService.CompanyId);

            var queryOrderDistribution = BaseService <OrderDistribution> .CurrentRepository.QueryEntity.Where(o => o.CompanyId == CommonService.CompanyId);

            var queryIndentOrder = BaseService <VwOrder> .CurrentRepository.QueryEntity.Where(o => o.CompanyId == CommonService.CompanyId);

            var    queryUser = UserInfoService.CurrentRepository.QueryEntity.Where(o => o.CompanyId == CommonService.CompanyId);
            string userID    = Pharos.Sys.SupplierUser.SupplierId;
            var    query     = from x in queryOrderReturn
                               join y in queryOrderList on x.IndentOrderId equals y.IndentOrderId
                               join z in queryOrderDistribution on x.DistributionId equals z.DistributionId
                               join a in queryProduct on x.Barcode equals a.Barcode into tempProduct
                               from h in tempProduct.DefaultIfEmpty()
                               join i in queryIndentOrder on y.IndentOrderId equals i.IndentOrderId
                               join j in queryUser on x.CreateUID equals j.UID into tempUser
                               from k in tempUser.DefaultIfEmpty()
                               where (x.Barcode == y.Barcode && i.SupplierID == userID)
                               select new
            {
                x.Id,
                x.ReturnType,
                x.State,
                h.ProductCode,
                h.Barcode,
                h.Title,
                h.BrandTitle,
                h.SubUnit,
                x.ReturnNum,
                y.Price,
                x.CreateDT,
                i.StoreId,
                i.StoreTitle,
                x.Memo,
                x.CreateUID,
                CreateTitle = k.FullName,
            };
            var returnType  = nvl["ReturnType"];
            var returnState = nvl["State"];
            var searchText  = nvl["SearchText"];

            if (!returnType.IsNullOrEmpty())
            {
                var rt = short.Parse(returnType);
                query = query.Where(r => r.ReturnType == rt);
            }
            if (!returnState.IsNullOrEmpty())
            {
                var rs = short.Parse(returnState);
                query = query.Where(r => r.State == rs);
            }

            if (!searchText.IsNullOrEmpty())
            {
                query = query.Where(r => (r.ProductCode != null && r.ProductCode.Contains(searchText)) ||
                                    (r.Title != null && r.Title.Contains(searchText)));
            }


            recordCount = query.Count();
            var reason = SysDataDictService.GetReasonTitle();

            return(query.ToPageList(nvl).Select(o => new
            {
                o.Id,
                o.ReturnType,
                o.State,
                o.ProductCode,
                o.Barcode,
                o.Title,
                o.BrandTitle,
                o.SubUnit,
                ReturnNum = (o.ReturnNum ?? 0).ToAutoString(3),
                o.Price,
                o.CreateDT,
                o.StoreId,
                o.StoreTitle,
                o.Memo,
                o.CreateUID,
                o.CreateTitle,
                StateTitle = Enum.GetName(typeof(OrderReturnState), o.State),
                ReType = Enum.GetName(typeof(OrderReturnType), o.ReturnType),
            }));
        }
示例#8
0
        /// <summary>
        /// 退换详情(收货明细使用)
        /// </summary>
        /// <param name="returnId"></param>
        /// <returns></returns>
        public static object FindDetailById(int returnId)
        {
            var queryOrderReturn       = BaseService <OrderReturns> .CurrentRepository.QueryEntity;
            var queryOrderList         = BaseService <IndentOrderList> .CurrentRepository.QueryEntity;
            var queryProductRecord     = BaseService <VwProduct> .CurrentRepository.QueryEntity;
            var queryOrderDistribution = BaseService <OrderDistribution> .CurrentRepository.QueryEntity;
            var queryIndentOrder       = BaseService <VwOrder> .CurrentRepository.QueryEntity;
            var query = from x in queryOrderReturn
                        join y in queryOrderList on x.IndentOrderId equals y.IndentOrderId
                        join z in queryOrderDistribution on x.DistributionId equals z.IndentOrderId
                        join h in queryProductRecord on y.Barcode equals h.Barcode
                        join i in queryIndentOrder on y.IndentOrderId equals i.IndentOrderId
                        where x.Id == returnId
                        select new
            {
                x.Id,
                x.DistributionId,
                h.ProductCode,
                h.Barcode,
                h.Title,
                y.IndentNum,
                h.SubUnit,
                z.DeliveryNum,
                i.CreateDT,                 //订货日期
                z.ReceivedNum,
                z.ReceivedDT,
                i.DeliveryDate,             //收货日期
                x.ReturnType,
                x.ReasonId,
                x.ReturnNum,
                z.DistributionBatch,
                x.IndentOrderId,
                h.ValuationType
            };

            var list   = query.ToList();
            var reason = SysDataDictService.GetReasonTitle();
            var obj    = list.Select(o => new
            {
                o.Id,
                o.ProductCode,
                o.Barcode,
                o.Title,
                IndentNum = o.IndentNum.ToAutoString(3) + o.SubUnit,
                o.SubUnit,
                DeliveryNum = (o.DeliveryNum ?? 0).ToAutoString(3) + o.SubUnit,
                o.CreateDT,     //订货日期
                ReceivedNum = (o.ReceivedNum ?? 0).ToAutoString(3) + o.SubUnit,
                ReceiveNum  = (o.ReceivedNum ?? 0).ToAutoString(3),
                o.ReceivedDT, //收货日期
                o.ReturnType,
                o.ReasonId,
                ReturnNum    = (o.ReturnNum ?? 0).ToAutoString(3),
                ReceivedNums = ReceivedNums(o.IndentOrderId, o.Barcode).ToAutoString(3) + o.SubUnit,
                o.DistributionBatch,
                o.IndentOrderId,
                o.DistributionId,
                o.ValuationType
            }).FirstOrDefault();

            return(obj);
        }
        /// <summary>
        /// 退货管理列表
        /// </summary>
        /// <param name="nvl">查询条件</param>
        /// <param name="recordCount">总记录数</param>
        /// <returns>退换管理列表</returns>
        public static object CommodityReturnList(NameValueCollection nvl, out int recordCount)
        {
            var queryCommodityReturn = BaseService <CommodityReturns> .CurrentRepository.QueryEntity.Where(o => o.CompanyId == CommonService.CompanyId);

            var queryReturnDetail = BaseService <CommodityReturnsDetail> .CurrentRepository.QueryEntity;
            var queryStore        = BaseService <Warehouse> .CurrentRepository.QueryEntity.Where(o => o.CompanyId == CommonService.CompanyId);

            var queryUser     = UserInfoService.CurrentRepository.QueryEntity.Where(o => o.CompanyId == CommonService.CompanyId);
            var querySupplier = BaseService <Supplier> .CurrentRepository.QueryEntity.Where(o => o.CompanyId == CommonService.CompanyId);

            var groupbyReturnDetail = from a in queryReturnDetail

                                      group a by a.ReturnId into g
                                      select new
            {
                g.Key,
                TotalPrice = g.Sum(a => a.BuyPrice * a.ReturnNum),
                TotalNum   = g.Sum(a => a.ReturnNum)
            };

            var query = from x in queryCommodityReturn
                        join j in queryUser on x.CreateUID equals j.UID into tempUser
                        from k in tempUser.DefaultIfEmpty()
                        join l in queryStore on new { x.CompanyId, x.StoreId } equals new { l.CompanyId, l.StoreId }
            join m in groupbyReturnDetail on x.ReturnId equals m.Key
            join n in querySupplier on x.SupplierID equals n.Id into temp3
            from p in temp3.DefaultIfEmpty()
            select new
            {
                x.Id,
                x.ReturnId,
                x.State,
                x.CreateDT,
                x.CreateUID,
                CreateTitle = k.FullName,
                StoreTitle  = l.Title,
                m.TotalPrice,
                m.TotalNum,
                SupplierTitle = p.Title,
                x.VerifyTime
            };
            var returnType  = nvl["ReturnType"];
            var returnState = nvl["State"];
            var searchText  = nvl["SearchText"].Trim();

            if (!returnState.IsNullOrEmpty())
            {
                var rs = short.Parse(returnState);
                query = query.Where(r => r.State == rs);
            }
            if (!searchText.IsNullOrEmpty())
            {
                query = query.Where(r => (r.ReturnId != null && r.ReturnId.Contains(searchText)));
            }

            recordCount = query.Count();
            var reason = SysDataDictService.GetReasonTitle();

            return(query.ToPageList(nvl).Select(o => new
            {
                o.Id,
                o.ReturnId,
                o.State,
                o.StoreTitle,
                CreateDT = o.CreateDT.ToString("yyyy-MM-dd"),
                VerifyDTStr = o.VerifyTime.HasValue ? o.VerifyTime.Value.ToString("yyyy-MM-dd") : "",
                o.CreateUID,
                o.CreateTitle,
                o.SupplierTitle,
                StateTitle = Enum.GetName(typeof(OrderReturnState), o.State),
                TotalNum = o.TotalNum.ToAutoString(3),
                TotalPrice = o.TotalPrice.ToAutoString()
            }));
        }
示例#10
0
        public static OpResult SaveOrUpdate(Supplier obj)
        {
            var re                        = new OpResult();
            var classify                  = SysDataDictService.GetSupplierTypes();
            List <SysUserInfo> list       = new List <SysUserInfo>();
            string             desig      = GetUser(obj.Designee, list);
            string             stateTitle = obj.MasterState == 1 ? "可用" : "关闭";

            obj.CompanyId = CommonService.CompanyId;
            if (!obj.MasterAccount.IsNullOrEmpty() && SupplierService.IsExist(o => o.Id != obj.Id && o.MasterAccount == obj.MasterAccount && o.BusinessType == 1 && o.CompanyId == obj.CompanyId))
            {
                re.Message = "账号已存在";
            }
            else if (!obj.Title.IsNullOrEmpty() && SupplierService.IsExist(o => o.Id != obj.Id && o.Title == obj.Title && o.BusinessType == 1 && o.CompanyId == obj.CompanyId))
            {
                re.Message = "供应商简称已存在";
            }
            else if (!obj.FullTitle.IsNullOrEmpty() && SupplierService.IsExist(o => o.Id != obj.Id && o.FullTitle == obj.FullTitle && o.BusinessType == 1 && o.CompanyId == obj.CompanyId))
            {
                re.Message = "供应商全称已存在";
            }
            else if (obj.Id.IsNullOrEmpty())
            {
                obj.Id           = Logic.CommonRules.GUID;
                obj.BusinessType = 1;
                re = SupplierService.Add(obj);
                #region 写入日志
                string msg    = "成功新增供应商!";
                var    module = Pharos.Sys.LogModule.档案管理;
                if (re.Successed)
                {
                    string designee = (string.IsNullOrEmpty(obj.Designee) && string.IsNullOrEmpty(desig)) ? "" : ",指派人=" + desig;
                    string phoneNum = string.IsNullOrEmpty(obj.MobilePhone) ? "" : ",手机=" + obj.MobilePhone;
                    string telNum   = string.IsNullOrEmpty(obj.Tel) ? "" : ",电话=" + obj.Tel;
                    string email    = string.IsNullOrEmpty(obj.Email) ? "" : ",邮箱=" + obj.Email;
                    string address  = string.IsNullOrEmpty(obj.Address) ? "" : ",地址=" + obj.Address;
                    msg += "<br />Id=" + obj.Id + ",";
                    msg += "<br />分类=" + GetTitle(classify, obj.ClassifyId) + designee + ",简称=" + obj.Title + ",全称=" + obj.FullTitle + ",联系人=" + obj.Linkman + phoneNum + telNum + email + address + ",账号=" + obj.MasterAccount + ",状态=" + stateTitle + "。";
                }
                else
                {
                    msg = "新增供应商失败!";
                }
                log.WriteInsert(msg, module);
                #endregion
            }
            else
            {
                var supp = SupplierService.FindById(obj.Id);
                var exc  = new List <string>();
                if (obj.MasterPwd.IsNullOrEmpty())
                {
                    exc.Add("MasterPwd");
                }
                exc.Add("CompanyId");
                var  isUpdateClassify = obj.ClassifyId != supp.ClassifyId;
                var  isUpdateDesignee = obj.Designee != supp.Designee;
                var  isUpdateLinkman  = obj.Linkman != supp.Linkman;
                var  isUpdatePhone    = obj.MobilePhone != supp.MobilePhone;
                var  isUpdateTel      = obj.Tel != supp.Tel;
                var  isUpdateEmail    = obj.Email != supp.Email;
                var  isUpdateAddress  = obj.Address != supp.Address;
                var  isUpdateState    = obj.MasterState != supp.MasterState;
                var  isUpdatePwd      = string.IsNullOrEmpty(obj.MasterPwd) ? false : (obj.MasterPwd != supp.MasterPwd);
                bool isUpdate         = isUpdateClassify || isUpdateDesignee || isUpdateLinkman || isUpdatePhone || isUpdateTel || isUpdateEmail || isUpdateAddress || isUpdatePwd || isUpdateState;

                obj.ToCopyProperty(supp, exc);
                re = SupplierService.Update(supp);
                #region 写入日志
                string msg    = "成功修改供应商!";
                var    module = Pharos.Sys.LogModule.档案管理;
                if (re.Successed)
                {
                    int n = 0;
                    if (isUpdate)
                    {
                        msg += "<br />Id=" + obj.Id + ",<br />";
                        if (isUpdateClassify)
                        {
                            var classifyTitle = GetTitle(classify, obj.ClassifyId);
                            msg += "分类=" + classifyTitle;
                            n    = n + 1;
                        }
                        if (isUpdateDesignee)
                        {
                            msg += n > 0 ? ",指派人=" + desig : "指派人=" + desig;
                            n    = n + 1;
                        }
                        if (isUpdateLinkman)
                        {
                            msg += n > 0 ? ",联系人=" + obj.Linkman : "联系人=" + obj.Linkman;
                            n    = n + 1;
                        }
                        if (isUpdatePhone)
                        {
                            msg += n > 0 ? ",手机=" + obj.MobilePhone : "手机=" + obj.MobilePhone;
                            n    = n + 1;
                        }
                        if (isUpdateTel)
                        {
                            msg += n > 0 ? ",电话=" + obj.Tel : "电话=" + obj.Tel;
                            n    = n + 1;
                        }
                        if (isUpdateEmail)
                        {
                            msg += n > 0 ? ",邮箱=" + obj.Email : "邮箱=" + obj.Email;
                            n    = n + 1;
                        }
                        if (isUpdateAddress)
                        {
                            msg += n > 0 ? ",地址=" + obj.Address : "地址=" + obj.Address;
                            n    = n + 1;
                        }
                        if (isUpdateState)
                        {
                            msg += n > 0 ? ",状态=" + stateTitle : "状态=" + stateTitle;
                            n    = n + 1;
                        }
                        if (isUpdatePwd)
                        {
                            msg += n > 0 ? ",并修改了密码" : "修改了密码";
                        }
                        msg += "。";
                        log.WriteUpdate(msg, module);
                    }
                }
                else
                {
                    msg = "修改供应商失败!";
                    log.WriteUpdate(msg, module);
                }
                #endregion
            }
            return(re);
        }
示例#11
0
        public static OpResult Import(ImportSet obj, System.Web.HttpFileCollectionBase httpFiles, string fieldName, string columnName, short businessType)
        {
            var op    = new OpResult();
            var errLs = new List <string>();
            int count = 0;

            try
            {
                Dictionary <string, char> fieldCols = null;
                DataTable dt = null;
                op = ImportSetService.ImportSet(obj, httpFiles, fieldName, columnName, ref fieldCols, ref dt);
                if (!op.Successed)
                {
                    return(op);
                }
                var supplierClass = SysDataDictService.FindList(o => o.DicPSN == (int)DicType.供应商分类);
                var otherClass    = supplierClass.FirstOrDefault(o => o.Title.StartsWith("其"));
                var suppliers     = GetList();
                var users         = UserInfoService.GetList();
                var max           = SysDataDictService.GetMaxSN;
                var clsIdx        = Convert.ToInt32(fieldCols["ClassifyId"]) - 65;
                var titleIdx      = Convert.ToInt32(fieldCols["Title"]) - 65;
                var fulltitleIdx  = Convert.ToInt32(fieldCols["FullTitle"]) - 65;
                var linkmanIdx    = Convert.ToInt32(fieldCols["Linkman"]) - 65;
                var designeeIdx   = Convert.ToInt32(fieldCols["Designee"]) - 65;
                count = dt.Rows.Count;
                for (int i = dt.Rows.Count - 1; i >= 0; i--)
                {
                    try
                    {
                        var dr   = dt.Rows[i];
                        var text = dr[clsIdx].ToString();
                        if (text.IsNullOrEmpty())
                        {
                            errLs.Add("行号[" + i + "]供应商分类为空!");
                            dt.Rows.RemoveAt(i);//去除不导入
                            continue;
                        }
                        var cls = supplierClass.FirstOrDefault(o => o.Title == text);
                        if (cls != null)
                        {
                            dr[clsIdx] = cls.DicSN.ToString();
                        }
                        else
                        {
                            if (obj.RefCreate)
                            {
                                var data = new Sys.Entity.SysDataDictionary()
                                {
                                    DicPSN    = (int)DicType.供应商分类,
                                    DicSN     = max++,
                                    Status    = true,
                                    Title     = text,
                                    CompanyId = CommonService.CompanyId
                                };
                                SysDataDictService.Add(data);
                                supplierClass.Add(data);
                                dr[clsIdx] = data.DicSN.ToString();
                            }
                            else if (otherClass != null)
                            {
                                dr[clsIdx] = otherClass.DicSN.ToString();
                            }
                            else
                            {
                                errLs.Add("供应商分类[" + text + "]不存在!");
                                dt.Rows.RemoveAt(i);//去除不导入
                                continue;
                            }
                        }
                        text = dr[designeeIdx].ToString();
                        var user = users.FirstOrDefault(o => o.FullName == text);
                        if (user != null)
                        {
                            dr[designeeIdx] = user.UID;
                        }
                        else
                        {
                            errLs.Add("指派人[" + text + "]不存在!");
                            dt.Rows.RemoveAt(i);
                            continue;
                        }
                        text = dr[titleIdx].ToString().Trim();
                        var fulltext = dr[fulltitleIdx].ToString().Trim();
                        var linkman  = dr[linkmanIdx].ToString().Trim();
                        if (text.IsNullOrEmpty())
                        {
                            errLs.Add("行号[" + text + "]简称为空!");
                            dt.Rows.RemoveAt(i);
                        }
                        else if (fulltext.IsNullOrEmpty())
                        {
                            errLs.Add("简称[" + text + "]全称为空!");
                            dt.Rows.RemoveAt(i);
                        }
                        else if (linkman.IsNullOrEmpty())
                        {
                            errLs.Add("简称[" + text + "]联系人为空!");
                            dt.Rows.RemoveAt(i);
                        }
                        else if (suppliers.Any(o => o.Title == text))
                        {
                            errLs.Add("简称[" + text + "]已存在!");
                            dt.Rows.RemoveAt(i);
                        }
                        else if (suppliers.Any(o => o.FullTitle == fulltext))
                        {
                            errLs.Add("全称[" + fulltext + "]已存在!");
                            dt.Rows.RemoveAt(i);
                        }
                        else
                        {
                            suppliers.Add(new Supplier()
                            {
                                Title     = text,
                                FullTitle = fulltext
                            });
                        }
                    }
                    catch (Exception e)
                    {
                        throw new Exception("供应商分类处理失败!", e);
                    }
                }
                StringBuilder sb = new StringBuilder();
                sb.Append("begin tran ");
                foreach (DataRow dr in dt.Rows)
                {
                    sb.Append("insert into Supplier");
                    sb.Append("(CompanyId,BusinessType,Id,");
                    sb.Append(string.Join(",", fieldCols.Keys));
                    sb.Append(") values(");
                    sb.AppendFormat("{0},", obj.CompanyId);
                    sb.AppendFormat(businessType + ",");
                    sb.AppendFormat("'{0}',", CommonRules.GUID);
                    foreach (var de in fieldCols)
                    {
                        var index = Convert.ToInt32(de.Value) - 65;
                        try
                        {
                            var text = dr[index].ToString();
                            sb.Append("'" + text + "',");
                        }
                        catch (Exception e)
                        {
                            throw new Exception("列选择超过范围!", e);
                        }
                    }
                    sb = sb.Remove(sb.Length - 1, 1);
                    sb.Append(");");
                }
                sb.Append(" commit tran");
                op.Successed = new Pharos.Logic.DAL.CommonDAL()._db.ExecuteNonQueryText(sb.ToString(), null) > 0;
                log.WriteInsert(obj.TableName == "Supplier" ? "供应商导入" : "批发商导入", Pharos.Sys.LogModule.档案管理);
            }
            catch (Exception ex)
            {
                op.Message   = ex.Message;
                op.Successed = false;
                Log.WriteError(ex);
                errLs.Add("导入出现异常!");
            }
            return(CommonService.GenerateImportHtml(errLs, count));
        }