예제 #1
0
        /// <summary>
        /// 修改公司信息数据
        /// </summary>
        public AjaxResult Update(TbCompany cyp, bool isApi = false)
        {
            if (cyp == null)
            {
                return(AjaxResult.Warning("参数错误"));
            }

            try
            {
                //var model = MapperHelper.Map<TbCompany, TbCompany>(cyp);
                //var count = Repository<TbCompany>.Update(model,isApi);
                //if (count <= 0)
                //{
                //    return AjaxResult.Error();
                //}
                Repository <TbCompany> .Update(cyp, d => d.CompanyCode == cyp.CompanyCode, isApi);

                return(AjaxResult.Success());
            }
            catch (Exception e)
            {
                var err = e.ToString();
                return(AjaxResult.Error(err));
            }
        }
예제 #2
0
        /// <summary>
        /// 新增公司信息数据
        /// </summary>
        public AjaxResult Insert(TbCompany cpy, bool isApi = false)
        {
            if (cpy == null)
            {
                return(AjaxResult.Warning("参数错误"));
            }
            if (cpy.ParentCompanyCode == "0")
            {
                var num = JudgeExist();
                if (num > 0)
                {
                    return(AjaxResult.Warning("父级(顶级)公司只能存在一个!"));
                }
            }
            try
            {
                //var model = MapperHelper.Map<TbCompany, TbCompany>(cpy);
                //var count = Repository<TbCompany>.Insert(model,isApi);
                //if (count <= 0)
                //    return AjaxResult.Error();
                Repository <TbCompany> .Insert(cpy, isApi);

                return(AjaxResult.Success());
            }
            catch (Exception e)
            {
                var err = e.ToString();
                return(AjaxResult.Error(err));
            }
        }
예제 #3
0
        public List <TbCompany> GetAllCompanyOrBySearchNew()
        {
            string           ProjectId = OperatorProvider.Provider.CurrentUser.ProjectId;
            var              listAll   = new List <TbCompany>();
            List <TbCompany> list2     = new List <TbCompany>();
            string           sql1      = @"select pc.ProjectId,pj.ProjectName from TbProjectCompany pc
left join TbProjectInfo pj on pc.ProjectId=pj.ProjectId where pc.OrgType=2 and pc.ProjectId='" + ProjectId + "'";
            DataTable        dt1       = Db.Context.FromSql(sql1).ToDataTable();

            if (dt1 != null)
            {
                for (int i = 0; i < dt1.Rows.Count; i++)
                {
                    TbCompany cm = new TbCompany();
                    cm.CompanyCode       = dt1.Rows[i]["ProjectId"].ToString();
                    cm.ParentCompanyCode = "0";
                    cm.CompanyFullName   = dt1.Rows[i]["ProjectName"].ToString();
                    cm.OrgType           = -1;
                    list2.Add(cm);
                }
                listAll.AddRange(list2);
            }
            string           sql   = @"select cp.id,cp.CompanyCode,cp.CompanyFullName,cp.ParentCompanyCode,cp.OrgType from TbCompany cp
left join TbProjectCompany pcp on cp.CompanyCode=pcp.CompanyCode where pcp.ProjectId='" + ProjectId + "' order by id asc";
            List <TbCompany> list1 = Db.Context.FromSql(sql).ToList <TbCompany>();
            List <TbCompany> list3 = list1.Where(s => s.OrgType != 2).ToList();

            listAll.AddRange(list3);
            List <TbCompany> list4 = list1.Where(s => s.OrgType == 2).ToList();

            if (list4.Count > 0)
            {
                for (int i = 0; i < list4.Count; i++)
                {
                    switch (list4[i].CompanyCode)//用户输入的值,和下面的case匹配
                    {
                    case "6247574415609954304":
                        list4[i].ParentCompanyCode = "6245721945602523136";
                        break;

                    case "6247574415609954305":
                        list4[i].ParentCompanyCode = "6245721945602523137";
                        break;

                    case "6247574415609954309":
                        list4[i].ParentCompanyCode = "6245721945602523139";
                        break;

                    case "6247574415609954306":
                        list4[i].ParentCompanyCode = "6422195692059623424";
                        break;

                    default:     //如果匹配全不成功则执行下面的代码
                        break;
                    }
                }
                listAll.AddRange(list4);
            }
            return(listAll);
        }
예제 #4
0
        public int VerificationMethod(TbCompany company, string type)
        {
            if (type == "add")
            {
                var list = Db.Context.From <TbCompany>().Where(d => d.CompanyFullName == company.CompanyFullName && d.CompanyCode == company.CompanyCode).ToList().Count;
                return(list);
            }
            else
            {
                //新建查询where
                var where = new Where <TbCompany>();
                where.And(t => t.CompanyFullName == company.CompanyFullName);
                where.And(t => t.CompanyCode != company.CompanyCode);
                where.And(t => t.id != company.id);
                //根据条件查询部分数据
                var list = Repository <TbCompany> .Query(where, d => d.id).ToList().Count;

                return(list);
            }
        }
예제 #5
0
 /// <summary>
 /// 新增公司信息 Or 修改公司信息
 /// </summary>
 /// <param name="company"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public ActionResult SubmitForm(TbCompany company, string type)
 {
     if (type == "add")
     {
         var OnlyVerification = cit.VerificationMethod(company, "add");
         if (OnlyVerification > 0)
         {
             return(Error("公司名称重复!"));
         }
         var data = cit.Insert(company);
         return(Content(data.ToJson()));
     }
     else
     {
         var OnlyVerification = cit.VerificationMethod(company, "edit");
         if (OnlyVerification > 0)
         {
             return(Error("公司名称重复!"));
         }
         var data = cit.Update(company);
         return(Content(data.ToJson()));
     }
 }
