protected void btnAdd_ServerClick(Object sender, EventArgs e) { string mbcode = this.drpMBCode.InnerDropDownList.SelectedValue; string series = this.dSeries.Text; string type = this.drpType.SelectedValue; string assemblyCode = this.dAssemblyCode.Text.ToUpper(); try { MBCFGDef mbcfDef = new MBCFGDef(); mbcfDef.MBCode = mbcode; mbcfDef.Series = series; mbcfDef.TP = type; mbcfDef.CFG = assemblyCode; mbcfDef.Editor = this.HiddenUserName.Value; mbcfDef.Udt = DateTime.Now; mbcfDef.Cdt = DateTime.Now; IMBAssemblyCode.AddMBCFG(mbcfDef); } catch (FisException ex) { showErrorMessage(ex.mErrmsg); return; } catch (Exception ex) { showErrorMessage(ex.Message); return; } ShowMBCFGList(); this.UpdatePanel1.Update(); int id = getLstID(mbcode, series, type); string currentID = replaceSpecialChart(id.ToString()); ScriptManager.RegisterStartupScript(this.updatePanelAll, typeof(System.Object), "saveUpdate", "resetTableHeight();AddUpdateComplete('" + currentID + "');", true); }
/// <summary> /// /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { string check = (string)CurrentSession.GetValue(Session.SessionKeys.CN); string model = (string)CurrentSession.GetValue(Session.SessionKeys.ModelName); if ((check != null && check == "RCTO") || ((model != null) && (model.IndexOf("173") == 0 || model.IndexOf("146") == 0))) { IMBRepository CurrentMBRepository = RepositoryFactory.GetInstance().GetRepository<IMBRepository, IMB>(); IModelRepository CurrentModelRepository = RepositoryFactory.GetInstance().GetRepository<IModelRepository, Model>(); var CurrentMB = (MB)CurrentSession.GetValue(Session.SessionKeys.MB); IList<IMES.FisObject.Common.Model.ModelInfo> infos = new List<IMES.FisObject.Common.Model.ModelInfo>(); infos = CurrentModelRepository.GetModelInfoByModelAndName(model, "MN"); string series = ""; if (infos == null || infos.Count <= 0) { throw new FisException("ICT006", new string[] { }); } else { series = infos[0].Value; } IList<MBCFGDef> currentMBCFGList = new List<MBCFGDef>(); MBCFGDef currentMBCFG = new MBCFGDef(); currentMBCFGList = CurrentMBRepository.GetMBCFGByCodeSeriesAndType(CurrentMB.MBCode, series, "RCTO"); if (currentMBCFGList == null || currentMBCFGList.Count <= 0) { throw new FisException("ICT006", new string[] { }); } else { currentMBCFG = currentMBCFGList[0]; } //string thisYear = DateTime.Today.Year.ToString("0000"); string thisYear = ""; string weekCode = ""; //Vincent 2014-01-01 fixed bug : used wrong this year cross year issue //IList<string> weekCodeList = CurrentModelRepository.GetCodeFromHPWeekCodeInRangeOfDescr(); IList<HpweekcodeInfo> weekCodeList = CurrentModelRepository.GetHPWeekCodeInRangeOfDescr(); if (weekCodeList != null && weekCodeList.Count > 0) { weekCode = weekCodeList[0].code; thisYear = weekCodeList[0].descr.Trim().Substring(0, 4); } else { throw new FisException("ICT009", new string[] { }); } try { SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); NumControl currentMaxNum = numCtrlRepository.GetMaxValue("MBCT", currentMBCFG.CFG); if (currentMaxNum == null) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB"); if (first == null) { throw new FisException("ICT013", new string[] { }); } currentMaxNum = new NumControl(); currentMaxNum.NOName = currentMBCFG.CFG; currentMaxNum.NOType = "MBCT"; currentMaxNum.Value = thisYear + weekCode + first.code + beginNO; currentMaxNum.Customer = ""; numCtrlRepository.InsertNumControl(currentMaxNum); SqlTransactionManager.Commit(); CurrentSession.AddValue("MBCT", currentMBCFG.CFG + "00" + first.code + weekCode + beginNO); } else if (currentMaxNum.Value.Substring(0, 6) != (thisYear + weekCode)) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB"); if (first == null) { throw new FisException("ICT013", new string[] { }); } currentMaxNum.Value = thisYear + weekCode + first.code + beginNO; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue("MBCT", currentMBCFG.CFG + "00" + first.code + weekCode + beginNO); } else { if (currentMaxNum.Value.EndsWith("ZZZ")) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IList<SupplierCodeInfo> codeList = currentProductRepository.GetSupplierCodeListByCode(currentMaxNum.Value.Substring(6, 2)); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB", codeList[0].idex); if (first == null) { throw new FisException("ICT005", new string[] { }); } currentMaxNum.Value = thisYear + weekCode + first.code + beginNO; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue("MBCT", currentMBCFG.CFG + "00" + first.code + weekCode + beginNO); } else { ISequenceConverter seqCvt = new SequenceConverterNormal("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 3, "ZZZ", beginNO, '0'); string sequenceNumber = currentMaxNum.Value.Substring(8, 3); sequenceNumber = seqCvt.NumberRule.IncreaseToNumber(sequenceNumber, 1); currentMaxNum.Value = currentMaxNum.Value.Substring(0, 8) + sequenceNumber; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue("MBCT", currentMBCFG.CFG + "00" + currentMaxNum.Value.Substring(6, 2) + weekCode + sequenceNumber); } } } /*string mbct = CurrentSession.GetValue("MBCT") as string; if (!string.IsNullOrEmpty(mbct)) { IMES.FisObject.PCA.MB.MBInfo mbctInfo = new IMES.FisObject.PCA.MB.MBInfo(0, CurrentMB.Sn, "MBCT", mbct, Editor, DateTime.Now, DateTime.Now); CurrentMB.AddMBInfo(mbctInfo); }*/ } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } } else { MB currenMB = CurrentSession.GetValue(Session.SessionKeys.MB) as MB; string mbctValue = "T"; if (!MustGenerate) { IPartRepository CurrentPartRepository = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>(); mbctValue = CurrentPartRepository.GetPartInfoValue(currenMB.PCBModelID, "MBCT"); } if (mbctValue == "T") { IMBRepository CurrentMBRepository = RepositoryFactory.GetInstance().GetRepository<IMBRepository, IMB>(); MBCFGDef currentMBCFG = CurrentMBRepository.GetMBCFG(currenMB.MBCode, "PC"); if (currentMBCFG == null || string.IsNullOrEmpty(currentMBCFG.CFG)) { throw new FisException("ICT006", new string[] { }); } //string thisYear = DateTime.Today.Year.ToString("0000"); string thisYear = ""; string weekCode = ""; IModelRepository CurrentModelRepository = RepositoryFactory.GetInstance().GetRepository<IModelRepository, Model>(); //Vincent 2014-01-01 fixed bug : used wrong this year cross year issue //IList<string> weekCodeList = CurrentModelRepository.GetCodeFromHPWeekCodeInRangeOfDescr(); IList<HpweekcodeInfo> weekCodeList = CurrentModelRepository.GetHPWeekCodeInRangeOfDescr(); if (weekCodeList != null && weekCodeList.Count > 0) { weekCode = weekCodeList[0].code; thisYear = weekCodeList[0].descr.Trim().Substring(0, 4); } else { throw new FisException("ICT009", new string[] { }); } try { SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); NumControl currentMaxNum = numCtrlRepository.GetMaxValue("MBCT", currentMBCFG.CFG); if (currentMaxNum == null) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB"); if (first == null) { throw new FisException("ICT013", new string[] { }); } currentMaxNum = new NumControl(); currentMaxNum.NOName = currentMBCFG.CFG; currentMaxNum.NOType = "MBCT"; currentMaxNum.Value = thisYear + weekCode + first.code + beginNO; currentMaxNum.Customer = ""; numCtrlRepository.InsertNumControl(currentMaxNum); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.MBCT, currentMBCFG.CFG + "00" + first.code + weekCode + beginNO); } else if (currentMaxNum.Value.Substring(0, 6) != (thisYear + weekCode)) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB"); if (first == null) { throw new FisException("ICT013", new string[] { }); } currentMaxNum.Value = thisYear + weekCode + first.code + beginNO; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.MBCT, currentMBCFG.CFG + "00" + first.code + weekCode + beginNO); } else { if (currentMaxNum.Value.EndsWith("ZZZ")) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IList<SupplierCodeInfo> codeList = currentProductRepository.GetSupplierCodeListByCode(currentMaxNum.Value.Substring(6, 2)); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB", codeList[0].idex); if (first == null) { throw new FisException("ICT005", new string[] { }); } currentMaxNum.Value = thisYear + weekCode + first.code + beginNO; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.MBCT, currentMBCFG.CFG + "00" + first.code + weekCode + beginNO); } else { ISequenceConverter seqCvt = new SequenceConverterNormal("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 3, "ZZZ", beginNO, '0'); string sequenceNumber = currentMaxNum.Value.Substring(8, 3); sequenceNumber = seqCvt.NumberRule.IncreaseToNumber(sequenceNumber, 1); currentMaxNum.Value = currentMaxNum.Value.Substring(0, 8) + sequenceNumber; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.MBCT, currentMBCFG.CFG + "00" + currentMaxNum.Value.Substring(6, 2) + weekCode + sequenceNumber); } } } } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } } } return base.DoExecute(executionContext); }