Exemplo n.º 1
0
        public JsonResult InsertDetail(string versionID, string targetID)
        {
            //首次
            if (string.IsNullOrEmpty(targetID))
            {
                if (entities.Set <S_C_BOQ_Version_Detail>().Any(a => a.VersionID == versionID))
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有指定插入位置的ID");
                }
                else
                {
                    S_C_BOQ_Version_Detail newDetail = new S_C_BOQ_Version_Detail();
                    newDetail.ID           = FormulaHelper.CreateGuid();
                    newDetail.BOQID        = newDetail.ID;
                    newDetail.Name         = "新增清单";
                    newDetail.VersionID    = versionID;
                    newDetail.Quantity     = 0;
                    newDetail.SortIndex    = 1;
                    newDetail.CreateDate   = DateTime.Now;
                    newDetail.CreateUser   = CurrentUserInfo.UserName;
                    newDetail.CreateUserID = CurrentUserInfo.UserID;
                    newDetail.ModifyState  = "Add";
                    entities.Set <S_C_BOQ_Version_Detail>().Add(newDetail);
                }
            }
            //插入
            else
            {
                var targetDetail = entities.Set <S_C_BOQ_Version_Detail>().SingleOrDefault(a => a.ID == targetID);
                if (targetDetail == null)
                {
                    throw new Formula.Exceptions.BusinessValidationException("未能找到指定的数据清单,无法再后面插入新行");
                }

                var targetDetailNext = entities.Set <S_C_BOQ_Version_Detail>()
                                       .Where(a => a.SortIndex > targetDetail.SortIndex && a.VersionID == targetDetail.VersionID).OrderBy(a => a.SortIndex).FirstOrDefault();

                double newDetailSortIndex = targetDetail.SortIndex + 1;
                if (targetDetailNext != null)
                {
                    newDetailSortIndex = (targetDetailNext.SortIndex + targetDetail.SortIndex) / 2;
                }
                S_C_BOQ_Version_Detail newDetail = new S_C_BOQ_Version_Detail();
                newDetail.ID           = FormulaHelper.CreateGuid();
                newDetail.BOQID        = newDetail.ID;
                newDetail.Name         = "新增清单";
                newDetail.VersionID    = targetDetail.VersionID;
                newDetail.Quantity     = 0;
                newDetail.SortIndex    = newDetailSortIndex;
                newDetail.CreateDate   = DateTime.Now;
                newDetail.CreateUser   = CurrentUserInfo.UserName;
                newDetail.CreateUserID = CurrentUserInfo.UserID;
                newDetail.ModifyState  = "Add";
                entities.Set <S_C_BOQ_Version_Detail>().Add(newDetail);
            }

            entities.SaveChanges();
            return(Json(""));
        }
Exemplo n.º 2
0
        public JsonResult MoveItem(string sourceID, string targetID, string dragAction)
        {
            var sourceNode = this.GetEntityByID <S_C_BOQ_Version_Detail>(sourceID);

            if (sourceNode == null)
            {
                throw new Formula.Exceptions.BusinessValidationException("没有找到指定内容,无法移动");
            }
            if (dragAction.ToLower() == "before")
            {
                var target = this.GetEntityByID <S_C_BOQ_Version_Detail>(targetID);
                if (target == null)
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有找到指定内容,无法移动");
                }

                S_C_BOQ_Version_Detail targetPre = entities.Set <S_C_BOQ_Version_Detail>()
                                                   .Where(a => a.ParentID == target.ParentID && a.SortIndex < target.SortIndex)
                                                   .OrderByDescending(a => a.SortIndex).FirstOrDefault();

                if (targetPre != null)
                {
                    sourceNode.SortIndex = (targetPre.SortIndex + target.SortIndex) / 2;
                }
                else
                {
                    sourceNode.SortIndex = target.SortIndex - 1;
                }
            }
            else if (dragAction.ToLower() == "after")
            {
                var target = this.GetEntityByID <S_C_BOQ_Version_Detail>(targetID);
                if (target == null)
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有找到指定内容,无法移动");
                }

                S_C_BOQ_Version_Detail targetNext = entities.Set <S_C_BOQ_Version_Detail>()
                                                    .Where(a => a.ParentID == target.ParentID && a.SortIndex > target.SortIndex)
                                                    .OrderBy(a => a.SortIndex).FirstOrDefault();

                if (targetNext != null)
                {
                    sourceNode.SortIndex = (targetNext.SortIndex + target.SortIndex) / 2;
                }
                else
                {
                    sourceNode.SortIndex = target.SortIndex + 1;
                }
            }
            this.entities.SaveChanges();
            return(Json(sourceNode));
        }