예제 #6
0
        /// <summary>
        /// 查询公司(全部查询 or 条件查询)
        /// </summary>
        /// <param name="pr"></param>
        /// <param name="keyword"></param>
        /// <returns></returns>
        //public List<TbCompany> GetAllCompanyOrBySearch(PageSearchRequest pt, string keyword)
        public List <TbCompany> GetAllCompanyOrBySearch(string keyword)
        {
            var listAll = new List <TbCompany>();

            //新建查询where
            var where = new Where <TbCompany>();
            //判断条件查询是否为空,不为空,条件添加进行查询
            if (!string.IsNullOrEmpty(keyword))
            {
                where.And(t => t.CompanyFullName.Like(keyword));
            }
            //where.And(t => t.OrgType != 1);

            List <TbCompany> list1 = Repository <TbCompany> .Query(where, d => d.id, "asc").ToList(); //获取所有的组织机构

            List <TbCompany> list3 = list1.Where(s => s.OrgType != 2 && s.OrgType != 1).ToList();     //获取除经理部跟加工厂外的组织机构

            listAll.AddRange(list3);
            List <TbCompany> list2 = new List <TbCompany>(); //获取所有项目
            string           sql1  = @"select pc.ProjectId,pj.ProjectName from TbProjectCompany pc
left join TbProjectInfo pj on pc.ProjectId=pj.ProjectId where pc.OrgType=2";
            DataTable        dt1   = Db.Context.FromSql(sql1).ToDataTable();

            if (dt1 != null)
            {
                for (int i = 0; i < dt1.Rows.Count; i++)
                {
                    TbCompany cm = new TbCompany();
                    cm.CompanyCode       = dt1.Rows[i]["ProjectId"].ToString();
                    cm.ParentCompanyCode = "0";
                    cm.ParentCompanyName = "";
                    cm.CompanyFullName   = dt1.Rows[i]["ProjectName"].ToString();
                    cm.Address           = "";
                    cm.OrgType           = -1;
                    list2.Add(cm);
                }
                listAll.AddRange(list2);
            }
            List <TbCompany> list4 = list1.Where(s => s.OrgType == 2).ToList(); //给所有经理部添加上级编号
            List <TbCompany> list5 = list1.Where(s => s.OrgType == 1).ToList(); //给所有加工厂同时把加工厂添加的对应项目中
            List <TbCompany> list6 = new List <TbCompany>();                    //给所有加工厂同时把加工厂添加的对应项目中

            if (list4.Count > 0)
            {
                for (int i = 0; i < list4.Count; i++)
                {
                    switch (list4[i].CompanyCode)//用户输入的值,和下面的case匹配
                    {
                    case "6247574415609954304":
                        list4[i].ParentCompanyCode = "6245721945602523136";
                        for (int j = 0; j < list5.Count; j++)
                        {
                            TbCompany cm = new TbCompany();
                            cm.CompanyCode       = list5[j].CompanyCode + "_" + list4[i].CompanyCode;
                            cm.ParentCompanyCode = list4[i].CompanyCode;
                            cm.ParentCompanyName = "";
                            cm.CompanyFullName   = list5[j].CompanyFullName;
                            cm.Address           = "";
                            cm.OrgType           = 1;
                            list6.Add(cm);
                        }
                        break;

                    case "6247574415609954305":
                        list4[i].ParentCompanyCode = "6245721945602523137";
                        for (int j = 0; j < list5.Count; j++)
                        {
                            TbCompany cm = new TbCompany();
                            cm.CompanyCode       = list5[j].CompanyCode + "_" + list4[i].CompanyCode;
                            cm.ParentCompanyCode = list4[i].CompanyCode;
                            cm.ParentCompanyName = "";
                            cm.CompanyFullName   = list5[j].CompanyFullName;
                            cm.Address           = "";
                            cm.OrgType           = 1;
                            list6.Add(cm);
                        }
                        break;

                    case "6247574415609954309":
                        list4[i].ParentCompanyCode = "6245721945602523139";
                        for (int j = 0; j < list5.Count; j++)
                        {
                            TbCompany cm = new TbCompany();
                            cm.CompanyCode       = list5[j].CompanyCode + "_" + list4[i].CompanyCode;
                            cm.ParentCompanyCode = list4[i].CompanyCode;
                            cm.ParentCompanyName = "";
                            cm.CompanyFullName   = list5[j].CompanyFullName;
                            cm.Address           = "";
                            cm.OrgType           = 1;
                            list6.Add(cm);
                        }
                        break;

                    case "6247574415609954306":
                        list4[i].ParentCompanyCode = "6422195692059623424";
                        for (int j = 0; j < list5.Count; j++)
                        {
                            TbCompany cm = new TbCompany();
                            cm.CompanyCode       = list5[j].CompanyCode + "_" + list4[i].CompanyCode;
                            cm.ParentCompanyCode = list4[i].CompanyCode;
                            cm.ParentCompanyName = "";
                            cm.CompanyFullName   = list5[j].CompanyFullName;
                            cm.Address           = "";
                            cm.OrgType           = 1;
                            list6.Add(cm);
                        }
                        break;

                    default:     //如果匹配全不成功则执行下面的代码
                        break;
                    }
                }

                listAll.AddRange(list6);
                listAll.AddRange(list4);
            }
            return(listAll);
        }