public async Task GetPrioritiesAsync() { OperationInProgress = true; Priorities = await PrioritiesProvider.GetPrioritiesAsync(); SelectedPriority = Priorities?.FirstOrDefault(); OperationInProgress = false; }
protected void ucFileUpload_Upload(object sender, EventArgs e) { UploadEventArgs ue = e as UploadEventArgs; DataTable dtDetails = ue.ContentTable; dtDetails.DefaultView.Sort = "零件号"; dtDetails = dtDetails.DefaultView.ToTable(); bool isValid = true; List <ViewPart> partList = new List <ViewPart>(); //get part by code, plant, duns //for (int i = 0; i < dtDetails.Rows.Count; i++) //{ // ViewPart tmpPart = new ViewPart // { // PlantCode = dtDetails.Rows[i]["工厂代码"].ToString(), // DUNS = dtDetails.Rows[i]["供应商DUNS"].ToString(), // PartCode = dtDetails.Rows[i]["零件号"].ToString() // }; // if (!partList.Exists(p => string.Equals(p.PartCode , tmpPart.PartCode, StringComparison.OrdinalIgnoreCase) && string.Equals(p.PlantCode ,tmpPart.PlantCode , StringComparison.OrdinalIgnoreCase)&& string.Equals(p.DUNS ,tmpPart.DUNS, StringComparison.OrdinalIgnoreCase))) // { // partList.Add(tmpPart); // } //} List <View_StocktakeDetails> detailsList = new List <View_StocktakeDetails>(); for (int i = 0; i < dtDetails.Rows.Count; i++) { bool hasError = false; View_StocktakeDetails details = new View_StocktakeDetails { RowNumber = int.Parse(dtDetails.Rows[i]["序号"].ToString()), PartCode = dtDetails.Rows[i]["零件号"].ToString(), DUNS = dtDetails.Rows[i]["供应商DUNS"].ToString(), PartPlantCode = dtDetails.Rows[i]["工厂代码"].ToString(), TypeName = dtDetails.Rows[i]["申请类别"].ToString(), PriorityName = dtDetails.Rows[i]["紧急程度"].ToString(), Description = dtDetails.Rows[i]["备注"].ToString() }; string msg; if (i % 5000 == 0) { string startCode = details.PartCode; int end = i + 4999; if (end >= dtDetails.Rows.Count) { end = dtDetails.Rows.Count - 1; } string endCode = dtDetails.Rows[end]["零件号"].ToString(); partList = Service.QueryPartCodeScope(null, startCode, endCode); } ViewPart part = partList.FirstOrDefault(p => string.Equals(p.PartCode, details.PartCode, StringComparison.OrdinalIgnoreCase) && string.Equals(p.PlantCode, details.PartPlantCode, StringComparison.OrdinalIgnoreCase) && string.Equals(p.DUNS, details.DUNS, StringComparison.OrdinalIgnoreCase)); if (part == null)//part is invalid { msg = string.Format("第{0}行,该零件不存在", i + 2); UCFileUpload1.AddErrorInfo(msg); hasError = true; } else { details.PartID = part.PartID; } StocktakePriority priority = Priorities.FirstOrDefault(p => string.Equals(p.PriorityName, details.PriorityName, StringComparison.OrdinalIgnoreCase)); if (priority == null) { msg = string.Format("第{0}行,紧急程度信息非法", i + 2); UCFileUpload1.AddErrorInfo(msg); hasError = true; } else { details.Priority = priority.PriorityID; } StocktakeType type = StocktakeTypes.FirstOrDefault(t => string.Equals(t.TypeName, details.TypeName, StringComparison.OrdinalIgnoreCase)); if (type == null) { msg = string.Format("第{0}行,申请类别信息非法", i + 2); UCFileUpload1.AddErrorInfo(msg); hasError = true; } else { details.StocktakeType = type.TypeID; } if (!hasError) { if (detailsList.Exists(d => string.Equals(d.TypeName, details.TypeName, StringComparison.OrdinalIgnoreCase) && string.Equals(d.PriorityName, details.PriorityName, StringComparison.OrdinalIgnoreCase) && string.Equals(d.PartPlantCode, details.PartPlantCode, StringComparison.OrdinalIgnoreCase) && string.Equals(d.DUNS, details.DUNS, StringComparison.OrdinalIgnoreCase) && string.Equals(d.PartCode, details.PartCode, StringComparison.OrdinalIgnoreCase))) { msg = string.Format("第{0}行,数据重复", i + 2); UCFileUpload1.AddErrorInfo(msg); hasError = true; } else { detailsList.Add(details); } } isValid = isValid && !hasError; } if (isValid) { NewStocktakeRequest newRequest = new NewStocktakeRequest { IsStatic = (rblIsStatic.SelectedIndex == 1), RequestBy = CurrentUser.UserInfo.UserID, IsCycleCount = false, Details = (from d in detailsList select new NewStocktakeDetails { PartID = d.PartID.ToString(), StocktakePriority = d.Priority.Value, StocktakeTypeID = d.StocktakeType.Value, Description = d.Description }).ToList() }; int currentDynAmount = 0; int currentStAmount = 0; foreach (var item in UserGroups) { currentDynAmount += item.CurrentDynamicStocktake ?? 0; currentStAmount += item.CurrentStaticStocktake ?? 0; } int maxUserCount; int currentCount; int maxCount; if (!newRequest.IsStatic) { BizParams param = BizParamsList.Find(p => p.ParamKey == "MaxDynamic"); maxCount = int.Parse(param.ParamValue); maxUserCount = CurrentUser.UserInfo.UserGroup.MaxDynamicStocktake ?? 0; currentCount = CurrentUser.UserInfo.UserGroup.CurrentDynamicStocktake.Value; int dynOverflowAmount = currentCount + newRequest.Details.Count - maxUserCount; if (dynOverflowAmount > 0) { ScriptManager.RegisterStartupScript(this, this.GetType(), "maxOverflow", "alert('超过当前用户组动态盘点上限" + dynOverflowAmount + "个')", true); return; } dynOverflowAmount = currentDynAmount + newRequest.Details.Count - maxCount; if (dynOverflowAmount > 0) { ScriptManager.RegisterStartupScript(this, this.GetType(), "maxOverflow", "alert('超过动态盘点总数上限" + dynOverflowAmount + "个')", true); return; } } if (newRequest.IsStatic) { BizParams param = BizParamsList.Find(p => p.ParamKey == "MaxStatic"); maxCount = int.Parse(param.ParamValue); maxUserCount = CurrentUser.UserInfo.UserGroup.MaxStaticStocktake.Value; currentCount = CurrentUser.UserInfo.UserGroup.CurrentStaticStocktake.Value; int stOverflowAmount = currentCount + newRequest.Details.Count - maxUserCount; if (stOverflowAmount > 0) { ScriptManager.RegisterStartupScript(this, this.GetType(), "maxOverflow", "alert('超过当前用户组静态盘点上限" + stOverflowAmount + "个')", true); return; } stOverflowAmount = currentStAmount + newRequest.Details.Count - maxCount; if (stOverflowAmount > 0) { ScriptManager.RegisterStartupScript(this, this.GetType(), "maxOverflow", "alert('超过静态盘点总数上限" + stOverflowAmount + "个')", true); return; } } //fill in items StocktakeRequest request = Service.RequestStocktake(newRequest); BindDataControl(gvResult, detailsList); CurrentUser.RefreshUserProfile(); CacheHelper.RemoveCache(Consts.CACHE_KEY_USER_GROUPS); //show information this.UCFileUpload1.AddSuccessInfo("盘点申请成功,申请单号" + request.RequestNumber, string.Empty, string.Empty); } }