public List <Guid> SaveCompareExceptionList(string IDlist, string SelectType, string TargetID)
        {
            List <Guid> result = new List <Guid>();

            string[] arr = IDlist.Split('|');
            if (SelectType == "B")//从可比变为不可比   在异常表中添加
            {
                for (int i = 0; i < arr.Length; i++)
                {
                    C_ExceptionTarget model = new C_ExceptionTarget();
                    model.CompanyID     = Guid.Parse(arr[i]);
                    model.TargetID      = Guid.Parse(TargetID);
                    model.ExceptionType = EnumHelper.GetEnumValue(typeof(ExceptionTargetType), "全年不可比门店");
                    Guid ID = C_ExceptiontargetOperator.Instance.AddExceptiontarget(model);
                    result.Add(ID);
                }
            }
            else//从不可比变为可比  在异常表中删除
            {
                for (int i = 0; i < arr.Length; i++)
                {
                    Guid ID = C_ExceptiontargetOperator.Instance.RemoveExceptiontarget(Guid.Parse(arr[i]));
                    result.Add(ID);
                }
            }
            return(result);
        }
        public Guid SaveCompareException(string SelectType, string ID, string TargetID)
        {
            Guid result;

            if (SelectType == "A")//本身为不可比 变为可比,从异常表中删除即可
            {
                result = C_ExceptiontargetOperator.Instance.RemoveExceptiontarget(Guid.Parse(ID));
            }
            else//本身为可比,变为不可比,在异常表中添加
            {
                C_ExceptionTarget Model = new C_ExceptionTarget();
                Model.CompanyID     = Guid.Parse(ID);
                Model.TargetID      = Guid.Parse(TargetID);
                Model.ExceptionType = EnumHelper.GetEnumValue(typeof(ExceptionTargetType), "全年不可比门店");
                result = C_ExceptiontargetOperator.Instance.AddExceptiontarget(Model);
            }
            return(result);
        }
        public Guid ChangeExceptionTarget(string OldType, string NewType, string ID, string TargetID)
        {
            Guid result;

            if (OldType == "3")//当OldType=3时,证明该数据在异常表里不存在,是从普通公司表插入异常表,其ID为公司ID
            {
                C_ExceptionTarget Model = new C_ExceptionTarget();
                Model.CompanyID     = Guid.Parse(ID);
                Model.TargetID      = Guid.Parse(TargetID);
                Model.ExceptionType = int.Parse(NewType);
                result = C_ExceptiontargetOperator.Instance.AddExceptiontarget(Model);
            }
            else
            {
                if (NewType == "3")//当NewType=3时,则该数据在需要在异常表里删除
                {
                    //result = C_ExceptiontargetOperator.Instance.RemoveExceptiontarget(Guid.Parse(ID));
                    C_ExceptionTarget model = C_ExceptiontargetOperator.Instance.GetExceptiontarget(Guid.Parse(ID));
                    result = C_ExceptiontargetOperator.Instance.RemoveExceptiontarget(Guid.Parse(ID));

                    //C_Company Commodel = C_CompanyOperator.Instance.GetCompany(model.CompanyID);
                    //C_CompanyOperator.Instance.RemoveCompany(model.CompanyID);
                    //C_Company NewModel = Commodel;
                    //NewModel.VersionStart = DateTime.Now;
                    //NewModel.VersionEnd = Commodel.VersionStart;
                    //C_CompanyOperator.Instance.AddCompany(NewModel);
                }
                else
                {
                    C_ExceptionTarget model = C_ExceptiontargetOperator.Instance.GetExceptiontarget(Guid.Parse(ID));
                    model.ExceptionType = int.Parse(NewType);
                    result = C_ExceptiontargetOperator.Instance.UpdateExceptiontarget(model);
                }
            }
            return(result);
        }
        public List <Guid> SaveExceptionReplace(string IDlist, string Type, string SelectType, string TargetID)
        {
            List <Guid> result = new List <Guid>();

            string[] arr = IDlist.Split('|');
            if (Type == "C")           //数据本身是不存在于异常表中
            {
                if (SelectType == "A") //在异常表中添加数据,类型给1
                {
                    for (int i = 0; i < arr.Length; i++)
                    {
                        C_Company         Company = C_CompanyOperator.Instance.GetCompany(Guid.Parse(arr[i]));
                        C_ExceptionTarget model   = new C_ExceptionTarget();
                        model.CompanyID     = Company.ID;
                        model.TargetID      = Guid.Parse(TargetID);
                        model.ExceptionType = (int)ExceptionTargetType.HaveDeTailNONeedEvaluation;
                        Guid ID = C_ExceptiontargetOperator.Instance.AddExceptiontarget(model);
                        result.Add(ID);
                    }
                }
                else
                {
                    for (int i = 0; i < arr.Length; i++)
                    {
                        C_Company         Company = C_CompanyOperator.Instance.GetCompany(Guid.Parse(arr[i]));
                        C_ExceptionTarget model   = new C_ExceptionTarget();
                        model.CompanyID     = Company.ID;
                        model.TargetID      = Guid.Parse(TargetID);
                        model.ExceptionType = (int)ExceptionTargetType.HaveDetailNONeedReport;
                        Guid ID = C_ExceptiontargetOperator.Instance.AddExceptiontarget(model);
                        result.Add(ID);
                    }
                }
            }
            else//数据本身存在于异常表中
            {
                if (SelectType == "C")//用户选择了上报审批,即从异常表中删除
                {
                    for (int i = 0; i < arr.Length; i++)
                    {
                        //取到异常数据
                        //C_ExceptionTarget model = C_ExceptiontargetOperator.Instance.GetExceptiontarget(Guid.Parse(arr[i]));
                        //取到该公司数据  加版本暂时不用
                        //C_Company Commodel = C_CompanyOperator.Instance.GetCompany(model.CompanyID);
                        //C_CompanyOperator.Instance.RemoveCompany(model.CompanyID);
                        //C_Company NewModel = Commodel;
                        //NewModel.VersionStart = DateTime.Now;
                        //NewModel.VersionEnd = Commodel.VersionStart;
                        //C_CompanyOperator.Instance.AddCompany(NewModel);
                        Guid ID = C_ExceptiontargetOperator.Instance.RemoveExceptiontarget(Guid.Parse(arr[i]));
                        result.Add(ID);
                    }
                }
                else
                {
                    if (SelectType == "B")
                    {
                        for (int i = 0; i < arr.Length; i++)
                        {
                            C_ExceptionTarget model = C_ExceptiontargetOperator.Instance.GetExceptiontarget(Guid.Parse(arr[i]));
                            model.ExceptionType = EnumHelper.GetEnumValue(typeof(ExceptionTargetType), "不上报不考核");
                            Guid ID = C_ExceptiontargetOperator.Instance.UpdateExceptiontarget(model);
                            result.Add(ID);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < arr.Length; i++)
                        {
                            C_ExceptionTarget model = C_ExceptiontargetOperator.Instance.GetExceptiontarget(Guid.Parse(arr[i]));
                            model.ExceptionType = EnumHelper.GetEnumValue(typeof(ExceptionTargetType), "上报不考核");
                            Guid ID = C_ExceptiontargetOperator.Instance.UpdateExceptiontarget(model);
                            result.Add(ID);
                        }
                    }
                }
            }
            return(result);
        }
        public int UpdateCompany(string info, string TargetIDList, string SelTargetIDList)
        {
            int result = 0;

            C_Company detail = JsonHelper.Deserialize <C_Company>(info);
            //取出该公司异常type=1的指标名称
            List <ExceptionTargetVModel> list = C_ExceptiontargetOperator.Instance.GetExctargetListByComList(detail.ID).ToList();

            C_CompanyOperator.Instance.UpdateCompany(detail);



            if (TargetIDList != null)
            {
                //取出页面传来的所有没有勾中的指标
                string[] arr = TargetIDList.Split('|');

                //获取页面选中的指标
                string[] selArr = SelTargetIDList.Split('|');


                //位选中的值中循环
                for (int i = 0; i < arr.Length; i++)
                {
                    //循环所有传过来的ID
                    int arrl = 0;
                    for (int j = 0; j < list.Count; j++)
                    {
                        if (arr[i] == list[j].TargetID.ToString())
                        {
                            arrl++;
                        }
                    }
                    if (arrl == 0)
                    {
                        //若arrl==0,说明该指标在原本的异常表里不存在,添加操作
                        C_ExceptionTarget model = new C_ExceptionTarget();
                        model.CompanyID     = detail.ID;
                        model.TargetID      = Guid.Parse(arr[i]);
                        model.ExceptionType = 2;
                        C_ExceptiontargetOperator.Instance.AddExceptiontarget(model);
                    }
                }

                //选中值里循环异常表的数据
                for (int i = 0; i < list.Count; i++)
                {
                    //int arrl = 0;
                    for (int j = 0; j < selArr.Length; j++)
                    {
                        if (list[i].TargetID.ToString() != selArr[j])
                        {
                            #region 对于存在异常指标里的数据

                            int flag = CompanyExceptionTargetEngine.CompanyExceptionTargetEngineService.GetCompanyExceptionTarget(detail);

                            if (flag == 1) //flag: 0 的时候表示正常的数据,不用像异常表里添加数据, 而 flag: 1的时候需要像异常表中添加数据
                            {
                                C_ExceptionTarget newModel = new C_ExceptionTarget();
                                newModel.CompanyID     = detail.ID;
                                newModel.TargetID      = Guid.Parse(selArr[j]);
                                newModel.ExceptionType = (int)ExceptionTargetType.HaveDeTailNONeedEvaluation;;
                                C_ExceptiontargetOperator.Instance.AddExceptiontarget(newModel);
                            }
                            else if (flag == 0)
                            {
                                List <C_ExceptionTarget> ExcList = C_ExceptiontargetOperator.Instance.GetExceptiontargetList(detail.ID, selArr[j].ToGuid()).ToList();

                                if (ExcList != null && ExcList.Count() > 0)
                                {
                                    ExcList.ForEach(p =>
                                    {
                                        p.IsDeleted = true;
                                        C_ExceptiontargetOperator.Instance.UpdateExceptiontarget(p);
                                    });
                                }
                            }

                            #endregion
                        }
                    }
                }
            }
            else
            {
                //若TargetIDList为空 说明页面全部勾中

                //获取页面选中的指标
                string[] selArr = SelTargetIDList.Split('|');

                for (int j = 0; j < selArr.Length; j++)
                {
                    #region 对于存在异常指标里的数据

                    int flag = CompanyExceptionTargetEngine.CompanyExceptionTargetEngineService.GetCompanyExceptionTarget(detail);

                    if (flag == 1) //flag: 0 的时候表示正常的数据,不用像异常表里添加数据, 而 flag: 1的时候需要像异常表中添加数据
                    {
                        C_ExceptionTarget newModel = new C_ExceptionTarget();
                        newModel.CompanyID     = detail.ID;
                        newModel.TargetID      = Guid.Parse(selArr[j]);
                        newModel.ExceptionType = (int)ExceptionTargetType.HaveDeTailNONeedEvaluation;;
                        C_ExceptiontargetOperator.Instance.AddExceptiontarget(newModel);
                    }
                    else if (flag == 0)
                    {
                        List <C_ExceptionTarget> ExcList = C_ExceptiontargetOperator.Instance.GetExceptiontargetList(detail.ID, selArr[j].ToGuid()).ToList();

                        if (ExcList != null && ExcList.Count() > 0)
                        {
                            ExcList.ForEach(p =>
                            {
                                p.IsDeleted = true;
                                C_ExceptiontargetOperator.Instance.UpdateExceptiontarget(p);
                            });
                        }
                    }

                    #endregion
                }
            }

            return(result);
        }
        public int AddCompany(string info, string SysID, string SelTargetIDList)
        {
            int a = 0;

            string[] brr;
            C_System model = new C_System();

            model = StaticResource.Instance[Guid.Parse(SysID), DateTime.Now];
            List <string> TargetList = new List <string>();
            C_Company     detail     = new C_Company();

            string[] arr = info.Split('|');
            for (int i = 0; i < arr.Length; i++)
            {
                brr = arr[i].Split(':');
                #region//解析info
                if (brr[0] == "CompanyProperty1")
                {
                    detail.CompanyProperty1 = brr[1];
                }
                else if (brr[0] == "CompanyProperty2")
                {
                    detail.CompanyProperty2 = brr[1];
                }
                else if (brr[0] == "CompanyProperty3")
                {
                    detail.CompanyProperty3 = brr[1];
                }
                else if (brr[0] == "CompanyProperty4")
                {
                    detail.CompanyProperty4 = brr[1];
                }
                else if (brr[0] == "CompanyProperty5")
                {
                    detail.CompanyProperty5 = brr[1];
                }
                else if (brr[0] == "CompanyProperty6")
                {
                    detail.CompanyProperty6 = brr[1];
                }
                else if (brr[0] == "CompanyProperty7")
                {
                    detail.CompanyProperty7 = brr[1];
                }
                else if (brr[0] == "CompanyProperty8")
                {
                    detail.CompanyProperty8 = brr[1];
                }
                else if (brr[0] == "CompanyProperty9")
                {
                    detail.CompanyProperty9 = brr[1];
                }
                else if (brr[0] == "Sequence")
                {
                    detail.Sequence = int.Parse(brr[1]);
                }
                else if (brr[0] == "CompanyName")
                {
                    detail.CompanyName = brr[1];
                }
                else if (brr[0] == "SystemID")
                {
                    detail.SystemID = Guid.Parse(brr[1]);
                }
                else if (brr[0] == "OpeningTime")
                {
                    detail.OpeningTime = DateTime.Parse(brr[1]);
                }
                else if (brr[0] == "ExTargetList")
                {
                    if (brr[1] != "")
                    {
                        TargetList = new List <string>(brr[1].Split(','));
                    }
                }

                #endregion
            }

            Guid Id = C_CompanyOperator.Instance.AddCompany(detail);

            #region  对筹备门店和尾盘做处理操作

            if (SelTargetIDList != null)
            {
                string[] selArr = SelTargetIDList.Split('|'); //选中的指标

                for (int j = 0; j < selArr.Length; j++)
                {
                    int flag = CompanyExceptionTargetEngine.CompanyExceptionTargetEngineService.GetCompanyExceptionTarget(detail);

                    if (flag == 1) //flag: 0 的时候表示正常的数据,不用像异常表里添加数据, 而 flag: 1的时候需要像异常表中添加数据
                    {
                        C_ExceptionTarget newModel = new C_ExceptionTarget();
                        newModel.CompanyID     = Id;
                        newModel.TargetID      = Guid.Parse(selArr[j]);
                        newModel.ExceptionType = (int)ExceptionTargetType.HaveDeTailNONeedEvaluation;;
                        C_ExceptiontargetOperator.Instance.AddExceptiontarget(newModel);
                    }
                }
            }

            #endregion

            if (TargetList.Count > 0)
            {
                C_ExceptiontargetOperator.Instance.AddExceptiontargetList(TargetList, Id);
            }
            return(a);
        }