void addModuleSelf(string moduleCode, string moduleName, int ID, int parentID, int qty, string manageId, string moduleCodeHD) { string typeID = "T0068"; DataTable dt = LibQLSX.Select("select TypeId from SourceCode with(nolock) where FolderCode = '" + moduleCode + "'"); if (dt.Rows.Count > 0) { typeID = TextUtils.ToString(dt.Rows[0]["TypeId"]); } ProjectProductsModel projectProduct = new ProjectProductsModel(); #region Create ProjectModule DataTable dtPMID = LibQLSX.Select(" SELECT top 1 ProjectModuleId FROM ProjectModule with(nolock) order by ProjectModuleId desc"); string PMid = TextUtils.ToString(dtPMID.Rows[0]["ProjectModuleId"]); PMid = PMid.Substring(2, PMid.Length - 2); PMid = "PM" + string.Format("{0:00000000}", TextUtils.ToInt(PMid) + 1); ProjectModuleModel projectModule = new ProjectModuleModel(); projectModule.IsModuleStandard = 0; projectModule.Note = ""; projectModule.ProjectModuleCode = moduleCode; projectModule.ProjectModuleName = moduleName; projectModule.Specifications = ""; projectModule.ProjectModuleId = PMid; ProjectModuleBO.Instance.InsertQLSX(projectModule); #endregion #region Update ProjectProducts ArrayList listPP = ProjectProductsBO.Instance.FindByAttribute("PProductId", manageId); projectProduct = (ProjectProductsModel)listPP[0]; projectProduct.ProjectModuleId = projectModule.ProjectModuleId; projectProduct.TypeId = typeID; ProjectProductsBO.Instance.UpdateQLSX(projectProduct); #endregion #region Create ChildModule DataRow[] drsChild = _dtModule.Select("ParentID = " + ID); if (drsChild.Length > 0) { foreach (DataRow item in drsChild) { string moduleCode1 = TextUtils.ToString(item["F5"]); string moduleName1 = TextUtils.ToString(item["F3"]); int ID1 = TextUtils.ToInt(item["ID"]); int parentID1 = TextUtils.ToInt(item["ParentID"]); int qty1 = TextUtils.ToInt(item["F7"]); string manageId1 = projectProduct.PProductId; addModule(moduleCode1, moduleName1, ID1, parentID1, qty1, manageId1, ""); } } #endregion }
protected ProjectModuleFacade(ProjectModuleModel model) : base(model) { }
void addModule(string moduleCode, string moduleName, int ID, int parentID, int qty, string manageId, string moduleCodeHD) { string typeID = "T0068"; DataTable dt = LibQLSX.Select("select TypeId from SourceCode with(nolock) where FolderCode = '" + moduleCode + "'"); if (dt.Rows.Count > 0) { typeID = TextUtils.ToString(dt.Rows[0]["TypeId"]); } ProjectProductsModel projectProduct = new ProjectProductsModel(); if (parentID == 0) { if (moduleCode.StartsWith("TPAD")) { DataTable dtPP = LibQLSX.Select("select * from vGetProductOfProject with(nolock) where ManageId = '" + manageId + "' and PPCode = '" + moduleCodeHD + "'"); foreach (DataRow row in dtPP.Rows) { string id = TextUtils.ToString(row["PProductId"]); #region Create ProjectModule DataTable dtPMID = LibQLSX.Select(" SELECT top 1 ProjectModuleId FROM ProjectModule with(nolock) order by ProjectModuleId desc"); string PMid = TextUtils.ToString(dtPMID.Rows[0]["ProjectModuleId"]); PMid = PMid.Substring(2, PMid.Length - 2); PMid = "PM" + string.Format("{0:00000000}", TextUtils.ToInt(PMid) + 1); ProjectModuleModel projectModule = new ProjectModuleModel(); projectModule.IsModuleStandard = 0; projectModule.Note = ""; projectModule.ProjectModuleCode = moduleCode; projectModule.ProjectModuleName = moduleName; projectModule.Specifications = ""; projectModule.ProjectModuleId = PMid; ProjectModuleBO.Instance.InsertQLSX(projectModule); #endregion #region Update ProjectProducts ArrayList listPP = ProjectProductsBO.Instance.FindByAttribute("PProductId", id); projectProduct = (ProjectProductsModel)listPP[0]; projectProduct.ProjectModuleId = PMid; projectProduct.TypeId = typeID; ProjectProductsBO.Instance.UpdateQLSX(projectProduct); #endregion #region Create ChildModule DataRow[] drsChild = _dtModule.Select("ParentID = " + ID); if (drsChild.Length > 0) { foreach (DataRow item in drsChild) { string moduleCode1 = TextUtils.ToString(item["F5"]); string moduleName1 = TextUtils.ToString(item["F3"]); int ID1 = TextUtils.ToInt(item["ID"]); int parentID1 = TextUtils.ToInt(item["ParentID"]); int qty1 = TextUtils.ToInt(item["F7"]); string manageId1 = projectProduct.PProductId; addModule(moduleCode1, moduleName1, ID1, parentID1, qty1, manageId1, ""); } } #endregion } } else //Nếu là vật tư phụ { #region Create ProjectModule DataTable dtPMID = LibQLSX.Select(" SELECT top 1 ProjectModuleId FROM ProjectModule with(nolock) order by ProjectModuleId desc"); string PMid = TextUtils.ToString(dtPMID.Rows[0]["ProjectModuleId"]); PMid = PMid.Substring(2, PMid.Length - 2); PMid = "PM" + string.Format("{0:00000000}", TextUtils.ToInt(PMid) + 1); ProjectModuleModel projectModule = new ProjectModuleModel(); projectModule.IsModuleStandard = 0; projectModule.Note = ""; projectModule.ProjectModuleCode = moduleCode; projectModule.ProjectModuleName = moduleName; projectModule.Specifications = ""; projectModule.ProjectModuleId = PMid; ProjectModuleBO.Instance.InsertQLSX(projectModule); #endregion #region Create ProjectProducts DataTable dtPPID = LibQLSX.Select(" SELECT top 1 PProductId FROM ProjectProducts with(nolock) order by PProductId desc"); string PPid = TextUtils.ToString(dtPPID.Rows[0]["PProductId"]); PPid = PPid.Substring(2, PPid.Length - 2); PPid = "PP" + string.Format("{0:00000000}", TextUtils.ToInt(PPid) + 1); projectProduct.DepartmentCreateId = "D009"; projectProduct.DepartmentDesignId = "D009"; projectProduct.ManageId = manageId; projectProduct.ManufacturerId = "M000000001"; projectProduct.PProductInforId = ""; projectProduct.ProjectId = TextUtils.ToString(grvProject.GetFocusedRowCellValue(colProjectID)); projectProduct.ProjectModuleId = projectModule.ProjectModuleId; projectProduct.Status = 2; projectProduct.StatusCheckDesignInfor = 1; projectProduct.StatusConfirm = 1; projectProduct.Total = qty; projectProduct.TypeId = typeID; projectProduct.Origin = "Việt Nam"; projectProduct.PProductId = PPid; ProjectProductsBO.Instance.InsertQLSX(projectProduct); #endregion } } else //nếu là module con { #region Create ProjectModule DataTable dtPMID = LibQLSX.Select(" SELECT top 1 ProjectModuleId FROM ProjectModule with(nolock) order by ProjectModuleId desc"); string PMid = TextUtils.ToString(dtPMID.Rows[0]["ProjectModuleId"]); PMid = PMid.Substring(2, PMid.Length - 2); PMid = "PM" + string.Format("{0:00000000}", TextUtils.ToInt(PMid) + 1); ProjectModuleModel projectModule = new ProjectModuleModel(); projectModule.IsModuleStandard = 0; projectModule.Note = ""; projectModule.ProjectModuleCode = moduleCode; projectModule.ProjectModuleName = moduleName; projectModule.Specifications = ""; projectModule.ProjectModuleId = PMid; ProjectModuleBO.Instance.InsertQLSX(projectModule); #endregion #region Create ProjectProducts DataTable dtPPID = LibQLSX.Select(" SELECT top 1 PProductId FROM ProjectProducts with(nolock) order by PProductId desc"); string PPid = TextUtils.ToString(dtPPID.Rows[0]["PProductId"]); PPid = PPid.Substring(2, PPid.Length - 2); PPid = "PP" + string.Format("{0:00000000}", TextUtils.ToInt(PPid) + 1); projectProduct.DepartmentCreateId = "D009"; projectProduct.DepartmentDesignId = "D009"; projectProduct.ManageId = manageId; projectProduct.ManufacturerId = "M000000001"; projectProduct.PProductInforId = ""; projectProduct.ProjectId = TextUtils.ToString(grvProject.GetFocusedRowCellValue(colProjectID)); projectProduct.ProjectModuleId = projectModule.ProjectModuleId; projectProduct.Status = 2; projectProduct.StatusCheckDesignInfor = 1; projectProduct.StatusConfirm = 1; projectProduct.Total = qty; projectProduct.TypeId = typeID; projectProduct.Origin = "Việt Nam"; projectProduct.PProductId = PPid; ProjectProductsBO.Instance.InsertQLSX(projectProduct); #endregion #region Create ChildModule DataRow[] drsChild = _dtModule.Select("ParentID = " + ID); if (drsChild.Length > 0) { foreach (DataRow item in drsChild) { string moduleCode1 = TextUtils.ToString(item["F5"]); string moduleName1 = TextUtils.ToString(item["F3"]); int ID1 = TextUtils.ToInt(item["ID"]); int parentID1 = TextUtils.ToInt(item["ParentID"]); int qty1 = TextUtils.ToInt(item["F7"]); string manageId1 = projectProduct.PProductId; addModule(moduleCode1, moduleName1, ID1, parentID1, qty1, manageId1, ""); } } #endregion } }
private void btnCreateDirection_Click(object sender, EventArgs e) { DocUtils.InitFTPQLSX(); grvData.FocusedRowHandle = -1; DataTable dtDirectionType = LibQLSX.Select("SELECT * FROM [ProjectDirectionType]"); DataTable dtMaterialModel = LibQLSX.Select("SELECT * FROM [MaterialsModel]"); string projectCode = TextUtils.ToString(grvProject.GetFocusedRowCellValue(colProjectCode)); DataRow[] drs = _dtData.Select("Check = 1 and ProjectDirectionID is null"); if (drs.Length == 0) { return; } //ProcessTransaction pt = new ProcessTransaction(); //pt.OpenConnection(); //pt.BeginTransaction(); //try //{ ProjectDirectionModel direction = new ProjectDirectionModel(); direction.Code = ""; direction.Name = "Chỉ thị ngày: " + DateTime.Now.ToString("dd/MM/yyyy"); direction.ProjectCode = projectCode; direction.ProjectId = TextUtils.ToString(cboProject.EditValue); direction.CreatedBy = Global.AppUserName; direction.CreatedDate = DateTime.Now; direction.ID = (int)ProjectDirectionBO.Instance.Insert(direction); for (int i = 0; i < drs.Length; i++) { //DateTime maxDate = new DateTime(1990, 1, 1); //string statusText = TextUtils.ToString(drs[i]["StatusText"]); //if (statusText != "") continue; string moduleCode = TextUtils.ToString(drs[i]["ProjectModuleCode"]); decimal parentQty = TextUtils.ToDecimal(drs[i]["TotalReal"]); DateTime?dateAboutE = TextUtils.ToDate2(drs[i]["DateAboutE"]); string projectModuleId = TextUtils.ToString(drs[i]["ProjectModuleId"]); string note = TextUtils.ToString(drs[i]["Note"]); DataTable dtLink = new DataTable(); dtLink = TextUtils.GetDMVT(moduleCode, true); DataRow[] drsL = dtLink.Select("F3 = 'TPA'"); if (drsL.Length > 0) { dtLink = drsL.CopyToDataTable(); } else { continue; } //dtLink = LibQLSX.Select("select * from vMaterialModuleLink with(nolock) where ThongSo = 'TPA' and ModuleCode = '" + moduleCode + "'"); string moduleGroup = moduleCode.Substring(0, 6); string serverPathMat = string.Format(@"/Thietke.Ck/{0}/{1}.Ck/MAT.{1}", moduleGroup, moduleCode); string serverPathCad = string.Format(@"/Thietke.Ck/{0}/{1}.Ck/CAD.{1}", moduleGroup, moduleCode); string[] array = DocUtils.GetContentList(serverPathMat); #region Update ProjectModule ArrayList arr = ProjectModuleBO.Instance.FindByAttribute("ProjectModuleId", projectModuleId); if (arr.Count > 0) { ProjectModuleModel model = (ProjectModuleModel)arr[0]; model.ProjectDirectionID = direction.ID; ProjectModuleBO.Instance.UpdateQLSX(model); } #endregion #region In phim if (array != null) { for (int i1 = 0; i1 < array.Length; i1++) { //try //{ string partsCode = array[i1].Split('-')[0]; DataRow[] drsLink = dtLink.Select("F4 = '" + partsCode + "' or F4 like '" + partsCode + "-%'"); decimal qty = parentQty * (drsLink.Length > 0 ? TextUtils.ToDecimal(drsLink[0]["QtyReal"]) : 1); //DataTable dtDetail = LibQLSX.Select("select top 1 * from ProjectDirectionDetail where ProjectDirectionTypeID = 2 and PartsCode = '" // + partsCode + "' and ProjectDirectionID = " + direction.ID); //if (dtDetail.Rows.Count > 0) //{ // ProjectDirectionDetailModel detail = (ProjectDirectionDetailModel)ProjectDirectionDetailBO.Instance.FindByPK(TextUtils.ToInt(dtDetail.Rows[0]["ID"])); // detail.Qty += qty; // ProjectDirectionDetailBO.Instance.Update(detail); //} //else //{ ProjectDirectionDetailModel detail = new ProjectDirectionDetailModel(); detail.ProjectModuleId = projectModuleId; detail.ProjectDirectionID = direction.ID; //projectDirection.Material = TextUtils.ToString(dtLink.Rows[j]["VatLieu"]); detail.ModuleCode = moduleCode; detail.PartsCode = partsCode; //projectDirection.PartsName = TextUtils.ToString(dtLink.Rows[j]["PartsName"]); detail.ProjectCode = projectCode; detail.Qty = qty; //projectDirection.STT = TextUtils.ToString(dtLink.Rows[j]["STT"]); detail.ThongSo = "TPA"; //projectDirection.Unit = TextUtils.ToString(dtLink.Rows[j]["Unit"]); detail.UserId = ""; detail.ProjectDirectionTypeID = 2;//In DataRow[] drsDirectionType = dtDirectionType.Select("ID = " + detail.ProjectDirectionTypeID); detail.MakeTime = TextUtils.ToDecimal(drsDirectionType[0]["TimeDK"]); detail.FilePath = serverPathMat + "/" + array[i1]; detail.FileName = array[i1]; detail.StartDateDK = null; //dateAboutE; detail.EndDateDK = null; //dateAboutE != null ? dateAboutE.Value.AddHours((double)(parentQty * detail.MakeTime)) : dateAboutE; detail.StartDate = null; detail.EndDate = null; detail.IsNew = 0; detail.IsDeleted = 0; detail.CreatedBy = Global.AppUserName; detail.CreatedDate = DateTime.Now; detail.Note = note; ProjectDirectionBO.Instance.Insert(detail); //} //} //catch (Exception) //{ // throw; //} } } #endregion #region Other for (int j = 0; j < dtLink.Rows.Count; j++) { //try //{ string partsCode = TextUtils.ToString(dtLink.Rows[j]["F4"]); decimal qty = parentQty * TextUtils.ToDecimal(dtLink.Rows[j]["QtyReal"]); string material = TextUtils.ToString(dtLink.Rows[j]["F8"]); int projectDirectionTypeID = TextUtils.ToInt(dtLink.Rows[j]["ProjectDirectionTypeID"]); if (partsCode.StartsWith("PCB")) { projectDirectionTypeID = 4; } //else //{ // DataRow[] drsMaterialModel = dtMaterialModel.Select("MaterialsId = '" + material + "'"); // projectDirectionTypeID = drsMaterialModel.Length > 0 ? 3 : TextUtils.ToInt(drsMaterialModel[0]["ProjectDirectionTypeID"]); //} //DataTable dtDetail = LibQLSX.Select("select top 1 * from ProjectDirectionDetail where ProjectDirectionTypeID = " + projectDirectionTypeID + " and PartsCode = '" // + partsCode + "' and ProjectDirectionID = " + direction.ID); //if (dtDetail.Rows.Count > 0) //{ // ProjectDirectionDetailModel detail = (ProjectDirectionDetailModel)ProjectDirectionDetailBO.Instance.FindByPK(TextUtils.ToInt(dtDetail.Rows[0]["ID"])); // detail.Qty += qty; // ProjectDirectionDetailBO.Instance.Update(detail); //} //else //{ ProjectDirectionDetailModel detail = new ProjectDirectionDetailModel(); detail.ProjectModuleId = projectModuleId; detail.ProjectDirectionID = direction.ID; detail.Material = material; detail.ModuleCode = moduleCode; detail.PartsCode = partsCode; detail.PartsName = TextUtils.ToString(dtLink.Rows[j]["F2"]); detail.ProjectCode = projectCode; detail.Qty = qty; detail.STT = TextUtils.ToString(dtLink.Rows[j]["F1"]); detail.ThongSo = "TPA"; //detail.Unit = TextUtils.ToString(dtLink.Rows[j]["F6"]); //detail.MaVatLieu = TextUtils.ToString(dtLink.Rows[j]["F5"]); detail.MaVatLieu = TextUtils.ToString(dtLink.Rows[j]["F5"]); string unitPart = TextUtils.ToString(LibQLSX.ExcuteScalar("select top 1 Unit from Parts where PartsCode = N'" + detail.MaVatLieu + "'")); detail.Unit = unitPart; detail.UserId = ""; detail.ProjectDirectionTypeID = projectDirectionTypeID; if (detail.PartsCode.StartsWith("PCB")) { string serverPathPCB = string.Format("/Thietke.Dt/PCB/{0}/PRD.{0}/", detail.PartsCode); detail.FilePath = serverPathPCB + "TPAT." + detail.PartsCode.Substring(4, 7) + ".doc";//PCB.B060101 detail.FileName = "TPAT." + detail.PartsCode.Substring(4, 7) + ".doc"; detail.StartDateDK = dateAboutE; detail.EndDateDK = dateAboutE != null?dateAboutE.Value.AddHours((double)(parentQty *detail.MakeTime)) : dateAboutE; } else { detail.FilePath = serverPathCad + "/" + detail.PartsCode + ".dwg"; detail.FileName = detail.PartsCode + ".dwg"; detail.StartDateDK = null; detail.EndDateDK = null; } DataRow[] drsDirectionType = dtDirectionType.Select("ID = " + detail.ProjectDirectionTypeID); detail.MakeTime = drsDirectionType.Length > 0 ? TextUtils.ToDecimal(drsDirectionType[0]["TimeDK"]) : 3; detail.StartDate = null; detail.EndDate = null; detail.IsNew = 0; detail.IsDeleted = 0; detail.CreatedBy = Global.AppUserName; detail.CreatedDate = DateTime.Now; detail.Note = note; ProjectDirectionBO.Instance.Insert(detail); //if (maxDate < detail.EndDateDK) // maxDate = (DateTime)detail.EndDateDK; //} //} //catch (Exception) //{ // throw; //} } #endregion #region Lắp ráp //try //{ //DataTable dtDetail1 = LibQLSX.Select("select top 1 * from ProjectDirectionDetail where ProjectDirectionTypeID > 4 and PartsCode = '" // + moduleCode + "' and ProjectDirectionID = " + direction.ID); //if (dtDetail1.Rows.Count > 0) //{ // ProjectDirectionDetailModel detail = (ProjectDirectionDetailModel)ProjectDirectionDetailBO.Instance.FindByPK(TextUtils.ToInt(dtDetail1.Rows[0]["ID"])); // detail.Qty += parentQty; // ProjectDirectionDetailBO.Instance.Update(detail); //} //else //{ ProjectDirectionDetailModel directionDetail = new ProjectDirectionDetailModel(); directionDetail.ProjectModuleId = projectModuleId; directionDetail.ProjectDirectionID = direction.ID; //directionDetail.Material = TextUtils.ToString(dtLink.Rows[j]["VatLieu"]); directionDetail.ModuleCode = moduleCode; directionDetail.PartsCode = moduleCode; directionDetail.PartsName = TextUtils.ToString(drs[i]["ProjectModuleName"]); directionDetail.ProjectCode = projectCode; directionDetail.Qty = parentQty; //directionDetail.STT = TextUtils.ToString(dtLink.Rows[j]["STT"]); directionDetail.ThongSo = "TPA"; directionDetail.Unit = "BỘ"; directionDetail.UserId = ""; directionDetail.FilePath = ""; DataRow[] drsDirectionType1 = dtDirectionType.Select("Code = '" + moduleCode.Substring(0, 6) + "'"); if (drsDirectionType1.Length > 0) { directionDetail.ProjectDirectionTypeID = TextUtils.ToInt(drsDirectionType1[0]["ID"]); directionDetail.MakeTime = TextUtils.ToDecimal(drsDirectionType1[0]["TimeDK"]); } else { directionDetail.MakeTime = 0; } directionDetail.StartDateDK = null; //maxDate; directionDetail.EndDateDK = null; //directionDetail.StartDateDK != null ? directionDetail.StartDateDK.Value.AddHours((double)(directionDetail.Qty * directionDetail.MakeTime)) : directionDetail.StartDateDK; directionDetail.StartDate = null; directionDetail.EndDate = null; directionDetail.IsNew = 0; directionDetail.IsDeleted = 0; directionDetail.CreatedBy = Global.AppUserName; directionDetail.CreatedDate = DateTime.Now; directionDetail.Note = note; ProjectDirectionBO.Instance.Insert(directionDetail); //} //} //catch (Exception) //{ // throw; //} #endregion } //pt.CommitTransaction(); MessageBox.Show("Tạo chỉ thị thành công", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); frmProjectDirection frm = new frmProjectDirection(); frm.ProjectDirectionID = direction.ID; frm.Show(); //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); //} //finally //{ // pt.CloseConnection(); //} }