Esempio n. 1
0
        public void EditTaskPOP_SearchConditions(Guid taskid, List <DefindControlEntity> pSearch, string conditions, int isAutoFill)
        {
            VisitingTaskEntity taskEntity = new VisitingTaskBLL(CurrentUserInfo).GetByID(taskid);

            IDbTransaction tran = new TransactionHelper(this.CurrentUserInfo).CreateTransaction();

            using (tran.Connection)
            {
                try
                {
                    POPGroupEntity entity = new POPGroupBLL(CurrentUserInfo).GetPOPGroupByTaskID(taskid);
                    if (entity != null)
                    {//修改
                        entity.SqlTemplate    = GetPOPSqlTemplate(pSearch, taskEntity.POPType.Value, taskid);
                        entity.GroupCondition = conditions;
                        entity.IsAutoFill     = isAutoFill;
                        entity.POPType        = taskEntity.POPType;
                        new POPGroupBLL(CurrentUserInfo).Update(entity, tran);
                    }
                    else
                    {//新增
                        entity                = new POPGroupEntity();
                        entity.SqlTemplate    = GetPOPSqlTemplate(pSearch, taskEntity.POPType.Value, taskid);
                        entity.GroupCondition = conditions;
                        entity.IsAutoFill     = isAutoFill;
                        entity.POPType        = taskEntity.POPType;

                        entity.ClientID            = CurrentUserInfo.ClientID;
                        entity.ClientDistributorID = Convert.ToInt32(CurrentUserInfo.ClientDistributorID);
                        new POPGroupBLL(CurrentUserInfo).Create(entity, tran);
                    }

                    taskEntity.POPGroupID = entity.POPGroupID;
                    new VisitingTaskBLL(CurrentUserInfo).Update(taskEntity, tran);


                    tran.Commit();
                }
                catch
                {
                    tran.Rollback();
                    throw;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 拜访任务选择门店
        /// </summary>
        /// <param name="pSearch">查询条件</param>
        /// <param name="taskid">拜访任务ID</param>
        /// <param name="allSelectorStatus">选择状态</param>
        /// <param name="defaultList">默认list</param>
        /// <param name="includeList">选择list</param>
        /// <param name="excludeList">排除list</param>
        public void EditTaskPOP_Store(int isAutoFill, List <DefindControlEntity> pSearch, string conditions, Guid taskid, int allSelectorStatus, string defaultList, string includeList, string excludeList)
        {
            VisitingTaskEntity taskEntity = new VisitingTaskBLL(CurrentUserInfo).GetByID(taskid);

            List <VisitingPOPMappingViewEntity> oldList = DataLoader.LoadFrom <VisitingPOPMappingViewEntity>(this.GetTaskStoreList(pSearch, int.MaxValue, 0, taskid.ToString()).GridData).ToList();

            IDbTransaction tran = new TransactionHelper(this.CurrentUserInfo).CreateTransaction();

            using (tran.Connection)
            {
                try
                {
                    #region 条件信息设置
                    bool           changeCondition = false;//如果设置条件修改了,那么清空POP表数据
                    POPGroupEntity entity          = new POPGroupBLL(CurrentUserInfo).GetPOPGroupByTaskID(taskid);
                    if (entity != null)
                    {//修改
                        if (entity.GroupCondition != conditions)
                        {
                            changeCondition = true;
                        }
                        entity.SqlTemplate    = new VisitingTaskBLL(CurrentUserInfo).GetPOPSqlTemplate(pSearch, taskEntity.POPType.Value, taskid);
                        entity.GroupCondition = conditions;
                        entity.IsAutoFill     = isAutoFill;
                        entity.POPType        = taskEntity.POPType;
                        new POPGroupBLL(CurrentUserInfo).Update(entity, tran);
                    }
                    else
                    {//新增
                        changeCondition       = true;
                        entity                = new POPGroupEntity();
                        entity.SqlTemplate    = new VisitingTaskBLL(CurrentUserInfo).GetPOPSqlTemplate(pSearch, taskEntity.POPType.Value, taskid);
                        entity.GroupCondition = conditions;
                        entity.IsAutoFill     = isAutoFill;
                        entity.POPType        = taskEntity.POPType;

                        entity.ClientID            = CurrentUserInfo.ClientID;
                        entity.ClientDistributorID = Convert.ToInt32(CurrentUserInfo.ClientDistributorID);
                        new POPGroupBLL(CurrentUserInfo).Create(entity, tran);
                    }

                    taskEntity.POPGroupID = entity.POPGroupID;
                    new VisitingTaskBLL(CurrentUserInfo).Update(taskEntity, tran);
                    #endregion

                    #region 添加终端信息
                    if (isAutoFill == 1)
                    {
                        #region 添加目前符合条件所有终端
                        //删除
                        if (changeCondition)
                        {
                            //删除所有,新增所有
                            this._currentDAO.DeleteVisitingPOPAll(taskid, tran);

                            this._currentDAO.CreatePOP_StoreList(
                                taskid,
                                oldList
                                .Select(m => m.StoreID.ToString()).ToArray().ToJoinString("','"),
                                tran);
                        }
                        else
                        {
                            //新增数据库没有的
                            this._currentDAO.CreatePOP_StoreList(
                                taskid,
                                oldList
                                .Where(m => !m.MappingID.HasValue).ToArray()
                                .Select(m => m.StoreID.ToString()).ToArray().ToJoinString("','"),
                                tran);
                        }
                        #endregion
                    }
                    else
                    {
                        #region 点选终端
                        //查询出数据库中已选择的产品
                        IEnumerable <string> selectedIDS = oldList.Where(x => x.MappingID != null).Select(x => x.StoreID.ToString());
                        //删除ID集合
                        IEnumerable <string> deletedList = null;
                        //新增ID集合
                        IEnumerable <string> createList = null;
                        //全选默认状态(没有点全选checkbox)
                        if (allSelectorStatus == 0)
                        {
                            //前端选择的产品ID数组
                            string[] frontSelectedIDS = includeList.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                            deletedList = selectedIDS.Except(frontSelectedIDS);
                            createList  = frontSelectedIDS.Except(selectedIDS);
                        }

                        //点了全选
                        else if (allSelectorStatus == 1)
                        {
                            //排除的ID数组
                            string[] excludeIDS = excludeList.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            //取交集,得出需要删除ID集合
                            deletedList = selectedIDS.Intersect(excludeIDS);
                            //取差集,得出需要新增ID集合
                            createList = oldList.Where(x => x.MappingID == null).Select(x => x.StoreID.ToString()).Except(excludeIDS);
                        }

                        //取消了全选
                        else if (allSelectorStatus == 2)
                        {
                            //选择的ID数组
                            string[] includeIDS = includeList.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            //取差集,得出需要新增的ID集合
                            createList = includeIDS.Except(selectedIDS);
                            //取差集,得出需要删除的ID集合
                            deletedList = oldList.Where(x => x.MappingID != null).Select(x => x.StoreID.ToString()).Except(includeIDS);
                        }

                        #region  除新增操作
                        //删除操作
                        if (deletedList != null && deletedList.Count() > 0)
                        {
                            this._currentDAO.DeleteVisitingPOPIn(taskid, string.Join("','", deletedList), tran);
                        }

                        //新增操作
                        if (createList != null && createList.Count() > 0)
                        {
                            this._currentDAO.CreatePOP_StoreList(taskid, string.Join("','", createList), tran);
                        }
                        #endregion

                        #endregion
                    }
                    #endregion

                    tran.Commit();
                }
                catch
                {
                    tran.Rollback();
                    throw;
                }
            }
        }