Exemplo n.º 3
0
        public JsonResult StandardImport(string listData)
        {
            var             vID     = GetQueryString("VersionID");
            S_C_BOQ_Version version = entities.Set <S_C_BOQ_Version>().Find(vID);

            if (version == null)
            {
                throw new Formula.Exceptions.BusinessValidationException("未找到ID为" + vID + "的S_C_BOQ_Version");
            }

            List <Dictionary <string, object> > dics = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(listData);

            var details  = this.entities.Set <S_C_BOQ_Version_Detail>().Where(a => a.VersionID == vID).ToList();
            var maxindex = details.Count() == 0 ? 0 : details.Max(a => a.SortIndex);

            foreach (var item in dics)
            {
                S_C_BOQ_Version_Detail detail = new S_C_BOQ_Version_Detail();
                detail.ID        = FormulaHelper.CreateGuid();
                detail.BOQID     = detail.ID;
                detail.VersionID = version.ID;

                string code = item.GetValue("Code");
                //if (entities.Set<S_C_BOQ_Version_Detail>()
                //    .Any(a => a.Code == code))
                //{
                //    throw new Formula.Exceptions.BusinessValidationException("编号【" + code + "】重复");
                //}

                detail.Code      = code;
                detail.Name      = item.GetValue("Name");
                detail.Property  = item.GetValue("Property");
                detail.Unit      = item.GetValue("Unit");
                detail.Quantity  = 0;
                detail.Price     = 0;
                detail.UnitPrice = 0;
                detail.Remark    = item.GetValue("Remark");

                detail.CreateDate   = DateTime.Now;
                detail.CreateUserID = CurrentUserInfo.UserID;
                detail.CreateUser   = CurrentUserInfo.UserName;
                detail.ModifyState  = "Add";
                detail.SortIndex    = maxindex + 0.001;
                maxindex            = detail.SortIndex;

                entities.Set <S_C_BOQ_Version_Detail>().Add(detail);
            }
            entities.SaveChanges();
            return(Json(""));
        }
Exemplo n.º 4
0
        public JsonResult ThisSaveList(string listData, string versionID)
        {
            var list = JsonHelper.ToList(listData);

            PriceValidate(list, versionID);

            foreach (var item in list)
            {
                string dataStateFromUICtrl = item.GetValue("_state").ToLower();
                var    data = this.GetEntityByID <S_C_BOQ_Version_Detail>(item.GetValue("ID"));

                if (dataStateFromUICtrl == "removed")
                {
                    if (data != null)
                    {
                        //删除的数据就是该未发布版(暂存)新增数据
                        //则直接删除数据库数据
                        if (data.ModifyState == "Add")
                        {
                            string id = item.GetValue("ID");
                            entities.Set <S_C_BOQ_Version_Detail>().Delete(a => a.ID == id);
                        }
                        else
                        {
                            string  id  = item.GetValue("BOQID");
                            S_C_BOQ boq = entities.Set <S_C_BOQ>().SingleOrDefault(a => a.ID == id);
                            if (boq != null && boq.Locked)
                            {
                                throw new Formula.Exceptions.BusinessValidationException("【" + item.GetValue("Name") + "】清单已被锁定(应用于计量单中)不能删除");
                            }
                            data.ModifyState = "Remove";
                        }
                    }
                }
                else if (dataStateFromUICtrl == "modified")
                {
                    if (data != null)
                    {
                        string  id  = item.GetValue("BOQID");
                        S_C_BOQ boq = entities.Set <S_C_BOQ>().SingleOrDefault(a => a.ID == id);
                        if (boq != null && boq.Locked)
                        {
                            decimal tmp = 0;
                            if (decimal.TryParse(item.GetValue("Quantity"), out tmp))
                            {
                                if (tmp < boq.CheckQuantityTotal)
                                {
                                    throw new Formula.Exceptions.BusinessValidationException("【" + item.GetValue("Name") + "】清单已经计量" + boq.CheckQuantityTotal + boq.Unit + ",因此不能比这个数值小");
                                }
                            }

                            if (decimal.TryParse(item.GetValue("Price"), out tmp))
                            {
                                if (tmp < boq.CheckPriceTotal)
                                {
                                    throw new Formula.Exceptions.BusinessValidationException("【" + item.GetValue("Name") + "】清单已经计价" + boq.CheckPriceTotal + "元,因此不能比这个数值小");
                                }
                            }
                        }
                        this.UpdateEntity <S_C_BOQ_Version_Detail>(data, item);
                        //Add的部分始终保持为add的state,不能混为修改项
                        //只找normal的state变为modify
                        if (data.ModifyState == "Normal")
                        {
                            data.ModifyState = "Modify";
                        }
                    }
                }
                else if (dataStateFromUICtrl == "added")
                {
                    S_C_BOQ_Version_Detail detail = new S_C_BOQ_Version_Detail();
                    detail.ID        = FormulaHelper.CreateGuid();
                    detail.BOQID     = detail.ID;
                    detail.VersionID = versionID;

                    var details = this.entities.Set <S_C_BOQ_Version_Detail>().Where(a => a.VersionID == versionID).ToList();
                    if (details.Count == 0)
                    {
                        detail.SortIndex = 0;
                    }
                    else
                    {
                        var maxSortIndex = details.Max(c => c.SortIndex);
                        detail.SortIndex = maxSortIndex + 0.001;
                    }

                    detail.Name      = item.GetValue("Name");
                    detail.Code      = item.GetValue("Code");
                    detail.Unit      = item.GetValue("Unit");
                    detail.UnitPrice = 0;
                    detail.Quantity  = 0;
                    detail.Price     = 0;
                    decimal tmp = 0;
                    if (decimal.TryParse(item.GetValue("UnitPrice"), out tmp))
                    {
                        detail.UnitPrice = tmp;
                    }
                    if (decimal.TryParse(item.GetValue("Quantity"), out tmp))
                    {
                        detail.Quantity = tmp;
                    }
                    if (decimal.TryParse(item.GetValue("Price"), out tmp))
                    {
                        detail.Price = tmp;
                    }
                    detail.Property     = item.GetValue("Property");
                    detail.Remark       = item.GetValue("Remark");
                    detail.CreateDate   = DateTime.Now;
                    detail.CreateUserID = CurrentUserInfo.UserID;
                    detail.CreateUser   = CurrentUserInfo.UserName;
                    detail.ModifyState  = "Add";
                    entities.Set <S_C_BOQ_Version_Detail>().Add(detail);
                }
            }
            entities.SaveChanges();
            return(Json(""));
        }
