/// <summary> /// Cất dữ liệu /// </summary> /// <returns></returns> bool saveData() { if (!ValidateForm()) { return(false); } Product.ProductGroupID = TextUtils.ToInt(cboGroup.EditValue); Product.ProductTypeCode = txtProductTypeCode.Text.Trim(); Product.ProductCode = txtCode.Text.Trim(); Product.ProductName = txtDes.Text.Trim(); Product.RatioCode = txtRatio.Text.Trim(); Product.PinNumber = txtPinNumber.Text.Trim(); Product.PinNumberIN = txtPinNumberIN.Text.Trim(); Product.CoilCode = txtCoilCode.Text.Trim(); Product.MotorCode = txtMotorCode.Text.Trim(); Product.LoaiMo = txtLoaiMo.Text.Trim(); Product.LuongMo = txtLuongMo.Value; Product.MURATA = txtMurata.Text.Trim(); Product.UnitMotor = txtUnitMotor.Text.Trim(); Product.MauSon = txtMauSon.Text.Trim(); Product.MEDEDAY = TextUtils.ToDate2(dtpMEDEDAY.EditValue); Product.ProductDate = TextUtils.ToDate2(dtpDate.EditValue); Product.HuongHopCau = txtHuongHopCau.Text.Trim(); Product.DienAp = txtDienAp.Value; Product.TanSo = txtTanSo.Value; Product.DongDienMin = txtDongDienMin.Value; Product.DongDienMax = txtDongDienMax.Value; Product.NhapLucMax = txtNhapLucMax.Value; Product.NhapLucMin = txtNhapLucMin.Value; Product.VongQuayMax = txtVongQuayMax.Value; Product.VongQuayMin = txtVongQuayMin.Value; Product.TiengOnMax = txtTiengOnMax.Value; Product.TiengOnMin = txtTiengOnMin.Value; Product.DoRungFFTMax = txtDoRungMax.Value; Product.DoRungFFTMin = txtDoRungMin.Value; Product.GunNumber = TextUtils.ToInt(txtGunNumber.Value); Product.JobNumber = TextUtils.ToInt(txtJobNumber.Value); Product.QtyOcBanGa = TextUtils.ToInt(txtQtyOcBanGa.Value); Product.QtyOcBanThat = TextUtils.ToInt(txtQtyOcBanThat.Value); Product.BuLongNumber = TextUtils.ToInt(txtBuLongNumber.Value); Product.ShootNumber = TextUtils.ToInt(txtShootNumber.Value); Product.SetForce = TextUtils.ToInt(txtSetForce.Value); Product.DifferenceMax = txtDifferenceMax.Value; Product.DifferenceMin = txtDifferenceMin.Value; Product.SizeSSSMax = txtSizeSSSMax.Value; Product.SizeSSSMin = txtSizeSSSMin.Value; Product.SpaceCenterMax = txtSpaceCenterMax.Value; Product.SpaceCenterMin = txtSpaceCenterMin.Value; Product.SpaceCycloidDiskMin = txtSpaceCycloidDiskMin.Value; Product.SpaceCycloidDiskMax = txtSpaceCycloidDiskMax.Value; Product.LucCheckGearMax = txtLucCheckGearMax.Value; Product.LucCheckGearMin = txtLucCheckGearMin.Value; Product.LucCheckGearMotorMax = txtLucCheckGearMotorMax.Value; Product.LucCheckGearMotorMin = txtLucCheckGearMotorMin.Value; Product.LucCheck3Max = txtLucCheck3Max.Value; //Lực check cụm trục tốc độ thấp 511-512 Product.LucCheck3Min = txtLucCheck3Min.Value; Product.LucCheck4Max = txtLucCheck4Max.Value; //Lực check phần xuất lực Naknishi Product.LucCheck4Min = txtLucCheck4Min.Value; Product.LucCheck5Max = txtLucCheck5Max.Value; //Lực check Ốc chặn mỡ Nakanishi, 6000 Product.LucCheck5Min = txtLucCheck5Min.Value; Product.DoDao1Max = txtDoDao1Max.Value; //ĐẢO TRƯỚC ÉP VÒNG BI Product.DoDao1Min = txtDoDao1Min.Value; Product.DoDao2Max = txtDoDao2Max.Value; //ĐẢO SAU ÉP VÒNG BI Product.DoDao2Min = txtDoDao2Min.Value; Product.DoDao3Max = txtDoDao3Max.Value; Product.DoDao3Min = txtDoDao3Min.Value; Product.DoDao4Max = txtDoDao4Max.Value; Product.DoDao4Min = txtDoDao4Min.Value; Product.LuongMo1Max = txtLuongMo1Max.Value; //Mỡ cho trục tốc độ thấp Product.LuongMo1Min = txtLuongMo1Min.Value; // Product.LuongMo2Max = txtLuongMo2Max.Value; //Lượng mỡ cho hộp Product.LuongMo2Min = txtLuongMo2Min.Value; // Product.LuongMo3Max = txtLuongMo3Max.Value; //Mỡ cho vòng bi chịu tải & Carrier SSS Product.LuongMo3Min = txtLuongMo3Min.Value; // Product.LuongMo4Max = txtLuongMo4Max.Value; //Lượng mỡ cho vòng bi không tải Product.LuongMo4Min = txtLuongMo4Min.Value; // Product.LuongMo5Max = txtLuongMo5Max.Value; //Mỡ cho Carrier Product.LuongMo5Min = txtLuongMo5Min.Value; // Product.LuongMo6Max = txtLuongMo6Max.Value; //Mỡ cho hộp (Gram) ở công đoạn 3, số thứ tự 50 của 511,512 Product.LuongMo6Min = txtLuongMo6Min.Value; // Product.LuongMo7Max = txtLuongMo7Max.Value; // Product.LuongMo7Min = txtLuongMo7Min.Value; // Product.Goal = txtGoal.Text.Trim(); if (Product.ID > 0) { WorkingBO.Instance.Update(Product); } else { Product.ID = (int)WorkingBO.Instance.Insert(Product); //Sinh các công đoạn và mục kiểm tra của sản phẩm theo định dạng của nhóm sản phẩm TextUtils.ExcuteSQL(string.Format("EXEC dbo.CreateProductWorking_ByGroupID {0},{1}", Product.ProductGroupID, Product.ID)); } /* * Cập nhật lại các mục check sản phẩm theo các rule quy định của các công đoạn */ //TextUtils.ExcuteSQL(string.Format("EXEC spUpdateProductWorking_ByProductID {0},{1}", Product.ID, Product.MURATA == "3" ? 0 : 1)); TextUtils.ExcuteSQL(string.Format("EXEC spUpdateProductWorking_ByProductID_New {0},{1}", Product.ID, Product.MURATA == "3" ? 0 : 1)); return(true); }
void loadDataOld() { string fcmCode = TextUtils.ToString(cboFCM.EditValue); txtTotalVT.EditValue = LibQLSX.ExcuteScalar("select sum(isnull(TotalBuy,0) * isnull(Price,0)) FROM [vRequirePartFull_Order] where ProjectCode = '" + fcmCode + "' and isnull([OrderCode],'')<>''"); int year = TextUtils.ToInt(cboYear.SelectedItem); //int month = cboMonth.SelectedIndex; DataTable dtLaiVay = loadLaiVay(fcmCode); string sqlStart = "SELECT a.PK_ID, a.C_MA, a.C_MOTA, a.[GroupCode] +'-'+ a.[GroupName] as [GroupCode]"; string sqlEnd = " FROM V_DM_KMP a where isnull([FK_GROUP],0) > 0"; string sql = ",[C_Value] = isnull((select sum([C_PRICE]) from [V_DM_FCM_DETAIL] where [C_CODE] like '" + fcmCode + "%' and [C_KMP_MA] = a.C_MA),0)"; DataTable dtMonth = LibIE.Select("select distinct [C_Month] from [V_XNTC_REPORT_ALL] where [C_DTCP_MA] like '" + fcmCode + "%' and [C_YEAR] = " + year); sql += " ,[Total_NamTruoc] = isnull((SELECT sum([C_PSNO]) FROM [V_XNTC_REPORT_ALL]" + " where [C_DTCP_MA] = '" + fcmCode + "' " + " and (FK_TKNO like '154%' or FK_TKNO like '6321%' or FK_TKNO like '642%' or FK_TKNO like '521%' or FK_TKNO like '635%')" + " and [C_KMP_MA] = a.C_MA " + " and [C_Year] < " + year + "),0)"; string exp = "Total_NamTruoc"; foreach (DataRow row in dtMonth.Rows) { string p = TextUtils.ToString(row["C_Month"]); sql += " ,[T_" + p + "] = isnull((SELECT sum([C_PSNO]) FROM [V_XNTC_REPORT_ALL]" + " where [C_DTCP_MA] like '" + fcmCode + "%'" + " and (FK_TKNO like '154%' or FK_TKNO like '6321%' or FK_TKNO like '642%' or FK_TKNO like '521%' or FK_TKNO like '635%')" + " and [C_KMP_MA] = a.C_MA " + " and [C_Year] = " + year + " and [C_Month] = " + p + "),0) "; exp += "+ T_" + p; } string str = sqlStart + sql + sqlEnd; DataTable dtData = LibIE.Select(str); #region Nhập chi phí vật tư thực tế của dự án DataRow[] drsVT = dtData.Select("C_MA = 'C27' or C_MA = 'C20' or C_MA = 'C24' or C_MA = 'C22'"); foreach (DataRow r in drsVT) { string kmpCode = TextUtils.ToString(r["C_MA"]); foreach (DataRow row in dtMonth.Rows) { string p = TextUtils.ToString(row["C_Month"]); string sql1 = "SELECT sum([C_PSNO]) FROM [V_XNTC_REPORT_ALL]" + " where [C_DTCP_MA] like '" + fcmCode + "%' " + " and (FK_TKNO like '154%' or FK_TKNO like '6321%' or FK_TKNO like '642%' or FK_TKNO like '521%' or FK_TKNO like '635%')" + " and [C_KMP_MA] = '" + kmpCode + "'" + " and [C_Year] = " + year + " and [C_Month] = " + p; string sql2 = "SELECT sum([C_PSNO]) FROM [V_XNTC_REPORT_ALL]" + " where [C_DTCP_MA_LUU] like '" + fcmCode + "%' " + " and (FK_TKNO = '154' AND FK_TKNO = '154')" //+ " and [C_KMP_MA] = '" + kmpCode + "'" + " and [C_Year] = " + year + " and [C_Month] = " + p; r["T_" + p] = TextUtils.ToDecimal(LibIE.ExcuteScalar(sql1)) + TextUtils.ToDecimal(LibIE.ExcuteScalar(sql2)); } } #endregion #region Nhập chi phí lãi vay thực tế của dự án DataRow[] drsLaiVay = dtData.Select("C_MA = 'C11'"); foreach (DataRow r in drsLaiVay) { string kmpCode = TextUtils.ToString(r["C_MA"]); foreach (DataRow row in dtMonth.Rows) { int p = TextUtils.ToInt(row["C_Month"]); decimal cLai = TextUtils.ToDecimal(dtLaiVay.Compute("SUM(LaiGop)", "C_Month = " + p + " and C_Year = " + year)); r["T_" + p] = cLai; } } #endregion DataColumnCollection columns = dtData.Columns; DataTable dtFCM = LibIE.Select("select top 1 * from T_DM_FCM where C_CODE = '" + fcmCode + "'"); if (dtFCM.Rows.Count > 0) { #region Add column DataRow dr1 = dtData.NewRow(); dr1["PK_ID"] = 0; dr1["C_MA"] = "T1"; dr1["C_MOTA"] = "DT.Giá bán trên HĐ"; dr1["GroupCode"] = ""; dr1["C_Value"] = TextUtils.ToDecimal(dtFCM.Rows[0]["TotalHD"]); if (columns.Contains("Total_NamTruoc")) { dr1["Total_NamTruoc"] = 0; } dtData.Rows.Add(dr1); DataRow dr2 = dtData.NewRow(); dr2["PK_ID"] = 0; dr2["C_MA"] = "T2"; dr2["C_MOTA"] = "DT.Giá bán theo quy định TPA"; dr2["GroupCode"] = ""; dr2["C_Value"] = TextUtils.ToDecimal(dtFCM.Rows[0]["TotalTPA"]); if (columns.Contains("Total_NamTruoc")) { dr2["Total_NamTruoc"] = 0; } dtData.Rows.Add(dr2); DataRow dr3 = dtData.NewRow(); dr3["PK_ID"] = 0; dr3["C_MA"] = "T3"; dr3["C_MOTA"] = "DT.Thuế GTGT"; dr3["GroupCode"] = ""; dr3["C_Value"] = TextUtils.ToDecimal(dtFCM.Rows[0]["TotalVAT"]); if (columns.Contains("Total_NamTruoc")) { dr3["Total_NamTruoc"] = 0; } dtData.Rows.Add(dr3); DataRow dr4 = dtData.NewRow(); dr4["PK_ID"] = 0; dr4["C_MA"] = "T4"; dr4["C_MOTA"] = "DT.Giá thực thu"; dr4["GroupCode"] = ""; dr4["C_Value"] = TextUtils.ToDecimal(dtFCM.Rows[0]["TotalReal"]); if (columns.Contains("Total_NamTruoc")) { dr4["Total_NamTruoc"] = 0; } dtData.Rows.Add(dr4); DataRow dr5 = dtData.NewRow(); dr5["PK_ID"] = 0; dr5["C_MA"] = "T5"; dr5["C_MOTA"] = "DT.Tổng chi phí triển khai DA tại Khách Hàng"; dr5["GroupCode"] = ""; dr5["C_Value"] = TextUtils.ToDecimal(dtFCM.Rows[0]["TotalTrienKhai"]); if (columns.Contains("Total_NamTruoc")) { dr5["Total_NamTruoc"] = 0; } dtData.Rows.Add(dr5); DataRow dr6 = dtData.NewRow(); dr6["PK_ID"] = 0; dr6["C_MA"] = "T6"; dr6["C_MOTA"] = "DT.Tổng chi phí nhân công trực tiếp"; dr6["GroupCode"] = ""; dr6["C_Value"] = TextUtils.ToDecimal(dtFCM.Rows[0]["TotalNC"]); if (columns.Contains("Total_NamTruoc")) { dr6["Total_NamTruoc"] = 0; } dtData.Rows.Add(dr6); DataRow dr7 = dtData.NewRow(); dr7["PK_ID"] = 0; dr7["C_MA"] = "T7"; dr7["C_MOTA"] = "DT.Tổng chi phí quản lí phân bổ"; dr7["GroupCode"] = ""; dr7["C_Value"] = TextUtils.ToDecimal(dtFCM.Rows[0]["TotalPB"]); if (columns.Contains("Total_NamTruoc")) { dr7["Total_NamTruoc"] = 0; } dtData.Rows.Add(dr7); DataRow dr8 = dtData.NewRow(); dr8["PK_ID"] = 0; dr8["C_MA"] = "T8"; dr8["C_MOTA"] = "DT.Chi phí bổ xung"; dr8["GroupCode"] = ""; dr8["C_Value"] = TextUtils.ToDecimal(dtFCM.Rows[0]["TotalBX"]); if (columns.Contains("Total_NamTruoc")) { dr8["Total_NamTruoc"] = 0; } dtData.Rows.Add(dr8); DataRow dr9 = dtData.NewRow(); dr9["PK_ID"] = 0; dr9["C_MA"] = "T9"; dr9["C_MOTA"] = "DT.Loi Nhuan"; dr9["GroupCode"] = ""; dr9["C_Value"] = TextUtils.ToDecimal(dtFCM.Rows[0]["TotalProfit"]); if (columns.Contains("Total_NamTruoc")) { dr9["Total_NamTruoc"] = 0; } dtData.Rows.Add(dr9); #endregion } DataRow[] drsTong = dtData.Select("C_MA like 'T%'", "C_MA ASC"); #region Update Tổng foreach (DataRow r in drsTong) { foreach (DataRow row in dtMonth.Rows) { string p = TextUtils.ToString(row["C_Month"]); decimal totalTrienKhai = 0; decimal totalPB = 0; decimal totalReal = 0; if (TextUtils.ToString(r["C_MA"]) == "T4") { string sql1 = "SELECT sum([C_PSNO]) FROM [V_XNTC_REPORT_ALL]" + " where [C_DTCP_MA] like '%" + fcmCode + "%' " + " and (FK_TKCO like '511%')" //+ " and [C_KMP_MA] in ('C13','C52','C03','C38','C39','C40','C43','C04','C41','C42','C46','C05','C44','C45')" + " and [C_Year] = " + year + " and [C_Month] = " + p; string sql2 = "SELECT sum([C_PSNO]) FROM [V_XNTC_REPORT_ALL]" + " where [C_DTCP_MA] like '%" + fcmCode + "%' " + " and (FK_TKNO like '521%')" //+ " and [C_KMP_MA] in ('C13','C52','C03','C38','C39','C40','C43','C04','C41','C42','C46','C05','C44','C45')" + " and [C_Year] = " + year + " and [C_Month] = " + p; r["T_" + p] = totalReal = TextUtils.ToDecimal(LibIE.ExcuteScalar(sql1)) - TextUtils.ToDecimal(LibIE.ExcuteScalar(sql2)); } else if (TextUtils.ToString(r["C_MA"]) == "T5") { string sql1 = "SELECT sum([C_PSNO]) FROM [V_XNTC_REPORT_ALL]" + " where [C_DTCP_MA] like '%" + fcmCode + "%' " + " and (FK_TKNO like '154%' or FK_TKNO like '6321%' or FK_TKNO like '642%' or FK_TKNO like '521%' or FK_TKNO like '635%')" + " and [C_KMP_MA] in ('C13','C52','C03','C38','C39','C40','C43','C04','C41','C42','C46','C05','C44','C45')" + " and [C_Year] = " + year + " and [C_Month] = " + p; r["T_" + p] = totalTrienKhai = TextUtils.ToDecimal(LibIE.ExcuteScalar(sql1)); } else if (TextUtils.ToString(r["C_MA"]) == "T7") { string sql1 = "SELECT sum([C_PSNO]) FROM [V_XNTC_REPORT_ALL]" + " where [C_DTCP_MA] like '%" + fcmCode + "%' " + " and (FK_TKNO like '154%' or FK_TKNO like '6321%' or FK_TKNO like '642%' or FK_TKNO like '521%' or FK_TKNO like '635%')" + " and [C_KMP_MA] in ('C09P01','C09P03','C09P05','C09P06','C09P08','C09P09','C09P13','C09P14','C09P16','C09P20','C09P23'" + ",'C07','C12','C01','C06','C02','C17','C16','C32','C51','C47','C48'," + "'C50','C54','C55','C57','C10','C23','C25','C26','C11','C19','C31','C30','C53','C29','C33')" + " and [C_Year] = " + year + " and [C_Month] = " + p; r["T_" + p] = totalPB = TextUtils.ToDecimal(LibIE.ExcuteScalar(sql1)); } else if (TextUtils.ToString(r["C_MA"]) == "T9") { string sqlReal1 = "SELECT sum([C_PSNO]) FROM [V_XNTC_REPORT_ALL]" + " where [C_DTCP_MA] like '%" + fcmCode + "%' " + " and (FK_TKCO like '511%')" //+ " and [C_KMP_MA] in ('C13','C52','C03','C38','C39','C40','C43','C04','C41','C42','C46','C05','C44','C45')" + " and [C_Year] = " + year + " and [C_Month] = " + p; string sqlReal2 = "SELECT sum([C_PSNO]) FROM [V_XNTC_REPORT_ALL]" + " where [C_DTCP_MA] like '%" + fcmCode + "%' " + " and (FK_TKNO like '521%')" //+ " and [C_KMP_MA] in ('C13','C52','C03','C38','C39','C40','C43','C04','C41','C42','C46','C05','C44','C45')" + " and [C_Year] = " + year + " and [C_Month] = " + p; string sqlTrienKhai = "SELECT sum([C_PSNO]) FROM [V_XNTC_REPORT_ALL]" + " where [C_DTCP_MA] like '%" + fcmCode + "%' " + " and (FK_TKNO like '154%' or FK_TKNO like '6321%' or FK_TKNO like '642%' or FK_TKNO like '521%' or FK_TKNO like '635%')" + " and [C_KMP_MA] in ('C13','C52','C03','C38','C39','C40','C43','C04','C41','C42','C46','C05','C44','C45')" + " and [C_Year] = " + year + " and [C_Month] = " + p; string sqlPB = "SELECT sum([C_PSNO]) FROM [V_XNTC_REPORT_ALL]" + " where [C_DTCP_MA] like '%" + fcmCode + "%' " + " and (FK_TKNO like '154%' or FK_TKNO like '6321%' or FK_TKNO like '642%' or FK_TKNO like '521%' or FK_TKNO like '635%')" + " and [C_KMP_MA] in ('C09P01','C09P03','C09P05','C09P06','C09P08','C09P09','C09P13','C09P14','C09P16','C09P20','C09P23'" + ",'C07','C12','C01','C06','C02','C17','C16','C32','C51','C47','C48'," + "'C50','C54','C55','C57','C10','C23','C25','C26','C11','C19','C31','C30','C53','C29','C33')" + " and [C_Year] = " + year + " and [C_Month] = " + p; string sqlNhanCong = "SELECT sum([C_PSNO]) FROM [V_XNTC_REPORT_ALL]" + " where [C_DTCP_MA] like '%" + fcmCode + "%' " + " and (FK_TKNO like '154%' or FK_TKNO like '6321%' or FK_TKNO like '642%' or FK_TKNO like '521%' or FK_TKNO like '635%')" + " and [C_KMP_MA] in ('C09','C09P01','C09P07','C09P10','C09P11','C09P12','C09P17','C15','C34','C35','C36')" + " and [C_Year] = " + year + " and [C_Month] = " + p; string sqlVT = "SELECT sum([C_PSNO]) FROM [V_XNTC_REPORT_ALL]" + " where [C_DTCP_MA] like '%" + fcmCode + "%' " + " and (FK_TKNO like '154%' or FK_TKNO like '6321%' or FK_TKNO like '642%' or FK_TKNO like '521%' or FK_TKNO like '635%')" + " and [C_KMP_MA] in ('C27','C20','C24','C22')" + " and [C_Year] = " + year + " and [C_Month] = " + p; decimal totalLoiNhuan = TextUtils.ToDecimal(LibIE.ExcuteScalar(sqlReal1)) - TextUtils.ToDecimal(LibIE.ExcuteScalar(sqlReal2)) - TextUtils.ToDecimal(LibIE.ExcuteScalar(sqlNhanCong)) - TextUtils.ToDecimal(LibIE.ExcuteScalar(sqlPB)) - TextUtils.ToDecimal(LibIE.ExcuteScalar(sqlTrienKhai)) - 0 - TextUtils.ToDecimal(LibIE.ExcuteScalar(sqlVT)); r["T_" + p] = totalLoiNhuan; } else { r["T_" + p] = 0; } } } #endregion dtData.Columns.Add("LuyKe", typeof(decimal), exp); dtData.Columns.Add("ChenhLech", typeof(decimal), "C_Value - (" + exp + ")"); dtData.Columns["PK_ID"].Caption = "PK_ID"; dtData.Columns["C_MA"].Caption = "Mã"; dtData.Columns["C_MOTA"].Caption = "Tên"; dtData.Columns["GroupCode"].Caption = "Nhóm"; dtData.Columns["C_Value"].Caption = "Tổng tiền"; dtData.Columns["Total_NamTruoc"].Caption = "Năm trước"; dtData.Columns["LuyKe"].Caption = "Lũy kế"; dtData.Columns["ChenhLech"].Caption = "Chênh lệch (DK-TT)"; grvData.PopulateColumns(dtData); grdData.DataSource = dtData; grvData.Columns[0].Visible = false; //grvData.Columns[3].GroupIndex = 0; grvData.Columns[3].Visible = false; grvData.Columns[4].Visible = false; for (int i = 5; i < dtData.Columns.Count; i++) { grvData.Columns[i].DisplayFormat.FormatType = FormatType.Numeric; grvData.Columns[i].DisplayFormat.FormatString = "n0"; } grvData.BestFitColumns(); grvData.ExpandAllGroups(); grvData.Columns[1].Fixed = FixedStyle.Left; grvData.Columns[2].Fixed = FixedStyle.Left; grvData.Columns[3].Fixed = FixedStyle.Left; grvData.Columns[4].Fixed = FixedStyle.Left; grvData.Columns["LuyKe"].AppearanceCell.BackColor = Color.Yellow; grvData.Columns["ChenhLech"].AppearanceCell.BackColor = Color.YellowGreen; }
void Save() { //ProcessTransaction pt = new ProcessTransaction(); //pt.OpenConnection(); //pt.BeginTransaction(); using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát", "Đang tạo thông số vật tư")) { try { string parentGroupCode = Path.GetFileNameWithoutExtension(btnBrowse.Text); ArrayList listGroup = MaterialGroupBO.Instance.FindByAttribute("Code", parentGroupCode); MaterialGroupModel parentGroup = (MaterialGroupModel)listGroup[0]; string currentGroup = "TPAVT." + cboSheet.SelectedValue.ToString().Split('-')[0].Trim(); #region Material Group MaterialGroupModel thisGroup; if (!MaterialGroupBO.Instance.CheckExist("Code", currentGroup)) { thisGroup = new MaterialGroupModel(); thisGroup.Code = currentGroup; thisGroup.Name = cboSheet.SelectedValue.ToString().Split('-')[1].Trim(); thisGroup.CreatedDate = TextUtils.GetSystemDate(); thisGroup.CreatedBy = Global.AppUserName; thisGroup.UpdatedDate = thisGroup.CreatedDate; thisGroup.UpdatedBy = Global.AppUserName; //thisGroup.ID = (int)pt.Insert(thisGroup); thisGroup.ID = (int)MaterialGroupBO.Instance.Insert(thisGroup); } else { thisGroup = (MaterialGroupModel)MaterialGroupBO.Instance.FindByAttribute("Code", currentGroup)[0]; } #endregion Material Group //List<MaterialParameterValueModel> listTemParaValue = new List<MaterialParameterValueModel>(); for (int i = 0; i < grvData.RowCount; i++) { if (i == 0) { for (int j = 4; j < grvData.Columns.Count; j++) { #region Thêm thông số kỹ thuật if (grvData.GetRowCellValue(i, "F" + (j + 1)) == null) { continue; } string thisNameTS = grvData.GetRowCellValue(i, "F" + (j + 1)).ToString().Trim(); if (thisNameTS == "") { continue; } DataTable dtTS = TextUtils.Select(string.Format("Select * from MaterialParameters with(nolock) where Name=N'{0}' and MaterialGroupID ={1}", thisNameTS, thisGroup.ID)); MaterialParametersModel modelTSVT = null; if (dtTS.Rows.Count == 0) { modelTSVT = new MaterialParametersModel(); modelTSVT.Name = thisNameTS; modelTSVT.MaterialGroupID = thisGroup.ID; //modelTSVT.ID = (int)pt.Insert(modelTSVT); modelTSVT.ID = (int)MaterialParametersBO.Instance.Insert(modelTSVT); } #endregion Thông số kỹ thuật } } else { if (grvData.GetRowCellValue(i, "F2") == null) { continue; } string materialCode = grvData.GetRowCellValue(i, "F2").ToString().Trim(); if (materialCode == "") { continue; } #region Check Customer string customerCode = grvData.GetRowCellValue(i, "F4").ToString().Trim(); CustomerModel thisCustomer = null; if (!CustomerBO.Instance.CheckExist("Code", customerCode)) { thisCustomer = new CustomerModel(); thisCustomer.Code = customerCode.ToUpper(); thisCustomer.Name = customerCode.ToUpper(); //thisCustomer.ID = (int)pt.Insert(thisCustomer); thisCustomer.ID = (int)CustomerBO.Instance.Insert(thisCustomer); if (!DocUtils.CheckExits("Datasheet" + "/" + customerCode.ToUpper())) { DocUtils.MakeDir("Datasheet" + "/" + customerCode.ToUpper()); } } else { thisCustomer = (CustomerModel)CustomerBO.Instance.FindByAttribute("Code", customerCode)[0]; } #endregion Check Customer #region Check Material MaterialModel thisMaterial; string materialName = grvData.GetRowCellValue(i, "F3").ToString().Trim(); if (!MaterialBO.Instance.CheckExist("Code", materialCode)) { thisMaterial = new MaterialModel(); thisMaterial.Code = materialCode; thisMaterial.Name = materialName; thisMaterial.CustomerID = thisCustomer.ID; thisMaterial.MaterialGroupID = thisGroup.ID; //thisMaterial.ID = (int)pt.Insert(thisMaterial); thisMaterial.ID = (int)MaterialBO.Instance.Insert(thisMaterial); } else { thisMaterial = (MaterialModel)MaterialBO.Instance.FindByAttribute("Code", materialCode)[0]; } #endregion Check Material for (int j = 4; j < grvData.Columns.Count; j++) { if (grvData.GetRowCellValue(i, "F" + (j + 1)) == null) { continue; } string thisTSName = grvData.GetRowCellValue(0, "F" + (j + 1)).ToString().Trim(); if (thisTSName == "") { continue; } //MaterialParametersModel modelTSVT = (MaterialParametersModel)MaterialParametersBO.Instance. // FindByExpression(new Expression("Name", thisTSName).And(new Expression("MaterialGroupID", thisGroup.ID)))[0]; DataTable dtTSKT = TextUtils.Select(string.Format("select * from MaterialParameters where Name = N'{0}' and MaterialGroupID = {1}", thisTSName, thisGroup.ID)); if (dtTSKT.Rows.Count == 0) { continue; } #region MaterialParameterLink MaterialParameterLinkModel link = null; DataTable dtlink = TextUtils.Select(string. Format("Select * from MaterialParameterLink with(nolock) where MaterialParameterID={0} and MaterialID ={1}", TextUtils.ToInt(dtTSKT.Rows[0]["ID"]), thisMaterial.ID)); if (dtlink.Rows.Count == 0) { link = new MaterialParameterLinkModel(); link.MaterialID = thisMaterial.ID; link.MaterialParameterID = TextUtils.ToInt(dtTSKT.Rows[0]["ID"]);//modelTSVT.ID; //link.ID = (int)pt.Insert(link); link.ID = (int)MaterialParameterLinkBO.Instance.Insert(link); } else { //link = (MaterialParameterLinkModel)MaterialParameterLinkBO.Instance.FindByPK(TextUtils.ToInt(dtlink.Rows[0]["ID"])); } #endregion MaterialParameterLink string value = grvData.GetRowCellValue(i, "F" + (j + 1)) == null ? "" : grvData.GetRowCellValue(i, "F" + (j + 1)).ToString().Trim(); value = value.Trim().Replace("\n", ",").Replace("_", "-"); if (value != "") { #region MaterialParameterValue MaterialParameterValueModel paraValue = null; DataTable dtParameterValue = TextUtils.Select(string. Format("Select * from MaterialParameterValue with(nolock) where MaterialParameterID={0} and REPLACE(ParaValue,' ','') =N'{1}'", TextUtils.ToInt(dtTSKT.Rows[0]["ID"]), value.Replace(" ", ""))); if (dtParameterValue.Rows.Count == 0) { paraValue = new MaterialParameterValueModel(); paraValue.MaterialParameterID = TextUtils.ToInt(dtTSKT.Rows[0]["ID"]);//modelTSVT.ID; paraValue.ParaValue = value; //paraValue.ID = (int)pt.Insert(paraValue); paraValue.ID = (int)MaterialParameterValueBO.Instance.Insert(paraValue); } else { paraValue = (MaterialParameterValueModel)MaterialParameterValueBO.Instance.FindByPK(TextUtils.ToInt(dtParameterValue.Rows[0]["ID"])); } #endregion MaterialParameterValue #region MaterialConnect MaterialConnectModel connect = null; DataTable dtConnect = TextUtils.Select(string. Format("Select * from MaterialConnect with(nolock) where MaterialParameterID={0} and MaterialID ={1} and MaterialParameterValueID={2}", TextUtils.ToInt(dtTSKT.Rows[0]["ID"]), thisMaterial.ID, paraValue.ID)); if (dtConnect.Rows.Count == 0) { connect = new MaterialConnectModel(); connect.MaterialParameterID = TextUtils.ToInt(dtTSKT.Rows[0]["ID"]);//modelTSVT.ID; connect.MaterialID = thisMaterial.ID; connect.MaterialParameterValueID = paraValue.ID; //connect.ID = (int)pt.Insert(connect); connect.ID = (int)MaterialConnectBO.Instance.Insert(connect); } #endregion MaterialConnect } } } } //pt.CommitTransaction(); MessageBox.Show("Thành công!"); } catch (Exception ex) { MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); } finally { //pt.CloseConnection(); } } }
private void treeData_KeyDown(object sender, KeyEventArgs e) { if (treeData.FocusedNode == null) { return; } if (e.KeyCode == Keys.Delete) { if (Quotation.IsApproved) { return; } try { string moduleCode = TextUtils.ToString(treeData.FocusedNode.GetValue(colModuleCode)); int id = TextUtils.ToInt(treeData.FocusedNode.GetValue(colDetailID)); if (C_QuotationDetail_SXBO.Instance.CheckExist("ParentID", id)) { MessageBox.Show("Bạn không thể xóa được thiết bị chính khi nó còn chứa các thiết bị con.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (MessageBox.Show("Bạn có chắc muốn xóa thiết bị [" + moduleCode + "]?", TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { C_QuotationDetail_SXModel item = (C_QuotationDetail_SXModel)C_QuotationDetail_SXBO.Instance.FindByPK(id); if (item.ParentID > 0) { C_QuotationDetail_SXModel itemP = (C_QuotationDetail_SXModel)C_QuotationDetail_SXBO.Instance.FindByPK(item.ParentID); itemP.PriceVT -= item.PriceVT; itemP.PriceVTLD -= item.PriceVTLD; itemP.PriceVTPS -= item.PriceVTPS; itemP.PriceVTTN -= item.PriceVTTN; //itemP.PriceVT -= item.PriceVT; itemP.PriceHD -= item.PriceHD; C_QuotationDetail_SXBO.Instance.Update(itemP); } C_CostQuotationItemLinkNewBO.Instance.DeleteByAttribute("C_QuotationDetail_SXID", id); C_QuotationDetail_SXBO.Instance.Delete(id); treeData.DeleteSelectedNodes(); if (item.ParentID == 0) { loadProduct(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (e.KeyCode == (Keys.C)) { try { string text = TextUtils.ToString(treeData.FocusedNode.GetValue(treeData.FocusedColumn)); Clipboard.SetText(text); } catch (Exception) { } } }
void calculateCost(C_QuotationDetail_SXModel item) { int costID = (Quotation.DepartmentId == "D018" ? 73 : 72);//Phòng KD1->lấy ra chi phí nhân công KD2 không thì lấy chi phí nhân công KD1 if (item.C_ProductGroupID == 0) { C_CostQuotationItemLinkNewBO.Instance.DeleteByAttribute("C_QuotationDetail_SXID", item.ID); item.TotalNC = 0; item.TotalPB = 0; C_QuotationDetail_SXBO.Instance.Update(item); } else { ArrayList arr = C_CostBO.Instance.FindByExpression(new Expression("IsUse", 1).And(new Expression("IsWithProject", 0))); DataTable dtCostProductGroup = LibQLSX.Select("select * from vC_CostProductGroupLinkNew where [C_ProductGroupID] = " + item.C_ProductGroupID); decimal totalNC = 0; decimal totalPB = 0; foreach (var c in arr) { C_CostModel cost = (C_CostModel)c; DataRow[] drs = dtCostProductGroup.Select("C_CostID = " + cost.ID); if (drs.Length == 0) { continue; } C_CostQuotationItemLinkNewModel link = new C_CostQuotationItemLinkNewModel(); ArrayList arrLink = C_CostQuotationItemLinkNewBO.Instance.FindByExpression(new Expression("C_CostID", cost.ID).And(new Expression("C_QuotationDetail_SXID", item.ID))); if (arrLink != null && arrLink.Count > 0) { link = (C_CostQuotationItemLinkNewModel)arrLink[0]; } link.C_CostID = cost.ID; link.C_QuotationDetail_SXID = item.ID; link.IsDirect = cost.IsDirectCost; if (link.IsDirect == 1) { #region Chi phí nhân công if (link.ID == 0) { if (cost.Price == 0) { link.Price = 0; } else { link.PersonNumber = TextUtils.ToDecimal(drs[0]["PersonNumber"]); int isFix = TextUtils.ToInt(drs[0]["IsFix"]); if (isFix == 1) { link.NumberDay = TextUtils.ToDecimal(drs[0]["NumberDay"]); } else { link.NumberDay = TextUtils.ToDecimal(drs[0]["VtuPercent"]) * item.PriceVT / cost.Price; } link.TotalR = link.NumberDay * link.PersonNumber; if (cost.ID == 61)//phòng thiết kế { link.TotalR = link.NumberDay * link.PersonNumber * (1 + 0.3M * (item.Qty - 1)) / item.Qty; //link.Price = (link.NumberDay * link.PersonNumber) * (1 + 0.3M * (item.Qty - 1)) / item.Qty * cost.Price; } link.Price = link.TotalR * cost.Price; } } totalNC += link.Price; #endregion } else { #region Chi phí phân bổ if (item.PriceHD > 0) { decimal valuePercent = TextUtils.ToDecimal(drs[0]["ValuePercentSX"]); link.Price = valuePercent / 100 * item.PriceTPA; if (link.C_CostID == costID) { link.Price = 0; } else { //link.Price = TextUtils.ToDecimal(row["ValuePercentSX"]) / 100 * item.PriceTPA; } } #endregion } if (link.ID == 0) { C_CostQuotationItemLinkNewBO.Instance.Insert(link); } else { C_CostQuotationItemLinkNewBO.Instance.Update(link); } item.TotalNC = totalNC; item.TotalPB = totalPB; C_QuotationDetail_SXBO.Instance.Update(item); } } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { txtRate.Text = ""; int rowCount = grvData.RowCount; // Bat dau duyet theo tung dong Excel for (int i = 0; i < rowCount; i++) { try { if (i < 1) { continue; // Form du lieu bat dau tu dong 1 } progressBar1.Invoke((Action)(() => { progressBar1.Value = i; })); txtRate.Invoke((Action)(() => { txtRate.Text = string.Format("{0}/{1}", i, rowCount - 1); })); string _partCode = TextUtils.ToString(grvData.GetRowCellValue(i, "F0")); //string _orderCode = TextUtils.ToString(grvData.GetRowCellValue(i, "F8")); // Kiem tra xem dong do' co du? thong tin hop le hay khong if (string.IsNullOrEmpty(_partCode)) { continue; } PartSonModel partSonModel = new PartSonModel(); #region Set value if (grvData.Columns.Count < 3) { partSonModel.PartCode = _partCode; partSonModel.QuantityExporting = 0; partSonModel.QuantityAssembling = 0; } else { partSonModel.PartCode = _partCode; partSonModel.QuantityExporting = TextUtils.ToInt(grvData.GetRowCellValue(i, "F1")); partSonModel.QuantityAssembling = TextUtils.ToInt(grvData.GetRowCellValue(i, "F2")); } #endregion // Kiem tra xem ma san pham/ma order da ton tai chua Expression exp1 = new Expression("PartCode", _partCode); ArrayList arr = PartSonBO.Instance.FindByExpression(exp1); if (arr.Count > 0) { if (grvData.Columns.Count < 3) { continue; } else { for (int j = 0; j < arr.Count; j++) { partSonModel.ID = (arr[j] as PartSonModel).ID; PartSonBO.Instance.Update(partSonModel); } } } else { partSonModel.ID = (int)PartSonBO.Instance.Insert(partSonModel); } } catch (Exception er) { MessageBox.Show("Lỗi lưu dữ liệu tại dòng " + i + Environment.NewLine + er.ToString()); } } }
private void btnAddModule_Click(object sender, EventArgs e) { #region Check if (txtModuleCode.Text.Trim() == "") { MessageBox.Show("Bạn phải thêm mã module!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (txtModuleName.Text.Trim() == "") { MessageBox.Show("Bạn phải thêm tên module!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (txtManufacture.Text.Trim() == "") { MessageBox.Show("Bạn phải thêm hãng!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (txtOrigin.Text.Trim() == "") { MessageBox.Show("Bạn phải thêm xuất xứ!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (TextUtils.ToDecimal(txtPriceVTSX.EditValue) == 0 && cboProduct.EditValue != null) { MessageBox.Show("Bạn phải điền giá vật tư sản xuất!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (TextUtils.ToDecimal(txtQtyT.EditValue) == 0) { MessageBox.Show("Bạn phải điền số lượng!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (cboProductGroup.EditValue == null && cboProduct.EditValue != null) { MessageBox.Show("Bạn phải chọn một nhóm sản phẩm!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } #endregion C_QuotationDetail_SXModel item = new C_QuotationDetail_SXModel(); item.C_QuotationID = Quotation.ID; item.ParentID = TextUtils.ToInt(cboProduct.EditValue); item.C_ProductGroupID = TextUtils.ToInt(cboProductGroup.EditValue); item.PriceVT = TextUtils.ToDecimal(txtPriceVTSX.EditValue); item.PriceVTLD = TextUtils.ToDecimal(txtPriceVTLD.EditValue); item.PriceVTPS = TextUtils.ToDecimal(txtPriceVTPS.EditValue); item.PriceVTTN = TextUtils.ToDecimal(txtPriceVTTN.EditValue); item.QtyT = TextUtils.ToDecimal(txtQtyT.EditValue); item.Manufacture = txtManufacture.Text.Trim(); item.ModuleCode = item.ModuleCodeHD = txtModuleCode.Text.Trim().ToUpper(); item.ModuleName = item.ModuleNameHD = txtModuleName.Text.Trim(); item.Origin = txtOrigin.Text.Trim(); item.VAT = TextUtils.ToDecimal(txtVAT.EditValue); if (item.ParentID > 0) { item.Qty = TextUtils.ToDecimal(txtQtyT.EditValue) * TextUtils.ToDecimal(grvCboProduct.GetFocusedRowCellValue(colPQty)); } else { item.Qty = item.QtyT = TextUtils.ToDecimal(txtQtyT.EditValue); } item.CreatedBy = item.UpdatedBy = Global.AppUserName; item.CreatedDate = item.UpdatedDate = DateTime.Now; item.ID = (int)C_QuotationDetail_SXBO.Instance.Insert(item); if (item.ParentID > 0) { C_QuotationDetail_SXModel itemP = (C_QuotationDetail_SXModel)C_QuotationDetail_SXBO.Instance.FindByPK(item.ParentID); itemP.C_ProductGroupID = 0; itemP.PriceVT += item.PriceVT; itemP.PriceVTLD += item.PriceVTLD; itemP.PriceVTPS += item.PriceVTPS; itemP.PriceVTTN += item.PriceVTTN; C_QuotationDetail_SXBO.Instance.Update(itemP); } MessageBox.Show("Lưu trữ thành công.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); loadProduct(); loadQuotationItem(); txtPriceVTSX.EditValue = 0; txtQtyT.EditValue = 1; txtModuleName.Text = txtModuleCode.Text = ""; }
private void btnExportFormBank_Click(object sender, EventArgs e) { bool isTrongNuoc = true; DialogResult result = MessageBox.Show("Bạn muốn xuất các biểu mẫu loại trong nước?", TextUtils.Caption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result == DialogResult.Yes) { isTrongNuoc = true; } else if (result == DialogResult.No) { isTrongNuoc = false; } else { return; } string filePath = ""; OpenFileDialog ofd = new OpenFileDialog(); ofd.Multiselect = false; if (ofd.ShowDialog() == DialogResult.OK) { filePath = ofd.FileName; } else { return; } DataTable dtItem = TextUtils.ExcelToDatatableNoHeader(filePath, "Sheet1"); for (int i = 0; i < 3; i++) { dtItem.Rows.RemoveAt(0); } DataTable dtDistinctItem = TextUtils.GetDistinctDatatable(dtItem, "F4"); string path = ""; FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { path = fbd.SelectedPath; } else { return; } using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang tạo mẫu lệnh chi...")) { #region Mẫu lệnh chi for (int i = 0; i < dtDistinctItem.Rows.Count; i++) //for (int i = 0; i < 1; i++) { string stt = TextUtils.ToString(dtDistinctItem.Rows[i]["F1"]); if (stt == "") { continue; } string filePathS = Application.StartupPath + "\\Templates\\PhongKeToan\\NganHang\\Mau lenh chi.xls"; string currentPath = path + "\\Mau lenh chi-" + TextUtils.ToString(dtDistinctItem.Rows[i]["F2"]) + ".xls"; try { File.Copy(filePathS, currentPath, true); } catch (Exception ex) { MessageBox.Show("Có lỗi khi tạo biểu mẫu lệnh chi!" + Environment.NewLine + ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); continue; } System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); Excel.Application app = default(Excel.Application); Excel.Workbook workBoook = default(Excel.Workbook); Excel.Worksheet workSheet = default(Excel.Worksheet); try { app = new Excel.Application(); app.Workbooks.Open(currentPath); workBoook = app.Workbooks[1]; workSheet = (Excel.Worksheet)workBoook.Worksheets[1]; string loaiTienTe = TextUtils.ToString(dtDistinctItem.Rows[i]["F13"]); string percentThanhToan = TextUtils.ToString(dtDistinctItem.Rows[i]["F14"]); string soTaiKhoan = TextUtils.ToString(dtDistinctItem.Rows[i]["F4"]); string soHoaDonHopDong = ""; double tienNhanNo = 0; DataRow[] drs = dtItem.Select("F4 = '" + soTaiKhoan + "'"); foreach (DataRow item in drs) { tienNhanNo += TextUtils.ToDouble(item["F9"]); soHoaDonHopDong += TextUtils.ToString(item["F5"]) + ","; } workSheet.Cells[7, 1] = " Số No………Ngày Date ……/" + string.Format("{0:00}", DateTime.Now.Month) + "/" + DateTime.Now.Year; workSheet.Cells[12, 3] = TextUtils.ToString(dtDistinctItem.Rows[i]["F2"]); //Bên thụ hưởng workSheet.Cells[15, 4] = TextUtils.ToString(dtDistinctItem.Rows[i]["F12"]); //địa chỉ bên thụ hưởng if (isTrongNuoc) { workSheet.Cells[13, 3] = "'" + soTaiKhoan; workSheet.Cells[16, 4] = tienNhanNo.ToString("n2") + " " + loaiTienTe; //Số tiền nhận nợ workSheet.Cells[17, 4] = TextUtils.NumericToString(tienNhanNo, loaiTienTe); //tiền nhận nợ bẳng chữ } workSheet.Cells[21, 3] = "Công ty cp tự động hóa Tân phát thanh toán " + tienNhanNo + " " + (loaiTienTe == "" ? "VNĐ" : loaiTienTe) + " tiền hợp đồng " + soHoaDonHopDong.Substring(0, soHoaDonHopDong.Length - 1); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (app != null) { app.ActiveWorkbook.Save(); app.Workbooks.Close(); app.Quit(); } } } #endregion Mẫu lệnh chi } using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang tạo Giấy nhận nợ...")) { #region Giấy nhận nợ Word.Application word = new Word.Application(); Word.Document doc = new Word.Document(); try { string localFilePath = ""; if (isTrongNuoc) { localFilePath = Application.StartupPath + "\\Templates\\PhongKeToan\\NganHang\\GiayNhanNo_VND.docx"; } else { localFilePath = Application.StartupPath + "\\Templates\\PhongKeToan\\NganHang\\GiayNhanNo_USD.docx"; } string currentFilePath = path + "\\GiayNhanNo-" + DateTime.Now.ToString("ddMMyyyy") + ".docx"; try { File.Copy(localFilePath, currentFilePath, true); } catch (Exception ex) { MessageBox.Show("Có lỗi khi tạo biểu Giấy nhận nợ!" + Environment.NewLine + ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } doc = word.Documents.Open(currentFilePath); doc.Activate(); decimal tong1 = 0; decimal tong2 = 0; for (int i = 0; i < dtItem.Rows.Count; i++) { int stt = TextUtils.ToInt(dtItem.Rows[i]["F1"]); decimal tienHoaDon = TextUtils.ToDecimal(dtItem.Rows[i]["F8"]); decimal tienNhanNo = TextUtils.ToDecimal(dtItem.Rows[i]["F9"]); string loaiTienTe = TextUtils.ToString(dtItem.Rows[i]["F13"]); tong1 += tienHoaDon; tong2 += tienNhanNo; TextUtils.RepalaceText(doc, "<thuHuong" + stt + ">", TextUtils.ToString(dtItem.Rows[i]["F2"])); TextUtils.RepalaceText(doc, "<nganHang" + stt + ">", TextUtils.ToString(dtItem.Rows[i]["F3"])); TextUtils.RepalaceText(doc, "<soTaiKhoan" + stt + ">", TextUtils.ToString(dtItem.Rows[i]["F4"])); TextUtils.RepalaceText(doc, "<soHoaDon" + stt + ">", TextUtils.ToString(dtItem.Rows[i]["F5"])); //TextUtils.RepalaceText(doc, "<ngay" + stt + ">", TextUtils.ToDate3(dtItem.Rows[i]["F6"]).ToString("dd/MM/yyyy")); TextUtils.RepalaceText(doc, "<ngay" + stt + ">", TextUtils.ToString(dtItem.Rows[i]["F6"])); TextUtils.RepalaceText(doc, "<matHang" + stt + ">", TextUtils.ToString(dtItem.Rows[i]["F7"])); TextUtils.RepalaceText(doc, "<tienHoaDon" + stt + ">", tienHoaDon.ToString("n2")); TextUtils.RepalaceText(doc, "<tienNhanNo" + stt + ">", tienNhanNo.ToString("n2")); } TextUtils.RepalaceText(doc, "<tong1>", tong1.ToString("n2")); TextUtils.RepalaceText(doc, "<tong2>", tong2.ToString("n2")); TextUtils.RepalaceText(doc, "<bangchu>", TextUtils.NumericToString((double)tong2, isTrongNuoc ? "" : "USD")); TextUtils.RepalaceText(doc, "<month>", string.Format("{0:00}", DateTime.Now.Month)); TextUtils.RepalaceText(doc, "<year>", DateTime.Now.Year.ToString()); doc.Save(); doc.Close(); word.Quit(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Tân Phát", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { TextUtils.ReleaseComObject(doc); TextUtils.ReleaseComObject(word); } #endregion Giấy nhận nợ } if (isTrongNuoc) { return; } using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang tạo Hợp đồng ngoại tệ...")) { #region Hợp đồng ngoại tệ Word.Application word = new Word.Application(); Word.Document doc = new Word.Document(); try { string localFilePath = Application.StartupPath + "\\Templates\\PhongKeToan\\NganHang\\HopDongMuaBanNgoaiTe.docx"; string currentFilePath = path + "\\HopDongMuaBanNgoaiTe-" + DateTime.Now.ToString("ddMMyyyy") + ".docx"; try { File.Copy(localFilePath, currentFilePath, true); } catch (Exception ex) { MessageBox.Show("Có lỗi khi tạo biểu Hợp đồng mua bán ngoại tệ!" + Environment.NewLine + ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } doc = word.Documents.Open(currentFilePath); doc.Activate(); for (int i = 0; i < dtDistinctItem.Rows.Count; i++) { int f1 = TextUtils.ToInt(dtDistinctItem.Rows[i]["F1"]); if (f1 == 0) { continue; } int stt = f1; //i + 1; string loaiTienTe = TextUtils.ToString(dtDistinctItem.Rows[i]["F13"]); string soTaiKhoan = TextUtils.ToString(dtDistinctItem.Rows[i]["F4"]); double tienNhanNo = 0; string noiDung = ""; DataRow[] drs = dtItem.Select("F4 = '" + soTaiKhoan + "'"); if (drs.Length > 1) { foreach (DataRow item in drs) { tienNhanNo += TextUtils.ToDouble(item["F9"]); string soHoaDonHopDong = TextUtils.ToString(item["F5"]); string ngay = TextUtils.ToDate3(item["F6"]).ToString("dd/MM/yyyy"); string percentThanhToan = TextUtils.ToString(item["F14"]); if (percentThanhToan != "") { noiDung += "Thanh toán trả trước nốt " + percentThanhToan + "% hợp đồng số " + soHoaDonHopDong + " ngày " + ngay + Environment.NewLine; } else { noiDung += "Thanh toán tiền hàng hợp đồng số " + soHoaDonHopDong + " ngày " + ngay + Environment.NewLine; } } } else { tienNhanNo = TextUtils.ToDouble(drs[0]["F9"]); string soHoaDonHopDong = TextUtils.ToString(drs[0]["F5"]); string ngay = TextUtils.ToDate3(drs[0]["F6"]).ToString("dd/MM/yyyy"); string percentThanhToan = TextUtils.ToString(drs[0]["F14"]); if (percentThanhToan != "") { noiDung = "Thanh toán trả trước nốt " + percentThanhToan + "% hợp đồng số " + soHoaDonHopDong + " ngày " + ngay; } else { noiDung = "Thanh toán tiền hàng hợp đồng số " + soHoaDonHopDong + " ngày " + ngay; } } int length = noiDung.Length; if (length <= 200) { TextUtils.RepalaceText(doc, "<noiDung" + stt + ">", noiDung); } TextUtils.RepalaceText(doc, "<benThuHuong" + stt + ">", TextUtils.ToString(dtDistinctItem.Rows[i]["F2"])); TextUtils.RepalaceText(doc, "<NganHang" + stt + ">", TextUtils.ToString(dtDistinctItem.Rows[i]["F3"])); TextUtils.RepalaceText(doc, "<soTaiKhoan" + stt + ">", TextUtils.ToString(dtDistinctItem.Rows[i]["F4"])); TextUtils.RepalaceText(doc, "<tienNhanNo" + stt + ">", tienNhanNo.ToString("n2")); TextUtils.RepalaceText(doc, "<bangChu" + stt + ">", TextUtils.NumericToString(tienNhanNo, "USD")); TextUtils.RepalaceText(doc, "<swiftCode" + stt + ">", TextUtils.ToString(dtDistinctItem.Rows[i]["F10"])); TextUtils.RepalaceText(doc, "<diaChiNganHang" + stt + ">", TextUtils.ToString(dtDistinctItem.Rows[i]["F11"])); TextUtils.RepalaceText(doc, "<diaChiBenThuHuong" + stt + ">", TextUtils.ToString(dtDistinctItem.Rows[i]["F12"])); } TextUtils.RepalaceText(doc, "<month>", string.Format("{0:00}", DateTime.Now.Month)); TextUtils.RepalaceText(doc, "<year>", DateTime.Now.Year.ToString()); doc.Save(); doc.Close(); word.Quit(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Tân Phát", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { TextUtils.ReleaseComObject(doc); TextUtils.ReleaseComObject(word); } #endregion Hợp đồng ngoại tệ } }
void save(bool close) { ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); try { if (!ValidateForm()) { return; } grvFile.FocusedRowHandle = -1; Require.Name = txtName.Text.Trim().ToUpper(); Require.Code = txtCode.Text.Trim(); Require.CustomerCode = TextUtils.ToString(cboCustomer.EditValue); Require.CustomerName = TextUtils.ToString(grvCboKhachHang.GetFocusedRowCellValue(colCboCustomerName)); Require.Description = txtDescription.Text; Require.RequireDate = (DateTime?)dtpRequestDate.EditValue; Require.SolutionDate = (DateTime?)dtpSolutionDate.EditValue; Require.RequirePerson = TextUtils.ToInt(cboNguoiYeuCau.EditValue); Require.NguoiPhuTrach = TextUtils.ToInt(cboNguoiPhuTrach.EditValue); Require.Priority = cboPriority.SelectedIndex; Require.NguoiDaiDien = txtNguoiDaiDien.Text.Trim(); Require.Phone = txtPhone.Text; Require.Email = txtEmail.Text; Require.Cost = TextUtils.ToDecimal(txtCost.Text); Require.UpdatedDate = TextUtils.GetSystemDate(); Require.UpdatedBy = Global.AppUserName; if (Require.ID <= 0) { Require.CreatedDate = TextUtils.GetSystemDate(); Require.CreatedBy = Global.AppUserName; Require.ID = (int)pt.Insert(Require); } else { pt.Update(Require); } //update tên cho file ipt DataRow[] drs = _dtFile.Select("ID = 0 or ID is null"); if (drs.Length > 0) { DocUtils.InitFTPTK(); using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang update tên cho file...")) { for (int i = 0; i < grvFile.RowCount; i++) { long id = TextUtils.ToInt64(grvFile.GetRowCellValue(i, colFileID)); if (id > 0) { continue; } string name = TextUtils.ToString(grvFile.GetRowCellValue(i, colFileName)); string extension = Path.GetExtension(name); decimal length = TextUtils.ToDecimal(grvFile.GetRowCellValue(i, colFileLenght)); string description = TextUtils.ToString(grvFile.GetRowCellValue(i, colFileDescription)); string path = "YeuCau/" + Require.Code + "/" + name; string createdBy = Global.AppUserName; DateTime?createdDate = DateTime.Now; string localPath = TextUtils.ToString(grvFile.GetRowCellValue(i, colFileLocalPath)); if (!DocUtils.CheckExits("YeuCau/" + Require.Code)) { DocUtils.MakeDir("YeuCau/" + Require.Code); } RequireSolutionFileModel fileModel = new RequireSolutionFileModel(); fileModel.CreatedBy = createdBy; fileModel.CreatedDate = createdDate; fileModel.Description = description; fileModel.Extension = extension; fileModel.Length = length; fileModel.Name = name; fileModel.Path = path; fileModel.RequireSolutionID = Require.ID; pt.Insert(fileModel); DocUtils.UploadFile(localPath, "YeuCau/" + Require.Code); } } } pt.CommitTransaction(); loadGrid(); _isSaved = true; if (close) { this.DialogResult = DialogResult.OK; } else { MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("Lưu trữ không thành công!" + Environment.NewLine + ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { pt.CloseConnection(); } }
void updateVersion() { if (!File.Exists(_pathFileConfigUpdate)) { return; } try { string[] lines = File.ReadAllLines(_pathFileConfigUpdate); if (lines == null) { return; } if (lines.Length < 2) { return; } string[] stringSeparators = new string[] { "||" }; string[] arr = lines[1].Split(stringSeparators, 4, StringSplitOptions.RemoveEmptyEntries); if (arr == null) { return; } if (arr.Length < 4) { return; } _pathFolderUpdate = Path.Combine(Application.StartupPath, arr[1].Trim()); _pathUpdateServer = arr[2].Trim(); _pathFileVersion = Path.Combine(Application.StartupPath, arr[3].Trim()); if (!Directory.Exists(_pathError)) { Directory.CreateDirectory(_pathError); } if (!Directory.Exists(_pathFolderUpdate)) { Directory.CreateDirectory(_pathFolderUpdate); } if (!File.Exists(_pathFileVersion)) { File.Create(_pathFileVersion); File.WriteAllText(_pathFileVersion, "1"); } int currentVerion = TextUtils.ToInt(File.ReadAllText(_pathFileVersion).Trim()); string[] listFileSv = DocUtils.GetFilesList(_pathUpdateServer); if (listFileSv == null) { return; } if (listFileSv.Length == 0) { return; } List <string> lst = listFileSv.ToList(); lst = lst.Where(o => o.Contains(".zip")).ToList(); int newVersion = lst.Max(o => TextUtils.ToInt(Path.GetFileNameWithoutExtension(o))); if (newVersion != currentVerion) { Process.Start(Path.Combine(Application.StartupPath, "UpdateVersion.exe")); } } catch { } }
private void getReport() { if (cbbType.SelectedIndex < 0) { MessageBox.Show("Bạn chưa chọn loại báo cáo!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //check valid period time if (DateTime.Parse(dtpFrom.Text) > DateTime.Parse(dtpTo.Text)) { MessageBox.Show("Khoảng thời gian không hợp lệ", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } pgbExport.Visible = true; pgbExport.Style = ProgressBarStyle.Marquee; pgbExport.Left = this.Width / 2; pgbExport.Top = this.Height / 2; this.Enabled = false; //get data report string from = new DateTime(dtpFrom.Value.Year, dtpFrom.Value.Month, dtpFrom.Value.Day, 0, 0, 0).ToString("yyyy-MM-dd HH:mm:ss"); string to = new DateTime(dtpTo.Value.Year, dtpTo.Value.Month, dtpTo.Value.Day, 23, 59, 59).ToString("yyyy-MM-dd HH:mm:ss"); string productStepCode; string productGroupCode; if (cbbProductStepCode.SelectedIndex != 0) { productStepCode = cbbProductStepCode.Text; } else { productStepCode = string.Empty; } if (cbbGroupProductCode.SelectedIndex != 0) { productGroupCode = cbbGroupProductCode.SelectedValue.ToString(); } else { productGroupCode = string.Empty; } int Type = cbbType.SelectedIndex; System.Data.DataTable dtReport = LibIE.GetDataTableFromSP("spGetAndonReport", new string[] { "@StartDate", "@EndDate", "@ProductStepCode", "@ProductGroupCode", "@Type" }, new object[] { from, to, productStepCode, productGroupCode, Type }); int totalDelay = 0; int totalRisk = 0; int totalTimeDelay = 0; int totalTimeRisk = 0; totalRisk = TextUtils.ToInt(dtReport.Compute("Count(Type)", "Type = 2")); totalDelay = TextUtils.ToInt(dtReport.Compute("Count(Type)", "Type = 1"));; totalTimeDelay = TextUtils.ToInt(dtReport.Compute("Sum(DelayTime)", "Type = 1"));; totalTimeRisk = TextUtils.ToInt(dtReport.Compute("Sum(RiskTime)", "Type = 2"));; grdReport.DataSource = dtReport; txtTotalDelay.Text = totalDelay.ToString(); txtTotalRisk.Text = totalRisk.ToString(); txtTimeDelay.Text = totalTimeDelay.ToString(); txtTimeRisk.Text = totalTimeRisk.ToString(); }
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(); //} }
private void btnSave_Click(object sender, EventArgs e) { if (!ValidateForm()) { return; } grvCost.FocusedRowHandle = grvCostTM.FocusedRowHandle = grvDiff.FocusedRowHandle = -1; try { #region Chi phí phát sinh if (grvDiff.RowCount > 0) { for (int i = 0; i < grvDiff.RowCount; i++) { BaoGiaDiffModel diffModel = new BaoGiaDiffModel(); int diffID = TextUtils.ToInt(grvDiff.GetRowCellValue(i, colDiffID)); if (diffID > 0) { diffModel = (BaoGiaDiffModel)BaoGiaDiffBO.Instance.FindByPK(diffID); } diffModel.STT = TextUtils.ToInt(grvDiff.GetRowCellValue(i, colDiffSTT)); diffModel.BaoGiaID = BaoGia.ID; diffModel.Description = grvDiff.GetRowCellValue(i, colDiffDescription) != null?grvDiff.GetRowCellValue(i, colDiffDescription).ToString() : ""; diffModel.Name = grvDiff.GetRowCellValue(i, colDiffName) != null?grvDiff.GetRowCellValue(i, colDiffName).ToString() : ""; diffModel.Price = grvDiff.GetRowCellValue(i, colDiffPrice) != null?TextUtils.ToDecimal(grvDiff.GetRowCellValue(i, colDiffPrice)) : 0; if (diffID > 0) { BaoGiaDiffBO.Instance.Update(diffModel); } else { BaoGiaDiffBO.Instance.Insert(diffModel); } } } #endregion #region Chi phí sản xuất if (grvCost.RowCount > 0) { for (int i = 0; i < grvCost.RowCount; i++) { CostSummaryModel sxModel = new CostSummaryModel(); int sxID = TextUtils.ToInt(grvCost.GetRowCellValue(i, colID)); if (sxID > 0) { sxModel = (CostSummaryModel)CostSummaryBO.Instance.FindByPK(sxID); } sxModel.CostDetailID = TextUtils.ToInt(grvCost.GetRowCellValue(i, colCostDetailID)); sxModel.BaoGiaID = BaoGia.ID; sxModel.DepartmentID = TextUtils.ToInt(grvCost.GetRowCellValue(i, colDepartmentID)); sxModel.TotalDK = TextUtils.ToDecimal(grvCost.GetRowCellValue(i, colTotal)); sxModel.TotalTT = TextUtils.ToDecimal(grvCost.GetRowCellValue(i, colTotalReal)); if (sxID > 0) { CostSummaryBO.Instance.Update(sxModel); } else { CostSummaryBO.Instance.Insert(sxModel); } } } #endregion #region Chi phí thương mại if (grvCostTM.RowCount > 0) { for (int i = 0; i < grvCostTM.RowCount; i++) { CostSummaryModel tmModel = new CostSummaryModel(); int tmID = TextUtils.ToInt(grvCostTM.GetRowCellValue(i, colIDTM)); if (tmID > 0) { tmModel = (CostSummaryModel)CostSummaryBO.Instance.FindByPK(tmID); } tmModel.CostDetailID = TextUtils.ToInt(grvCostTM.GetRowCellValue(i, colCostDetailIDTM)); tmModel.BaoGiaID = BaoGia.ID; tmModel.DepartmentID = TextUtils.ToInt(grvCostTM.GetRowCellValue(i, colDepartmentIDTM)); tmModel.TotalDK = TextUtils.ToDecimal(grvCostTM.GetRowCellValue(i, colTotalTM)); tmModel.TotalTT = TextUtils.ToDecimal(grvCostTM.GetRowCellValue(i, colTotalRealTM)); if (tmID > 0) { CostSummaryBO.Instance.Update(tmModel); } else { CostSummaryBO.Instance.Insert(tmModel); } } } #endregion #region Update Báo giá BaoGia.TotalPhatSinh = TextUtils.ToDecimal(colDiffPrice.SummaryItem.SummaryValue); BaoGia.TotalSX = TextUtils.ToDecimal(colTotal.SummaryItem.SummaryValue); BaoGia.TotalDkSX = TextUtils.ToDecimal(colTotalReal.SummaryItem.SummaryValue); BaoGia.TotalTM = TextUtils.ToDecimal(colTotalTM.SummaryItem.SummaryValue); BaoGia.TotalDkTM = TextUtils.ToDecimal(colTotalRealTM.SummaryItem.SummaryValue); BaoGiaBO.Instance.Update(BaoGia); #endregion _isSaved = true; LoadGrid(0); LoadGrid(1); loadDiffGrid(); MessageBox.Show("Ghi dữ liệu thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Cất dữ liệu /// </summary> /// <returns></returns> bool saveData() { if (!ValidateForm()) { return(false); } WorkingModel.ProductGroupID = TextUtils.ToInt(cboGroup.EditValue); WorkingModel.WorkingStepID = TextUtils.ToInt(cboStep.EditValue); WorkingModel.WorkingName = txtName.Text.Trim(); WorkingModel.SortOrder = (int)txtSortOrder.Value; WorkingModel.Unit = txtUnit.Text.Trim(); WorkingModel.ValueType = cboValueType.SelectedIndex; WorkingModel.ValueTypeName = cboValueType.SelectedIndex == 0 ? "Check mark" : "Giá trị\n数値"; WorkingModel.MaxValue = TextUtils.ToDecimal(txtMax.Value); WorkingModel.MinValue = TextUtils.ToDecimal(txtMin.Value); // WorkingModel.PeriodValue = WorkingModel.MinValue + "~" + WorkingModel.MaxValue; WorkingModel.IsGetAutoValueComport = chkAutoValue.Checked; WorkingModel.Comport = cboComPort.SelectedIndex + 1; WorkingModel.CheckValueType = cboCheckValueType.SelectedIndex; WorkingModel.IsGetAutoValueIP = chkIP.Checked; WorkingModel.IpAddress = txtIP.Text.Trim(); WorkingModel.Port = txtPort.Text.Trim(); if (WorkingModel.ValueType == 0)//checkmark { WorkingModel.PeriodValue = txtPeriodValue.Text.Trim(); } else { if (WorkingModel.CheckValueType == 1)//giá trị dạng số { if (WorkingModel.MinValue == WorkingModel.MaxValue) { WorkingModel.PeriodValue = WorkingModel.MaxValue.ToString("n3"); } else { WorkingModel.PeriodValue = WorkingModel.MinValue.ToString("n3") + "~" + WorkingModel.MaxValue.ToString("n3"); } } else { WorkingModel.PeriodValue = txtPeriodValue.Text.Trim(); } } if (WorkingModel.ID > 0) { WorkingBO.Instance.Update(WorkingModel); LibIE.ExcuteSQL(string.Format("EXEC spUpdateMultiProductWorking {0}, 1", WorkingModel.ID)); } else { WorkingModel.ID = (int)WorkingBO.Instance.Insert(WorkingModel); LibIE.ExcuteSQL(string.Format("EXEC CreateProductWorking_ByWorkingID {0}", WorkingModel.ID)); } return(true); }
private void btnShowWorking_Click(object sender, EventArgs e) { int Y = 0; int workingStepID = TextUtils.ToInt(cboWorkingStep.SelectedValue); string qrCode = txtQRCode.Text.Trim(); string workerCode = txtWorker.Text.Trim(); string productCode = ""; string orderCode = txtQRCode.Text.Trim(); string[] arr1 = orderCode.Split(' '); if (arr1.Length > 1) { productCode = arr1[1]; } if (workingStepID == 0) { MessageBox.Show("Bạn chưa chọn công đoạn kiểm tra!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrWhiteSpace(qrCode)) { MessageBox.Show("Bạn chưa nhập sản phẩm cần kiểm tra!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { if (!ProductBO.Instance.CheckExist("ProductCode", productCode)) { MessageBox.Show("Mã sản phẩm không đúng!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } //if (string.IsNullOrWhiteSpace(workerCode)) //{ // MessageBox.Show("Bạn chưa nhập người kiểm tra!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; //} //else //{ // if (!UsersBO.Instance.CheckExist("Code", workerCode)) // { // MessageBox.Show("Mã người kiểm tra không đúng!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; // } //} lstUC.Clear(); panel1.Controls.Clear(); ArrayList arr = ProductCheckHistoryDetailBO.Instance.GetListObject("spGetWorkingByProductGroupID", new string[4] { "@WorkingStepID", "@QRCode", "@ProductCode", "@WorkerCode" }, new object[4] { workingStepID, qrCode, productCode, workerCode }); if (arr.Count > 0) { foreach (var item in arr) { CheckControl uc = new CheckControl(); uc._model = (ProductCheckHistoryDetailModel)item; uc.Location = new Point(uc.Location.X, Y); panel1.Controls.Add(uc); Y += 53; lstUC.Add(uc); } } else { lstUC.Clear(); panel1.Controls.Clear(); } }
void LoadInfoSearch() { DataTable dt = LibQLSX.Select("Select * from vC_Quotation with(nolock) where Year = " + TextUtils.ToInt(cboYear.SelectedItem)); grdData.DataSource = dt; if (_rownIndex >= grvData.RowCount) { _rownIndex = 0; } if (_rownIndex > 0) { grvData.FocusedRowHandle = _rownIndex; } grvData.SelectRow(_rownIndex); }
void save() { ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); try { if (!ValidateForm()) { return; } UpdateSoftware.Code = txtCode.Text.Trim(); UpdateSoftware.Name = txtName.Text.Trim(); UpdateSoftware.Status = cboStatus.SelectedIndex; UpdateSoftware.Complete = chkClosed.Checked; UpdateSoftware.NgayBaoGia = TextUtils.ToDate2(dtpNgayBaoGia.EditValue); UpdateSoftware.NgayBaoGiaConfirm = TextUtils.ToDate2(dtpNgayBaoGiaConfirm.EditValue); UpdateSoftware.RequestDate = TextUtils.ToDate2(dtpRequestDate.EditValue); UpdateSoftware.WorkEndDate = TextUtils.ToDate2(dtpWorkEndDate.EditValue); UpdateSoftware.WorkEndDateDK = TextUtils.ToDate2(dtpWorkEndDateDK.EditValue); UpdateSoftware.ConfirmDate = TextUtils.ToDate2(dtpConfirmDate.EditValue); UpdateSoftware.Price = TextUtils.ToDecimal(txtPrice.EditValue); UpdateSoftware.SoftwareCompany = cboNCC.Text; UpdateSoftware.SoftwareName = cboPhanMem.Text; UpdateSoftware.Status = cboStatus.SelectedIndex; UpdateSoftware.Type = cboType.SelectedIndex; UpdateSoftware.UserID = TextUtils.ToInt(cboUser.EditValue); if (UpdateSoftware.ID == 0) { UpdateSoftware.ID = (int)pt.Insert(UpdateSoftware); } else { pt.Update(UpdateSoftware); } pt.CommitTransaction(); loadNCC(); loadPhanMem(); _isSaved = true; MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Lưu trữ không thành công!" + Environment.NewLine + ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { pt.CloseConnection(); } if (_isSaved && this.LoadDataChange != null) { this.LoadDataChange(null, null); } }
bool ValidateForm() { /*if (cKnifeList.EditValue == null) * { * MessageBox.Show("Vui lòng nhập mã dao!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); * return false; * }*/ if (txbQuantity.Value == 0) { MessageBox.Show("Vui lòng nhập số lượng khác 0!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (cWorker.EditValue == null) { MessageBox.Show("Vui lòng chọn người phụ trách!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (string.IsNullOrEmpty(cKnifeList.Text)) { MessageBox.Show("Vui lòng chọn loại dao!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } KnifeDetailListModel currentModel = (KnifeDetailListModel)KnifeDetailListBO.Instance.FindByPK(TextUtils.ToInt64(cKnifeList.EditValue)); if (currentModel.CurrentATC == currentModel.ATC) { if (MessageBox.Show("Mã dao này không thể tiếp tục sử dụng! \n Bạn có muốn hủy mã dao này?", "Thông báo", MessageBoxButtons.OKCancel) == DialogResult.OK) { frmKnifeDisposed frm = new frmKnifeDisposed(); frm.knifeID = currentModel.ID; if (frm.ShowDialog() == DialogResult.OK) { knifeProcessedList = new KnifeProcessedListModel(); ClearFormData(); LoadData(); } } return(false); } if (currentModel.CurrentSTD == currentModel.STD) { if (MessageBox.Show("Mã dao này cần được mài trước khi sử dụng! \n Bạn có muốn mài mã dao này ngay bây giờ?", "Thông báo", MessageBoxButtons.OKCancel) == DialogResult.OK) { // Mai dao frmKnifeSharpen frm = new frmKnifeSharpen(); frm.knifeID = TextUtils.ToInt(cKnifeList.EditValue); if (frm.ShowDialog() == DialogResult.OK) { knifeProcessedList = new KnifeProcessedListModel(); ClearFormData(); LoadData(); } } return(false); } return(true); }
void calculateCost_PB(C_QuotationDetail_SXModel item) { int costID = (Quotation.DepartmentId == "D018" ? 73 : 72);//Phòng KD1->lấy ra chi phí nhân công KD2 không thì lấy chi phí nhân công KD1 if (item.C_ProductGroupID == 0) { C_CostQuotationItemLinkNewBO.Instance.DeleteByAttribute("C_QuotationDetail_SXID", item.ID); item.TotalNC = 0; item.TotalPB = 0; C_QuotationDetail_KDBO.Instance.Update(item); } else { //ArrayList arr = C_CostBO.Instance.FindByExpression(new Expression("IsUse", 1)); string sql = ""; if (Quotation.StatusNC == 1) { sql = "select *, ValuePercentSX = (select top 1 ValuePercentSX from vC_CostProductGroupLinkNew where C_CostID = a.ID and [C_ProductGroupID] = " + item.C_ProductGroupID + " and [C_VersionID] = " + Quotation.C_VersionID + ") from vC_CostNew a where IsUse = 1 and IsDeleted = 0 and GroupCode in ('N01','N08','N09','N11','N02','N03','N04','N07.02','N07.03')"; } else { sql = "select *, ValuePercentSX = (select top 1 ValuePercentSX from vC_CostProductGroupLinkNew where C_CostID = a.ID and [C_ProductGroupID] = " + item.C_ProductGroupID + " and [C_VersionID] = " + Quotation.C_VersionID + ") from vC_CostNew a where IsUse = 1 and IsDeleted = 0 and GroupCode in ('N01','N08','N09','N11')"; } DataTable dtCost = LibQLSX.Select(sql); foreach (DataRow row in dtCost.Rows) { string code = TextUtils.ToString(row["Code"]); C_CostQuotationItemLinkNewModel link = new C_CostQuotationItemLinkNewModel(); ArrayList arrLink = C_CostQuotationItemLinkNewBO.Instance.FindByExpression(new Expression("C_CostID", TextUtils.ToInt(row["ID"])) .And(new Expression("C_QuotationDetail_SXID", item.ID))); if (arrLink != null && arrLink.Count > 0) { link = (C_CostQuotationItemLinkNewModel)arrLink[0]; } link.C_CostID = TextUtils.ToInt(row["ID"]); link.C_QuotationDetail_SXID = item.ID; //if (link.C_CostID == costID) //{ // link.Price = 0; //} //else //{ link.Price = TextUtils.ToDecimal(row["ValuePercentSX"]) / 100 * item.PriceTPA; //} if (link.ID == 0) { C_CostQuotationItemLinkNewBO.Instance.Insert(link); } else { C_CostQuotationItemLinkNewBO.Instance.Update(link); } } C_QuotationDetail_KDBO.Instance.Update(item); } }
void calculateCost(C_QuotationDetailModel item) { ArrayList arr = C_CostBO.Instance.FindByExpression(new Expression("IsUse", 1).And(new Expression("IsWithProject", 0))); DataTable dtCostProductGroup = LibQLSX.Select("select * from vC_CostProductGroupLink where [C_ProductGroupID] = " + item.C_ProductGroupID); decimal totalNC = 0; decimal totalPB = 0; foreach (var c in arr) { C_CostModel cost = (C_CostModel)c; DataRow[] drs = dtCostProductGroup.Select("C_CostID = " + cost.ID); if (drs.Length == 0) { continue; } C_CostQuotationItemLinkModel link = new C_CostQuotationItemLinkModel(); ArrayList arrLink = C_CostQuotationItemLinkBO.Instance.FindByExpression(new Expression("C_CostID", cost.ID).And(new Expression("C_QuotationDetailID", item.ID))); if (arrLink != null && arrLink.Count > 0) { link = (C_CostQuotationItemLinkModel)arrLink[0]; } link.C_CostID = cost.ID; link.C_QuotationDetailID = item.ID; link.IsDirect = cost.IsDirectCost; if (link.IsDirect == 1) { #region Chi phí nhân công link.PersonNumber = TextUtils.ToDecimal(drs[0]["PersonNumber"]); int isFix = TextUtils.ToInt(drs[0]["IsFix"]); if (isFix == 1) { link.NumberDay = TextUtils.ToDecimal(drs[0]["NumberDay"]); } else { link.NumberDay = TextUtils.ToDecimal(drs[0]["VtuPercent"]) * item.PriceVT / cost.Price; } link.Price = link.NumberDay * link.PersonNumber * cost.Price * item.Qty; if (cost.ID == 61)//phòng thiết kế { link.Price = (link.NumberDay * link.PersonNumber) * (1 + 0.3M * (item.Qty >= 2 ? item.Qty - 1 : 0)) * cost.Price; } totalNC += link.Price; #endregion } else { #region Chi phí phân bổ decimal valuePercent = TextUtils.ToDecimal(drs[0]["ValuePercent"]); link.Price = valuePercent * item.Qty * item.PriceHD; if (cost.IsDeliveryTime == 1) { link.Price *= Quotation.DeliveryTime / 288; } if (cost.ID == 72 || cost.ID == 73) { if (cost.ID != Quotation.DepartmentId) { link.Price = 0; } } totalPB += link.Price; #endregion } if (link.ID == 0) { C_CostQuotationItemLinkBO.Instance.Insert(link); } else { C_CostQuotationItemLinkBO.Instance.Update(link); } item.TotalNC = totalNC; item.TotalPB = totalPB; C_QuotationDetailBO.Instance.Update(item); } }
private void btnSave_Click(object sender, EventArgs e) { bool _isSaved = false; if (treeData.AllNodesCount == 0) { return; } treeData.ExpandAll(); treeData.FocusedNode = null; DataTable dtSource = (DataTable)treeData.DataSource; DataRow[] drsVatTu = dtSource.Select("(PriceVT is null or PriceVT = 0) and (C_ProductGroupID > 0 and ParentID > 0)"); if (drsVatTu.Length > 0) { MessageBox.Show("Bạn chưa nhập đủ VẬT TƯ SẢN XUẤT cho các hạng mục.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } int costID = (Quotation.DepartmentId == "D018" ? 73 : 72);//Phòng KD1->lấy ra chi phí nhân công KD2 không thì lấy chi phí nhân công KD1 using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang xử lý...")) { #region Save item for (int i = 0; i < treeData.AllNodesCount; i++) { int id = TextUtils.ToInt(treeData.GetNodeByVisibleIndex(i).GetValue(colDetailID)); C_QuotationDetail_SXModel item = (C_QuotationDetail_SXModel)C_QuotationDetail_SXBO.Instance.FindByPK(id); item.ModuleCode = TextUtils.ToString(treeData.GetNodeByVisibleIndex(i).GetValue(colModuleCode)); item.ModuleName = TextUtils.ToString(treeData.GetNodeByVisibleIndex(i).GetValue(colModuleName)); item.PriceVTLD = TextUtils.ToDecimal(treeData.GetNodeByVisibleIndex(i).GetValue(colPriceVTLD)); item.PriceVTPS = TextUtils.ToDecimal(treeData.GetNodeByVisibleIndex(i).GetValue(colPriceVTPS)); item.PriceVT = TextUtils.ToDecimal(treeData.GetNodeByVisibleIndex(i).GetValue(colPriceVTSX)); item.PriceVTTN = TextUtils.ToDecimal(treeData.GetNodeByVisibleIndex(i).GetValue(colPriceVTTN)); item.PriceHD = TextUtils.ToDecimal(treeData.GetNodeByVisibleIndex(i).GetValue(colPriceHD)); item.C_ProductGroupID = TextUtils.ToInt(treeData.GetNodeByVisibleIndex(i).GetValue(colProductGroupID)); item.VAT = TextUtils.ToDecimal(treeData.GetNodeByVisibleIndex(i).GetValue(colVAT)); item.QtyT = TextUtils.ToDecimal(treeData.GetNodeByVisibleIndex(i).GetValue(colQtyT)); string sqlPB = "select sum(ValuePercentSX) from vC_CostProductGroupLinkNew where C_CostGroupNew_Code in ('N01','N08','N09','N11') and C_ProductGroupID = " + item.C_ProductGroupID + " and [C_VersionID] = " + Quotation.C_VersionID; string sqlNC = "select sum(ValuePercentSX) from vC_CostProductGroupLinkNew where C_CostGroupNew_Code in ('N02','N03','N04','N07.02','N07.03') and C_ProductGroupID = " + item.C_ProductGroupID + " and [C_VersionID] = " + Quotation.C_VersionID; decimal totalPercentCP_PB = TextUtils.ToDecimal(LibQLSX.ExcuteScalar(sqlPB)) / 100; decimal totalPercentCP_NC = TextUtils.ToDecimal(LibQLSX.ExcuteScalar(sqlNC)) / 100; item.TotalPercentCP_NC = totalPercentCP_NC; item.TotalPercentCP_PB = totalPercentCP_PB; int parentID = TextUtils.ToInt(treeData.GetNodeByVisibleIndex(i).GetValue(colParentID)); if (parentID == 0) { item.Qty = item.QtyT; } else { C_QuotationDetail_SXModel parent = (C_QuotationDetail_SXModel)C_QuotationDetail_SXBO.Instance.FindByPK(parentID); item.Qty = item.QtyT * parent.Qty; } item.UpdatedDate = DateTime.Now; item.UpdatedBy = Global.AppUserName; C_QuotationDetail_SXBO.Instance.Update(item); } #endregion DataTable dtCostVT = LibQLSX.Select("select sum(isnull(Qty,0)*(isnull(PriceVT,0)+isnull(PriceVTTN,0)+isnull(PriceVTPS,0)+isnull(PriceVTLD,0)))" + ", sum(isnull(Qty,0)*isnull(TotalPercentCP_NC,0))" //+ ", sum(isnull(Qty,0)*isnull(TotalPercentCP_PB,0))" + " from C_QuotationDetail_SX where (ParentID > 0 or (ParentID = 0 and C_ProductGroupID > 0)) and [C_QuotationID] = " + Quotation.ID); decimal totalAllVT = dtCostVT.Rows.Count > 0 ? TextUtils.ToDecimal(dtCostVT.Rows[0][0]) : 0; decimal totalAllPercentCP_NC = dtCostVT.Rows.Count > 0 ? TextUtils.ToDecimal(dtCostVT.Rows[0][1]) : 0; //decimal totalAllPercentCP_PB = dtCostVT.Rows.Count > 0 ? TextUtils.ToDecimal(dtCostVT.Rows[0][2]) : 0; if (Quotation.StatusNC == 1) { #region Tính nhân công theo % phân bổ for (int i = 0; i < treeData.AllNodesCount; i++) { int id = TextUtils.ToInt(treeData.GetNodeByVisibleIndex(i).GetValue(colDetailID)); C_QuotationDetail_SXModel item = (C_QuotationDetail_SXModel)C_QuotationDetail_SXBO.Instance.FindByPK(id); if (item.ParentID == 0 && item.C_ProductGroupID == 0) { continue; } decimal profitPercent = TextUtils.ToDecimal(LibQLSX.ExcuteScalar("select top 1 ProfitPercentSX from C_ProductGroup where ID = " + item.C_ProductGroupID)) / 100; decimal percentPB = item.TotalPercentCP_NC + item.TotalPercentCP_PB; decimal totalVT = item.PriceVT + item.PriceVTLD + item.PriceVTPS + item.PriceVTTN; decimal tyle = (item.TotalPercentCP_NC + totalVT) / (totalAllPercentCP_NC + totalAllVT); item.TotalDP = Quotation.TotalDP_SX * tyle; //dự phòng item.TotalVC = Quotation.TotalCPVCHB_C13 * tyle; //vận chuyển item.TotalBX = Quotation.TotalBXHB_C52 * tyle; //bốc xếp item.PriceDiLai = Quotation.TotalDiLai * tyle; //Đi lại item.TotalPB_DA = item.TotalDP + item.TotalVC + item.TotalBX + item.PriceDiLai; item.PriceCP = item.TotalPB_DA + totalVT; item.PriceTPA = item.PriceCP * (1 + profitPercent) / (1 - percentPB * (1 + profitPercent)); item.TotalPB = item.TotalPercentCP_PB / 100 * item.PriceTPA; item.TotalNC = item.TotalPercentCP_NC / 100 * item.PriceTPA; item.TotalProfit = profitPercent * (item.PriceCP + (percentPB * item.PriceTPA)); C_QuotationDetail_SXBO.Instance.Update(item); calculateCost_PB(item); } #endregion } else { #region Tính nhân công theo công nhật decimal totalAllNC = TextUtils.ToDecimal(LibQLSX.ExcuteScalar("select sum(isnull(Qty,0) * isnull(Price,0)) from vC_CostQuotationItemLinkSX" + " where IsDirect = 1 and [C_QuotationID] = " + Quotation.ID)); for (int i = 0; i < treeData.AllNodesCount; i++) { int id = TextUtils.ToInt(treeData.GetNodeByVisibleIndex(i).GetValue(colDetailID)); C_QuotationDetail_SXModel item = (C_QuotationDetail_SXModel)C_QuotationDetail_SXBO.Instance.FindByPK(id); if (item.ParentID == 0 && item.C_ProductGroupID == 0) { continue; } decimal profitPercent = TextUtils.ToDecimal(LibQLSX.ExcuteScalar("select top 1 ProfitPercentSX from C_ProductGroup where ID = " + item.C_ProductGroupID)) / 100; decimal percentPB = item.TotalPercentCP_PB; decimal totalVT = item.PriceVT + item.PriceVTLD + item.PriceVTPS + item.PriceVTTN; decimal totalNC = TextUtils.ToDecimal(LibQLSX.ExcuteScalar("select sum(Price) from C_CostQuotationItemLinkNew where IsDirect = 1 and C_QuotationDetail_SXID = " + item.ID)); item.TotalNC = totalNC; item.TotalDP = Quotation.TotalDP_SX * (item.TotalNC + totalVT) / (totalAllNC + totalAllVT); //dự phòng item.TotalVC = Quotation.TotalCPVCHB_C13 * (item.TotalNC + totalVT) / (totalAllNC + totalAllVT); //vận chuyển item.TotalBX = Quotation.TotalBXHB_C52 * (item.TotalNC + totalVT) / (totalAllNC + totalAllVT); //bốc xếp item.PriceDiLai = Quotation.TotalDiLai * (item.TotalNC + totalVT) / (totalAllNC + totalAllVT); //Đi lại item.TotalPB_DA = item.TotalDP + item.TotalVC + item.TotalBX; item.PriceCP = item.TotalNC + item.TotalPB_DA + totalVT; item.PriceTPA = item.PriceCP * (1 + profitPercent) / (1 - percentPB * (1 + profitPercent)); item.TotalPB = percentPB * item.PriceTPA; //item.TotalNC = item.TotalPercentCP_NC * item.PriceTPA; item.TotalProfit = profitPercent * (item.PriceCP + (percentPB * item.PriceTPA)); C_QuotationDetail_SXBO.Instance.Update(item); calculateCost_PB(item); } #endregion } #region Save parent ArrayList listParent = C_QuotationDetail_SXBO.Instance.FindByExpression(new Expression("ParentID", 0) .And(new Expression("C_ProductGroupID", 0)) .And(new Expression("C_QuotationID", Quotation.ID))); if (listParent != null) { foreach (var item in listParent) { C_QuotationDetail_SXModel itemP = (C_QuotationDetail_SXModel)item; DataTable dtChild = LibQLSX.Select("select PriceVTLD=Sum(QtyT*PriceVTLD),PriceVTPS=Sum(QtyT*PriceVTPS),PriceVT=Sum(QtyT*PriceVT),PriceVTTN=Sum(QtyT*PriceVTTN)" + ",TotalNC=Sum(QtyT*TotalNC),TotalPB_DA=Sum(QtyT*TotalPB_DA),TotalPB=Sum(QtyT*TotalPB),PriceCP=Sum(QtyT*PriceCP),PriceTPA=Sum(QtyT*PriceTPA),PriceHD=Sum(QtyT*PriceHD)" + ",TotalProfit=Sum(QtyT*TotalProfit)" + ",TotalDP=Sum(QtyT*TotalDP),TotalVC=Sum(QtyT*TotalVC),TotalBX=Sum(QtyT*TotalBX) from C_QuotationDetail_SX where ParentID = " + itemP.ID); itemP.PriceVTLD = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["PriceVTLD"]) : itemP.PriceVTLD; itemP.PriceVTPS = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["PriceVTPS"]) : itemP.PriceVTPS; itemP.PriceVT = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["PriceVT"]) : itemP.PriceVT; itemP.PriceVTTN = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["PriceVTTN"]) : itemP.PriceVTTN; itemP.TotalNC = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["TotalNC"]) : itemP.TotalNC; itemP.TotalPB_DA = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["TotalPB_DA"]) : itemP.TotalPB_DA; itemP.TotalPB = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["TotalPB"]) : itemP.TotalPB; itemP.PriceCP = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["PriceCP"]) : itemP.PriceCP; itemP.PriceTPA = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["PriceTPA"]) : itemP.PriceTPA; itemP.PriceHD = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["PriceHD"]) : itemP.PriceHD; itemP.TotalProfit = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["TotalProfit"]) : itemP.TotalProfit; itemP.TotalDP = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["TotalDP"]) : itemP.TotalDP; itemP.TotalVC = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["TotalVC"]) : itemP.TotalVC; itemP.TotalBX = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["TotalBX"]) : itemP.TotalBX; C_QuotationDetail_SXBO.Instance.Update(itemP); } } #endregion loadQuotationItem(); _isSaved = true; } MessageBox.Show("Lưu trữ thành công.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); if (_isSaved) { if (this.LoadDataChange != null) { this.LoadDataChange(null, null); } } }
private void btnSave_Click(object sender, EventArgs e) { bool _isSaved = false; if (grvData.RowCount == 0) { return; } grvData.FocusedRowHandle = -1; using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang xử lý...")) { for (int i = 0; i < grvData.RowCount; i++) { int id = TextUtils.ToInt(grvData.GetRowCellValue(i, colDetailID)); C_QuotationDetailModel item = (C_QuotationDetailModel)C_QuotationDetailBO.Instance.FindByPK(id); item.PriceVTLD = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colPriceVTLD)); item.PriceVTPS = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colPriceVTPS)); item.PriceVTSX = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colPriceVTSX)); item.PriceVTTN = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colPriceVTTN)); item.PriceVT = item.PriceVTSX + item.PriceVTLD + item.PriceVTPS + item.PriceVTTN; item.PriceHD = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colPriceHDnoVAT)); item.C_ProductGroupID = TextUtils.ToInt(grvData.GetRowCellValue(i, colProductGroupID)); item.VAT = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colVAT)); item.Qty = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colQty)); C_QuotationDetailBO.Instance.Update(item); calculateCost(item); //LibQLSX.CalculatePriceTPA(item, Quotation); } for (int i = 0; i < grvData.RowCount; i++) { int id = TextUtils.ToInt(grvData.GetRowCellValue(i, colParentID)); if (id == 0) { continue; } C_QuotationDetailModel item = (C_QuotationDetailModel)C_QuotationDetailBO.Instance.FindByPK(id); DataTable dtChildTPA = LibQLSX.Select("select Sum(PriceTPA) from C_QuotationDetail where ParentID = " + id); DataTable dtChildHD = LibQLSX.Select("select Sum(PriceHD) from C_QuotationDetail where ParentID = " + id); item.PriceTPA = dtChildTPA.Rows.Count > 0 ? TextUtils.ToDecimal(dtChildTPA.Rows[0][0]) : item.PriceTPA; item.PriceHD = dtChildHD.Rows.Count > 0 ? TextUtils.ToDecimal(dtChildHD.Rows[0][0]) : item.PriceHD; C_QuotationDetailBO.Instance.Update(item); } loadQuotationItem(); _isSaved = true; } MessageBox.Show("Lưu trữ thành công.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); if (_isSaved) { if (this.LoadDataChange != null) { this.LoadDataChange(null, null); } } }
void exportBaoGia() { if (treeData.AllNodesCount == 0) { return; } string localPath = ""; FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { localPath = fbd.SelectedPath + "\\SX." + Quotation.Code + ".xls"; } else { return; } string filePath = Application.StartupPath + "\\Templates\\PhongKinhDoanh\\BaoGia.xls"; try { File.Copy(filePath, localPath, true); } catch (Exception ex) { MessageBox.Show("Lỗi: " + Environment.NewLine + ex.Message); return; } using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang tạo báo giá...")) { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); Excel.Application app = default(Excel.Application); Excel.Workbook workBoook = default(Excel.Workbook); Excel.Worksheet workSheet = default(Excel.Worksheet); try { app = new Excel.Application(); app.Workbooks.Open(localPath); workBoook = app.Workbooks[1]; workSheet = (Excel.Worksheet)workBoook.Worksheets[1]; DataTable dtItem = LibQLSX.Select("select * from vC_QuotationDetail_SX with(nolock) where ParentID = 0 and C_QuotationID = " + Quotation.ID); for (int i = dtItem.Rows.Count - 1; i >= 0; i--) { int id = TextUtils.ToInt(dtItem.Rows[i]["ID"]); string moduleCodeP = TextUtils.ToString(dtItem.Rows[i]["ModuleCode"]); string moduleNameP = TextUtils.ToString(dtItem.Rows[i]["ModuleName"]); decimal qtyP = TextUtils.ToDecimal(dtItem.Rows[i]["Qty"]); decimal priceP = TextUtils.ToDecimal(dtItem.Rows[i]["PriceHD"]); string hangP = TextUtils.ToString(dtItem.Rows[i]["Manufacture"]); DataTable dtC = LibQLSX.Select("select * from vC_QuotationDetail_SX with(nolock) where ParentID = " + id); if (dtC.Rows.Count == 0)//nếu thiết bị không có thiết bị con { #region Add Parent if (moduleCodeP.ToUpper().StartsWith("TPAD.") && moduleCodeP.Length == 10) { try { string spec = TextUtils.ToString(TextUtils.ExcuteScalar("select top 1 Specifications from Modules where Code = '" + moduleCodeP + "'")); if (spec.Length > 0) { string[] thongSo = spec.Split('\n'); for (int k = thongSo.Length - 1; k >= 0; k--) { workSheet.Cells[16, 3] = thongSo[k]; ((Excel.Range)workSheet.Rows[16]).Insert(); } } else { ((Excel.Range)workSheet.Rows[16]).Insert(); ((Excel.Range)workSheet.Rows[16]).Insert(); } } catch { } } else { ((Excel.Range)workSheet.Rows[16]).Insert(); ((Excel.Range)workSheet.Rows[16]).Insert(); } workSheet.Cells[16, 2] = (i + 1); workSheet.Cells[16, 3] = moduleNameP.ToUpper(); workSheet.Cells[16, 4] = moduleCodeP.ToUpper(); workSheet.Cells[16, 5] = hangP; workSheet.Cells[16, 6] = "BỘ"; workSheet.Cells[16, 7] = qtyP.ToString("n0"); workSheet.Cells[16, 8] = priceP.ToString("n0"); workSheet.Cells[16, 9] = qtyP * priceP; ((Excel.Range)workSheet.Rows[16]).Font.Bold = true; ((Excel.Range)workSheet.Rows[16]).Insert(); #endregion } else { decimal sumPrice = 0; #region Add child module for (int j = dtC.Rows.Count - 1; j >= 0; j--) { string moduleCode = TextUtils.ToString(dtC.Rows[j]["ModuleCode"]); string moduleName = TextUtils.ToString(dtC.Rows[j]["ModuleName"]); string qty = TextUtils.ToDecimal(dtC.Rows[j]["QtyT"]).ToString("n0"); string price = TextUtils.ToDecimal(dtC.Rows[j]["PriceHD"]).ToString("n0"); string hang = TextUtils.ToString(dtC.Rows[j]["Manufacture"]); //string total = TextUtils.ToDecimal(dtC.Rows[j]["TotalTPA"]).ToString("n0"); sumPrice += TextUtils.ToDecimal(qty) * TextUtils.ToDecimal(price); if (moduleCode.ToUpper().StartsWith("TPAD.") && moduleCode.Length == 10) { try { string spec = TextUtils.ToString(TextUtils.ExcuteScalar("select top 1 Specifications from Modules where Code = '" + moduleCode + "'")); if (spec.Length > 0) { string[] thongSo = spec.Split('\n'); for (int k = thongSo.Length - 1; k >= 0; k--) { workSheet.Cells[16, 3] = thongSo[k]; ((Excel.Range)workSheet.Rows[16]).Insert(); } } else { ((Excel.Range)workSheet.Rows[16]).Insert(); ((Excel.Range)workSheet.Rows[16]).Insert(); } } catch { } } else { ((Excel.Range)workSheet.Rows[16]).Insert(); ((Excel.Range)workSheet.Rows[16]).Insert(); } workSheet.Cells[16, 2] = (i + 1) + "." + (j + 1); workSheet.Cells[16, 3] = moduleName; //.ToUpper(); workSheet.Cells[16, 4] = moduleCode; //.ToUpper(); workSheet.Cells[16, 5] = hang; workSheet.Cells[16, 6] = ""; workSheet.Cells[16, 7] = qty; workSheet.Cells[16, 8] = price; //workSheet.Cells[16, 9] = total; ((Excel.Range)workSheet.Rows[16]).Font.Bold = true; ((Excel.Range)workSheet.Rows[16]).Insert(); } #endregion #region Add Parent workSheet.Cells[16, 3] = "'* Thông số kỹ thuật chi tiết"; ((Excel.Range)workSheet.Rows[16]).Font.Bold = true; ((Excel.Range)workSheet.Rows[16]).Insert(); for (int j = dtC.Rows.Count - 1; j >= 0; j--) { string moduleName = TextUtils.ToString(dtC.Rows[j]["ModuleName"]); string qty = TextUtils.ToDecimal(dtC.Rows[j]["QtyT"]).ToString("n0"); workSheet.Cells[16, 3] = qty + " " + moduleName; ((Excel.Range)workSheet.Rows[16]).Insert(); } workSheet.Cells[16, 3] = "'* Danh mục thiết bị"; ((Excel.Range)workSheet.Rows[16]).Font.Bold = true; ((Excel.Range)workSheet.Rows[16]).Insert(); ((Excel.Range)workSheet.Rows[16]).Insert(); ((Excel.Range)workSheet.Rows[16]).Insert(); workSheet.Cells[16, 3] = "'* Nội dung thực hành"; ((Excel.Range)workSheet.Rows[16]).Font.Bold = true; ((Excel.Range)workSheet.Rows[16]).Insert(); workSheet.Cells[16, 3] = "'- Xuất xứ: Việt Nam"; ((Excel.Range)workSheet.Rows[16]).Insert(); workSheet.Cells[16, 3] = "'- Hãng sản xuất: TPA"; ((Excel.Range)workSheet.Rows[16]).Insert(); workSheet.Cells[16, 3] = "'- Model: " + moduleCodeP; ((Excel.Range)workSheet.Rows[16]).Insert(); workSheet.Cells[16, 2] = (i + 1); workSheet.Cells[16, 3] = moduleNameP.ToUpper(); workSheet.Cells[16, 4] = moduleCodeP.ToUpper(); workSheet.Cells[16, 5] = hangP; workSheet.Cells[16, 6] = "BỘ"; workSheet.Cells[16, 7] = qtyP.ToString("n0"); workSheet.Cells[16, 8] = sumPrice.ToString("n0"); workSheet.Cells[16, 9] = qtyP * sumPrice; ((Excel.Range)workSheet.Rows[16]).Font.Bold = true; ((Excel.Range)workSheet.Rows[16]).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);// Color.Yellow; ((Excel.Range)workSheet.Rows[16]).Insert(); #endregion } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (app != null) { app.ActiveWorkbook.Save(); app.Workbooks.Close(); app.Quit(); } } if (File.Exists(localPath)) { Process.Start(localPath); } } }
private void thêmNhómVậtTưVàoDMVTToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Multiselect = false; if (ofd.ShowDialog() == DialogResult.OK) { string filePath = ofd.FileName; using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang thêm nhóm vật tư vào DMVT...")) { Excel.Application objXLApp = default(Excel.Application); Excel.Workbook objXLWb = default(Excel.Workbook); Excel.Worksheet objXLWs = default(Excel.Worksheet); try { objXLApp = new Excel.Application(); objXLApp.Workbooks.Open(filePath); objXLWb = objXLApp.Workbooks[1]; objXLWs = (Excel.Worksheet)objXLWb.Worksheets[1]; DataTable dtDMVT = TextUtils.ExcelToDatatableNoHeader(filePath, "DMVT"); dtDMVT = dtDMVT.AsEnumerable() .Where(row => TextUtils.ToInt(row.Field <string>("F1") == "" || row.Field <string>("F1") == null ? "0" : row.Field <string>("F1").Substring(0, 1)) > 0) .CopyToDataTable(); //L-12;M-13 for (int i = 0; i < dtDMVT.Rows.Count; i++) { string partCode = TextUtils.ToString(dtDMVT.Rows[i][3]); if (partCode == "" || partCode.StartsWith("TPAD.")) { continue; } DataTable dtGroup = TextUtils.Select("select * from [vMaterial] with(nolock) where Code = '" + partCode + "'"); string groupCode = ""; string groupName = ""; if (dtGroup.Rows.Count > 0) { groupCode = TextUtils.ToString(dtGroup.Rows[0]["MaterialGroupCode"]); groupName = TextUtils.ToString(dtGroup.Rows[0]["MaterialGroupName"]); objXLWs.Cells[7 + i, 12] = groupCode; objXLWs.Cells[7 + i, 13] = groupName; } } } catch { } finally { objXLApp.ActiveWorkbook.Save(); objXLApp.Workbooks.Close(); objXLApp.Quit(); } } } }
void loadData() { string fcmCode = TextUtils.ToString(cboFCM.EditValue); int year = TextUtils.ToInt(cboYear.SelectedItem); txtTotalVT.EditValue = LibQLSX.ExcuteScalar("select sum(isnull(TotalBuy,0) * isnull(Price,0)) FROM [vRequirePartFull_Order] where ProjectCode = '" + fcmCode + "' and isnull([OrderCode],'') <> ''"); DataTable dtLaiVay = loadLaiVay(fcmCode); DataTable dtMonth = LibIE.Select("select distinct [C_Month] from [V_XNTC_REPORT_ALL] where [C_DTCP_MA] like '" + fcmCode + "%' and [C_YEAR] = " + year); initTable(); string exp = "NamTruoc"; foreach (DataRow row in dtMonth.Rows) { string p = TextUtils.ToString(row["C_Month"]); _dtData.Columns.Add("T_" + p, typeof(decimal)); exp += "+ T_" + p; } foreach (DataRow r in _dtData.Rows) { string sql1 = TextUtils.ToString(r["SqlText1"]); string sql2 = TextUtils.ToString(r["SqlText2"]); if (sql1 == "") { continue; } foreach (DataColumn c in _dtData.Columns) { if (c.ColumnName == "NamTruoc") { if (sql2 == "") { r["NamTruoc"] = TextUtils.ToDecimal(LibIE.ExcuteScalar(sql1 + " and C_DTCP_MA like '" + fcmCode + "%' and [C_Year] < " + year)); } else { r["NamTruoc"] = TextUtils.ToDecimal(LibIE.ExcuteScalar(sql1 + " and C_DTCP_MA like '" + fcmCode + "%' and [C_Year] < " + year)) - TextUtils.ToDecimal(LibIE.ExcuteScalar(sql2 + " and C_DTCP_MA like '" + fcmCode + "%' and [C_Year] < " + year)); } } if (c.ColumnName.StartsWith("T_")) { if (sql2 == "") { r[c.ColumnName] = TextUtils.ToDecimal(LibIE.ExcuteScalar(sql1 + " and C_DTCP_MA like '" + fcmCode + "%' and [C_Year] = " + year + " and [C_Month] = " + c.ColumnName.Replace("T_", ""))); } else { r[c.ColumnName] = TextUtils.ToDecimal(LibIE.ExcuteScalar(sql1 + " and C_DTCP_MA like '" + fcmCode + "%' and [C_Year] = " + year + " and [C_Month] = " + c.ColumnName.Replace("T_", ""))) - TextUtils.ToDecimal(LibIE.ExcuteScalar(sql2 + " and C_DTCP_MA like '" + fcmCode + "%' and [C_Year] = " + year + " and [C_Month] = " + c.ColumnName.Replace("T_", ""))); } } } } #region Nhập chi phí lãi vay thực tế của dự án DataRow[] drsLaiVay = _dtData.Select("STT = 28"); foreach (DataRow r in drsLaiVay) { r["NamTruoc"] = TextUtils.ToDecimal(dtLaiVay.Compute("SUM(LaiGop)", "C_Month <= 12 and C_Year = " + (year - 1)));; foreach (DataRow row in dtMonth.Rows) { int p = TextUtils.ToInt(row["C_Month"]); decimal cLai = TextUtils.ToDecimal(dtLaiVay.Compute("SUM(LaiGop)", "C_Month = " + p + " and C_Year = " + year)); r["T_" + p] = cLai; } } #endregion _dtData.Columns.Add("LuyKe", typeof(decimal), exp); _dtData.Columns.Add("ChenhLech", typeof(decimal), "C_Value - (" + exp + ")"); //_dtData.Columns["PK_ID"].Caption = "PK_ID"; _dtData.Columns["Code"].Caption = "STT"; _dtData.Columns["Name"].Caption = "Tên"; //_dtData.Columns["GroupCode"].Caption = "Nhóm"; _dtData.Columns["C_Value"].Caption = "Tổng tiền"; _dtData.Columns["NamTruoc"].Caption = "Năm trước"; _dtData.Columns["LuyKe"].Caption = "Lũy kế"; _dtData.Columns["ChenhLech"].Caption = "Chênh lệch (DK-TT)"; grvData.PopulateColumns(_dtData); grdData.DataSource = _dtData; grvData.Columns["STT"].Visible = false; grvData.Columns["SqlText1"].Visible = false; grvData.Columns["SqlText2"].Visible = false; for (int i = 4; i < _dtData.Columns.Count; i++) { grvData.Columns[i].DisplayFormat.FormatType = FormatType.Numeric; grvData.Columns[i].DisplayFormat.FormatString = "n0"; } grvData.BestFitColumns(); grvData.Columns["Code"].Fixed = FixedStyle.Left; grvData.Columns["Name"].Fixed = FixedStyle.Left; //grvData.Columns["SqlText1"].Fixed = FixedStyle.Left; //grvData.Columns["SqlText2"].Fixed = FixedStyle.Left; //grvData.Columns["Group"].Fixed = FixedStyle.Left; grvData.Columns["C_Value"].Fixed = FixedStyle.Left; grvData.Columns["NamTruoc"].Fixed = FixedStyle.Left; grvData.Columns["Group"].GroupIndex = 0; grvData.Columns["Group"].Visible = false; grvData.Columns["LuyKe"].AppearanceCell.BackColor = Color.Yellow; grvData.Columns["ChenhLech"].AppearanceCell.BackColor = Color.YellowGreen; grvData.Columns["LuyKe"].SummaryItem.FieldName = "LuyKe"; grvData.Columns["LuyKe"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum; grvData.Columns["LuyKe"].SummaryItem.DisplayFormat = "{0:n0}"; grvData.GroupSummary.Add(DevExpress.Data.SummaryItemType.Sum, "LuyKe", grvData.Columns["LuyKe"], "{0:n0}"); grvData.GroupSummary.Add(DevExpress.Data.SummaryItemType.Sum, "NamTruoc", grvData.Columns["NamTruoc"], "{0:n0}"); foreach (DataRow row in dtMonth.Rows) { string p = TextUtils.ToString(row["C_Month"]); grvData.GroupSummary.Add(DevExpress.Data.SummaryItemType.Sum, "T_" + p, grvData.Columns["T_" + p], "{0:n0}"); grvData.Columns["T_" + p].Width = 90; } grvData.Columns["NamTruoc"].Width = 100; grvData.Columns["Code"].Width = 80; grvData.Columns["LuyKe"].Width = 200; grvData.ExpandAllGroups(); }
void save(bool close) { bool isAdd = false; ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); try { if (!ValidateForm()) { return; } BaiThucHanh.GroupID = TextUtils.ToInt(cboGroup.EditValue); BaiThucHanh.Name = txtName.Text.Trim().ToUpper(); BaiThucHanh.Code = txtCode.Text.Trim().ToUpper(); BaiThucHanh.Description = txtDescription.Text.Trim(); BaiThucHanh.Time = TextUtils.ToDecimal(txtTime.Text.Trim()); BaiThucHanh.RealPrice = TextUtils.ToDecimal(txtRealPrice.Text.Trim()); BaiThucHanh.TradePrice = TextUtils.ToDecimal(txtTradePrice.Text.Trim()); BaiThucHanh.UserPrice = TextUtils.ToDecimal(txtUserPrice.Text.Trim()); if (BaiThucHanh.ID == 0) { isAdd = true; BaiThucHanh.Version = 0; BaiThucHanh.ID = (int)pt.Insert(BaiThucHanh); } else { DialogResult result = MessageBox.Show("Bạn có muốn tạo phiên bản cho bài thực hành này trước khi ghi?", TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { string reason = ""; frmVersionReason frm = new frmVersionReason(); if (frm.ShowDialog() == DialogResult.OK) { reason = frm.Reason; CreateVersion(BaiThucHanh, reason); } } pt.Update(BaiThucHanh); } #region Module chính for (int i = 0; i < grvModule.RowCount; i++) { int id = TextUtils.ToInt(grvModule.GetRowCellValue(i, colMID)); BaiThucHanhModuleModel link; if (id == 0) { link = new BaiThucHanhModuleModel(); } else { link = (BaiThucHanhModuleModel)BaiThucHanhModuleBO.Instance.FindByPK(id); } link.BaiThucHanhID = BaiThucHanh.ID; link.Hang = grvModule.GetRowCellValue(i, colMHang).ToString(); link.Code = grvModule.GetRowCellValue(i, colMCode).ToString(); link.Name = grvModule.GetRowCellValue(i, colMName).ToString(); link.Qty = TextUtils.ToInt(grvModule.GetRowCellValue(i, colMQty)); link.Type = 0; link.CVersion = TextUtils.ToInt(grvModule.GetRowCellValue(i, colMCVersion)); if (id == 0) { link.ID = (int)pt.Insert(link); } else { pt.Update(link); } } #endregion #region Vật tư phụ for (int i = 0; i < grvVT.RowCount; i++) { int id = TextUtils.ToInt(grvVT.GetRowCellValue(i, colMaID)); BaiThucHanhModuleModel link; if (id == 0) { link = new BaiThucHanhModuleModel(); } else { link = (BaiThucHanhModuleModel)BaiThucHanhModuleBO.Instance.FindByPK(id); } link.BaiThucHanhID = BaiThucHanh.ID; link.Hang = grvVT.GetRowCellValue(i, colMaHang).ToString(); link.Code = grvVT.GetRowCellValue(i, colMaCode).ToString(); link.Name = grvVT.GetRowCellValue(i, colMaName).ToString(); link.Qty = TextUtils.ToInt(grvVT.GetRowCellValue(i, colMaQty)); link.Type = 1; link.CVersion = TextUtils.ToInt(grvVT.GetRowCellValue(i, colMaCVersion)); if (id == 0) { pt.Insert(link); } else { pt.Update(link); } } #endregion #region File string ftpFolderPath = "BieuMau\\BaiThucHanh\\" + BaiThucHanh.Code + "\\" + BaiThucHanh.Version; if (!DocUtils.CheckExits(Path.GetDirectoryName(ftpFolderPath))) { DocUtils.MakeDir(Path.GetDirectoryName(ftpFolderPath)); } List <string> listFilePath = new List <string>(); for (int i = 0; i < grvFile.RowCount; i++) { int id = TextUtils.ToInt(grvFile.GetRowCellValue(i, colFileID)); if (id == 0) { BaiThucHanhFileModel file = new BaiThucHanhFileModel(); file.BaiThucHanhID = BaiThucHanh.ID; file.Name = grvFile.GetRowCellValue(i, colFileName).ToString(); file.Length = TextUtils.ToDecimal(grvFile.GetRowCellValue(i, colFileSize).ToString()); file.LocalPath = grvFile.GetRowCellValue(i, colFileLocalPath).ToString(); file.Path = ftpFolderPath + "\\" + Path.GetFileName(file.LocalPath); file.Version = BaiThucHanh.Version; pt.Insert(file); listFilePath.Add(file.LocalPath); } } #endregion pt.CommitTransaction(); if (listFilePath.Count > 0) { foreach (string filePath in listFilePath) { if (!DocUtils.CheckExits(ftpFolderPath)) { DocUtils.MakeDir(ftpFolderPath); } DocUtils.UploadFile(filePath, ftpFolderPath); } } //if (isAdd) //{ // CreateVersion(BaiThucHanh); //} _isSaved = true; if (close) { this.DialogResult = DialogResult.OK; } else { loadGridMaterial(); loadGridModule(); loadGridFile(); MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { pt.CloseConnection(); } }
DataTable loadLaiVay(string projectCode) { DataTable dtTime = LibIE.Select("SELECT distinct [C_Month],[C_Year] FROM [tanphat].[dbo].V_XNTC_REPORT_ALL" + " where (FK_TKCO like '131%' or [FK_TKNO] like '331%') and [C_DTCP_MA] like '" + projectCode + "%' " + " order by [C_Year],[C_Month]"); DataTable dtLaiVay = LibIE.Select("SELECT [C_NGAYLAP],[FK_TKNO],[C_Month] ,[C_Year],sum([C_PSNO]) as [C_PSNO],0.00 as Total, 0.00 as Lai, 0.00 as LaiGop, 0.00 as TongLai FROM [tanphat].[dbo].V_XNTC_REPORT_ALL" + " where (FK_TKCO like '131%' or [FK_TKNO] like '331%') and [C_DTCP_MA] like '" + projectCode + "%'" + " group by [C_NGAYLAP],[FK_TKNO],[C_Month],[C_Year]" + " order by [C_NGAYLAP]"); foreach (DataRow r in dtTime.Rows) { int month = TextUtils.ToInt(r["C_Month"]); int year = TextUtils.ToInt(r["C_Year"]); int days = DateTime.DaysInMonth(year, month); DateTime cuoiThang = new DateTime(year, month, days); dtLaiVay.Rows.Add(cuoiThang, "331", month, year, 0, 0, 0, 0); } DataRow[] dataRows = dtLaiVay.Select().OrderBy(u => u["C_NGAYLAP"]).ToArray(); if (dataRows.Length == 0) { return(dtLaiVay); } else { dtLaiVay = dataRows.CopyToDataTable(); } decimal per = 0.07m / 365m; decimal total = 0; for (int i = 0; i < dtLaiVay.Rows.Count; i++) { string tk = TextUtils.ToString(dtLaiVay.Rows[i]["FK_TKNO"]); DateTime ngayLap = TextUtils.ToDate3(dtLaiVay.Rows[i]["C_NGAYLAP"]); if (tk.StartsWith("331")) { total += TextUtils.ToDecimal(dtLaiVay.Rows[i]["C_PSNO"]); } else { total -= TextUtils.ToDecimal(dtLaiVay.Rows[i]["C_PSNO"]); } dtLaiVay.Rows[i]["Total"] = total; dtLaiVay.Rows[i]["Lai"] = per * total; if (i == 0) { dtLaiVay.Rows[i]["TongLai"] = per * total; dtLaiVay.Rows[i]["LaiGop"] = per * total; } else { DateTime ngayLapTruoc = TextUtils.ToDate3(dtLaiVay.Rows[i - 1]["C_NGAYLAP"]); decimal laiTruoc = TextUtils.ToDecimal(dtLaiVay.Rows[i - 1]["Lai"]); decimal tongLaiTruoc = TextUtils.ToDecimal(dtLaiVay.Rows[i - 1]["TongLai"]); TimeSpan ts = ngayLap - ngayLapTruoc; decimal tongLai = (ts.Days - 1) * laiTruoc + per * total + tongLaiTruoc; dtLaiVay.Rows[i]["TongLai"] = tongLai; dtLaiVay.Rows[i]["LaiGop"] = (ts.Days - 1) * laiTruoc + per * total; } } return(dtLaiVay); }
void loadStaff() { try { DataTable tbl = TextUtils.Select("Select a.* from Users a with(nolock) where Status = 0 and a.DepartmentID = " + TextUtils.ToInt(leDepartment.EditValue)); grdData.DataSource = tbl; grvData.BestFitColumns(); } catch (Exception) { } }
/// <summary> /// F12 is Save /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void saveToolStripMenuItem_Click(object sender, EventArgs e) { if (txtOrderNo.Text.Trim() == "") { MessageBox.Show("Bạn chưa nhập Order", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (TextUtils.ToInt(txtQty.Text.Trim()) == 0) { MessageBox.Show("Bạn chưa nhập Số lượng", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (txtLAP.Text.Trim() == "") { MessageBox.Show("Bạn chưa nhập TESTTA LAP", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (txtWorkerName.Text.Trim() == "") { MessageBox.Show("Bạn chưa nhập Người gia công", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (txtMeasureName.Text.Trim() == "") { MessageBox.Show("Bạn chưa nhập Người đo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (txtLeader.Text.Trim() == "") { MessageBox.Show("Bạn chưa nhập Leader", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // hiện thị messagebox về việc lưu dữ liệu DialogResult rs = MessageBox.Show("Bạn muốn lưu dữ liệu?", "Lưu dữ liệu", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (rs == DialogResult.Cancel) { return; } // thực hiện lấy giá trị trên form for (int i = 0; i < _qty; i++) { TesttaModel tModel = new TesttaModel(); tModel.ID = TextUtils.ToInt(grvData.Rows[i].Cells[colID.Name].Value); tModel.Number = TextUtils.ToInt(grvData.Rows[i].Cells[colNumber.Name].Value); tModel.ClockDial11 = TextUtils.ToDecimal(grvData.Rows[i].Cells[colClockDial11.Name].Value); tModel.ClockDial12 = TextUtils.ToDecimal(grvData.Rows[i].Cells[colClockDial12.Name].Value); tModel.VibrationForward1 = TextUtils.ToDecimal(grvData.Rows[i].Cells[colVibrationForward1.Name].Value); tModel.VibrationReverse1 = TextUtils.ToDecimal(grvData.Rows[i].Cells[colVibrationReverse1.Name].Value); tModel.CheckEye11 = TextUtils.ToString(grvData.Rows[i].Cells[colCheckEye11.Name].Value); tModel.CheckEye12 = TextUtils.ToString(grvData.Rows[i].Cells[colCheckEye12.Name].Value); tModel.Result1 = TextUtils.ToString(grvData.Rows[i].Cells[colResult1.Name].Value); tModel.Vibrate11 = TextUtils.ToDecimal(grvData.Rows[i].Cells[colVibrate11.Name].Value); tModel.Vibrate12 = TextUtils.ToDecimal(grvData.Rows[i].Cells[colVibrate12.Name].Value); tModel.Vibrate13 = TextUtils.ToDecimal(grvData.Rows[i].Cells[colVibrate13.Name].Value); tModel.ClockDial21 = TextUtils.ToDecimal(grvData.Rows[i].Cells[colClockDial21.Name].Value); tModel.ClockDial22 = TextUtils.ToDecimal(grvData.Rows[i].Cells[colClockDial22.Name].Value); tModel.VibrationForward2 = TextUtils.ToDecimal(grvData.Rows[i].Cells[colVibrationForward2.Name].Value); tModel.VibrationReverse2 = TextUtils.ToDecimal(grvData.Rows[i].Cells[colVibrationReverse2.Name].Value); tModel.CheckEye21 = TextUtils.ToString(grvData.Rows[i].Cells[colCheckEye21.Name].Value); tModel.CheckEye22 = TextUtils.ToString(grvData.Rows[i].Cells[colCheckEye22.Name].Value); tModel.Result2 = TextUtils.ToString(grvData.Rows[i].Cells[colResult2.Name].Value); tModel.Vibrate21 = TextUtils.ToDecimal(grvData.Rows[i].Cells[colVibrate21.Name].Value); tModel.Vibrate22 = TextUtils.ToDecimal(grvData.Rows[i].Cells[colVibrate22.Name].Value); tModel.Vibrate23 = TextUtils.ToDecimal(grvData.Rows[i].Cells[colVibrate23.Name].Value); tModel.OrderCode = txtOrderNo.Text.Trim(); tModel.DateWork = dteNgayGiaCong.Value.Date; tModel.WorkerName = txtWorkerName.Text.Trim(); tModel.MeasureName = txtMeasureName.Text.Trim(); tModel.Leader = txtLeader.Text.Trim(); // nếu ID = 0 thì thực hiện insert dữ liệu lên Database if (tModel.ID == 0) { TesttaBO.Instance.Insert(tModel); } // ID khác 0 thực hiện update dữ liệu lên DataBase else { TesttaBO.Instance.Update(tModel); } } txtOrderNo.Text = ""; LoadData(); //MessageBox.Show("Đã hoàn thành việc lưu dữ liệu", "Hoàn thành", MessageBoxButtons.OK, MessageBoxIcon.Information); }
void sendMail() { if (ErrorModel.DepartmentID == 1)//Phong TK { //ModulesModel product = (ModulesModel)ModulesBO.Instance.FindByAttribute("Code", cboModule.EditValue.ToString())[0]; ModulesModel product = (ModulesModel)ModulesBO.Instance.FindByPK(TextUtils.ToInt(cboModule.EditValue)); string productCode = product.Code; List <string> listEmail = getListMail(productCode); #region Mở outlook int count = Process.GetProcesses().Where(o => o.ProcessName.Contains("OUTLOOK")).Count(); if (count == 0) { try { Process.Start("outlook.exe"); } catch (Exception) { } } #endregion Mở outlook string subject = string.Format("ERROR REPORT - {0} - {1}", ErrorModel.Code, productCode); string content = "Mã lỗi: <b>" + ErrorModel.Code + "</b><br>" + "Mã dự án: <b>" + cboProject.EditValue.ToString() + "<b><br>" + "Mã sản phẩm: <b>" + productCode + "<b><br>" + "Tên sản phẩm: <b>" + product.Name + "<b><br>" + "Mô tả lỗi: " + ErrorModel.Description + "<br>" + "Hình ảnh lỗi: <a>" + ErrorModel.FolderPathError + "</a>" + "<br>" + "Danh sách nhân viên thiết kế: " + "<br>" + "Thiết kế cơ khí: " + NVCoKhi + "<br>" + "Thiết kế điện: " + NVDien + "<br>" + "Thiết kế điện tử: " + NVDT ; string to = ""; foreach (string item in listEmail) { to += item.ToLower() + ";"; } frmSendEmailAttach frm = new frmSendEmailAttach(); frm.Subject = subject; frm.CC = "*****@*****.**"; frm.To = to; frm.Content = content; TextUtils.OpenForm(frm); //bool success = TextUtils.SetEmailSend(subject, content, to.Substring(0, to.Length - 1), "*****@*****.**"); //if (!success) //{ // TextUtils.SetEmailSend(subject, content, "*****@*****.**", ""); //} } }