Exemplo n.º 5
0
        public JsonResult SaveExcelData()
        {
            var    reader   = new System.IO.StreamReader(HttpContext.Request.InputStream);
            string data     = reader.ReadToEnd();
            var    tempdata = JsonConvert.DeserializeObject <Dictionary <string, string> >(data);
            var    list     = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(tempdata["data"]);

            var             vID     = GetQueryString("VersionID");
            S_C_BOQ_Version version = entities.Set <S_C_BOQ_Version>().Find(vID);

            if (version == null)
            {
                throw new Formula.Exceptions.BusinessValidationException("未找到ID为" + vID + "的S_C_BOQ_Version");
            }

            var groups = list.GroupBy(a => a.GetValue("Code")).Select(g => new { g.Key, Counts = g.Count() }).ToList();

            if (groups.Count(a => a.Counts > 1) > 0)
            {
                throw new Formula.Exceptions.BusinessValidationException("编号【" + groups.FirstOrDefault(a => a.Counts > 1).Key + "】重复");
            }

            var details  = this.entities.Set <S_C_BOQ_Version_Detail>().Where(a => a.VersionID == vID).ToList();
            var maxindex = details.Count() == 0 ? 0 : details.Max(a => a.SortIndex);

            foreach (var item in list)
            {
                string code = item.GetValue("Code");
                if (entities.Set <S_C_BOQ_Version_Detail>()
                    .Any(a => a.Code == code))
                {
                    throw new Formula.Exceptions.BusinessValidationException("编号【" + item.GetValue("Code") + "】重复");
                }

                S_C_BOQ_Version_Detail detail = new S_C_BOQ_Version_Detail();
                detail.ID        = FormulaHelper.CreateGuid();
                detail.BOQID     = detail.ID;
                detail.VersionID = version.ID;
                detail.Code      = item.GetValue("Code");
                detail.Name      = item.GetValue("Name");
                detail.Property  = item.GetValue("Property");
                detail.Unit      = item.GetValue("Unit");
                decimal tmp = 0;
                if (decimal.TryParse(item.GetValue("UnitPrice"), out tmp))
                {
                    detail.UnitPrice = tmp;
                }
                if (decimal.TryParse(item.GetValue("Quantity"), out tmp))
                {
                    detail.Quantity = tmp;
                }
                if (decimal.TryParse(item.GetValue("Price"), out tmp))
                {
                    detail.Price = tmp;
                }
                else
                {
                    detail.Price = detail.UnitPrice * detail.Quantity;
                }

                detail.Remark = item.GetValue("Remark");

                detail.CreateDate   = DateTime.Now;
                detail.CreateUserID = CurrentUserInfo.UserID;
                detail.CreateUser   = CurrentUserInfo.UserName;
                detail.ModifyState  = "Add";
                detail.SortIndex    = maxindex + 0.001;
                maxindex            = detail.SortIndex;

                entities.Set <S_C_BOQ_Version_Detail>().Add(detail);
            }

            entities.SaveChanges();
            return(Json("Success"));
        }