private void btnDelete_Click(object sender, EventArgs e) { if (!grvData.IsDataRow(grvData.FocusedRowHandle)) { return; } int ID = TextUtils.ToInt(grvData.GetRowCellValue(grvData.FocusedRowHandle, "ID")); string sTime = TextUtils.ToDate3(grvData.GetRowCellValue(grvData.FocusedRowHandle, "ShiftStartTime")).ToString("yyyy/MM/dd HH:mm"); string eTime = TextUtils.ToDate3(grvData.GetRowCellValue(grvData.FocusedRowHandle, "ShiftEndTime")).ToString("yyyy/MM/dd HH:mm"); DialogResult result = MessageBox.Show(String.Format("Are you want to delete a shift {0} - {1} ?", sTime, eTime), TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { return; } try { AndonBO.Instance.Delete(ID); LoadData(); } catch (Exception) { MessageBox.Show("An error occurred during processing, please try again later!"); } }
private bool checkValid() { if (TextUtils.ToDate3(nbdCNC.EditValue).Date > TextUtils.ToDate3(nktCNC.EditValue).Date) { MessageBox.Show("Ngày Deadline CNC không thể lớn hơn ngày dự kiến.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } else if (TextUtils.ToDate3(nbdGCN.EditValue).Date > TextUtils.ToDate3(nktGCN.EditValue).Date) { MessageBox.Show("Ngày Deadline GCN không thể lớn hơn ngày dự kiến.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } else if (TextUtils.ToDate3(nbdDT.EditValue).Date > TextUtils.ToDate3(nktDT.EditValue).Date) { MessageBox.Show("Ngày Deadline Điện tử không thể lớn hơn ngày dự kiến.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } else if (TextUtils.ToDate3(nbdIN.EditValue).Date > TextUtils.ToDate3(nktIN.EditValue).Date) { MessageBox.Show("Ngày Deadline In không thể lớn hơn ngày dự kiến.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } else if (TextUtils.ToDate3(nbdLr.EditValue).Date > TextUtils.ToDate3(nktLr.EditValue).Date) { MessageBox.Show("Ngày Deadline Lắp ráp không thể lớn hơn ngày dự kiến.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } return(true); }
private void cbxShiftType_SelectedIndexChanged(object sender, EventArgs e) { if (cbxShiftType.SelectedItem == null) { return; } if (_isAdd) { DataRowView shift = cbxShiftType.SelectedItem as DataRowView; //ShiftModel m = pickerStartTime.Value = TextUtils.ToDate3(shift.Row["StartTime"]); pickerEndTime.Value = TextUtils.ToDate3(shift.Row["EndTime"]); pickerStartBreak1.Value = TextUtils.ToDate3(shift.Row["StartTimeBreak1"]); pickerEndBreak1.Value = TextUtils.ToDate3(shift.Row["EndTimeBreak1"]); pickerStartBreak2.Value = TextUtils.ToDate3(shift.Row["StartTimeBreak2"]); pickerEndBreak2.Value = TextUtils.ToDate3(shift.Row["EndTimeBreak2"]); pickerStartBreak3.Value = TextUtils.ToDate3(shift.Row["StartTimeBreak3"]); pickerEndBreak3.Value = TextUtils.ToDate3(shift.Row["EndTimeBreak3"]); pickerStartBreak4.Value = TextUtils.ToDate3(shift.Row["StartTimeBreak4"]); pickerEndBreak4.Value = TextUtils.ToDate3(shift.Row["EndTimeBreak4"]); DateTime[] dateTimes = loadDateTime(pickerStartDate.Value, pickerStartTime.Value, pickerEndTime.Value, pickerStartBreak1.Value, pickerEndBreak1.Value, pickerStartBreak2.Value, pickerEndBreak2.Value, pickerStartBreak3.Value, pickerEndBreak3.Value, pickerStartBreak4.Value, pickerEndBreak4.Value); changePlanDay(dateTimes[0], dateTimes[1], dateTimes[2], dateTimes[3], dateTimes[4], dateTimes[5], dateTimes[6], dateTimes[7], dateTimes[8], dateTimes[9]); } }
private void dtpEndDate_EditValueChanged(object sender, EventArgs e) { if (dtpEndDate.EditValue == null && dtpStartDate.EditValue == null) { return; } txtTotalTime.Text = ((TextUtils.ToDate3(dtpEndDate.EditValue).AddDays(1) - TextUtils.ToDate3(dtpStartDate.EditValue)).Days * 8).ToString(); }
void loadStockCDDetail() { txtCDName.Text = _StockCD.CDName; txtCDCode.Text = _StockCD.CDCode; cboStockName.Text = _Stock.Name; txtTaktTime.Value = TextUtils.ToDate3(_StockCD.TaktTime); txtLocation.Text = _StockCD.NameLocation.Split('%')[0]; }
private void treeData_NodeCellStyle(object sender, GetCustomNodeCellStyleEventArgs e) { //if (_isStyle) return; decimal percentVT = TextUtils.ToDecimal(e.Node.GetValue(colPercentVT)); decimal qty = TextUtils.ToDecimal(e.Node.GetValue(colQty)); if (e.Column == colPercentExport || e.Column == colPercentVT) { decimal percentExport = TextUtils.ToDecimal(e.Node.GetValue(colPercentExport)); if (percentVT >= 100 && percentExport >= 100) { e.Appearance.BackColor = Color.GreenYellow; } if (percentVT >= 100 && percentExport < 100) { e.Appearance.BackColor = Color.Yellow; } //if (percentVT == 0 && qty == 0) //{ // e.Appearance.BackColor = Color.MediumTurquoise; //} } if (e.Column == colDateAboutE && percentVT < 100) { if (qty == 0) { return; } if (TextUtils.ToDate3(e.Node.GetValue(colDateAboutE)).Date > TextUtils.ToDate3(dtpSXLRDeadline.EditValue).Date) { e.Appearance.BackColor = Color.Red; } else { if (TextUtils.ToInt(e.Node.GetValue(colTotalDateAboutENull)) > 0) { e.Appearance.BackColor = Color.Orange; } } } if (e.Column == colIN || e.Column == colCNC || e.Column == colPCB || e.Column == colGCAL || e.Column == colLR) { string date = TextUtils.ToString(e.Node.GetValue(e.Column)); if (date.Contains("-")) { DateTime dateDK = TextUtils.ToDate(date); if (DateTime.Now.Date > dateDK.Date) { e.Appearance.BackColor = Color.Red; } } } //_isStyle = true; }
private void grvData_DoubleClick(object sender, EventArgs e) { if (grvData.RowCount > 0) { frmHistoryCheckDetail frm = new frmHistoryCheckDetail(); frm.QRCode = TextUtils.ToString(grvData.GetFocusedRowCellValue(colQRCode)); frm.DateLR = TextUtils.ToDate3(grvData.GetFocusedRowCellValue(colDateLR)); frm.Show(); } }
private void btnShowWorking_Click(object sender, EventArgs e) { if (grvData.RowCount > 0) { frmHistoryCheckOrderDetailH frm = new frmHistoryCheckOrderDetailH(); frm._QRCode = TextUtils.ToString(grvData.GetFocusedRowCellValue(colQRCode)); frm._DateLR = TextUtils.ToDate3(grvData.GetFocusedRowCellValue(colDateLR)); frm._OrderCode = TextUtils.ToString(grvData.GetFocusedRowCellValue(colOrderCode)); frm.Show(); } }
void changeEndDateTime(DateTime startDate, DateTime startTime) { DataRowView r = cbxShiftType.SelectedItem as DataRowView; if (r != null) { int shiftHour = TextUtils.ToDate3(r.Row["TotalTime"]).Hour; DateTime dateTimeEnd = startDate.Date.AddHours(startTime.Hour).AddMinutes(startTime.Minute).AddHours(shiftHour); pickerEndDate.Value = dateTimeEnd; pickerEndTime.Value = dateTimeEnd; } }
void loadCurrentVersion() { string sql = "select top 1 * from BackupVersion where IsUse = 1"; DataTable dt = TextUtils.Select(sql); if (dt.Rows.Count == 0) { this.Text += $" - Dữ liệu đang xem trống. Bạn hãy chọn dữ liệu muốn xem."; return; } this.Text += $" - Dữ liệu đang xem từ {TextUtils.ToDate3(dt.Rows[0]["StartDate"]).ToString("dd/MM/yyyy")} " + $"đến {TextUtils.ToDate3(dt.Rows[0]["EndDate"]).ToString("dd/MM/yyyy")}"; }
private void LoadDataTestlerByOrder(string order) { // load data từ store DataSet dts = TextUtils.GetListDataFromSP("spGetResultData_ByOrderCode" , new string[1] { "@OrderCode" } , new object[1] { order }); DataTable dataTable0 = new DataTable(); DataTable dataTable1 = new DataTable(); if (dts.Tables.Count > 1) { dataTable0 = dts.Tables[0]; dataTable1 = dts.Tables[1]; } // kieeemr tra table 0 if (dataTable0.Rows.Count > 0) { //nếu có thì binding dữ liệu vào các control dạng text txtOrderNo.Text = _Order; txtWorkerName.Text = TextUtils.ToString(dataTable0.Rows[0]["WorkerCode"]); txtHYP.Text = TextUtils.ToString(dataTable0.Rows[0]["HypCode"]); txtQty.Text = TextUtils.ToString(dataTable0.Rows[0]["Qty"]); dteNgayGiaCong.Value = TextUtils.ToDate3(dataTable0.Rows[0]["DateLR"]); txtBatch.Text = TextUtils.ToString(dataTable0.Rows[0]["Batch"]); txtConfirmer.Text = TextUtils.ToString(dataTable0.Rows[0]["Confirmer"]); lblTester.Text = TextUtils.ToString(dataTable0.Rows[0]["TesterName"]); _sttStart = (TextUtils.ToInt(dataTable0.Rows[0]["SttStart"])); _hypCode = txtHYP.Text.Trim(); loadGear(_hypCode); GenerateByQty(); //binding table 1 vào grid if (dataTable1.Rows.Count > 0) { bindingDataRow(dataTable1); checkAudioImageExist(); } } else { // focus khi không load đc order trong db txtConfirmer.Focus(); } }
private void btnEdit_Click(object sender, EventArgs e) { if (!grvData.IsDataRow(grvData.FocusedRowHandle)) { return; } SetInterface(true); _isAdd = false; txtPlanDay.Text = TextUtils.ToString(grvData.GetRowCellValue(grvData.FocusedRowHandle, "QtyPlanDay")); txtTakt.Text = TextUtils.ToString(grvData.GetRowCellValue(grvData.FocusedRowHandle, "Takt")); pickerStartDate.Value = TextUtils.ToDate3(grvData.GetRowCellValue(grvData.FocusedRowHandle, "ShiftStartTime")); pickerStartTime.Value = TextUtils.ToDate3(grvData.GetRowCellValue(grvData.FocusedRowHandle, "ShiftStartTime")); pickerEndDate.Value = TextUtils.ToDate3(grvData.GetRowCellValue(grvData.FocusedRowHandle, "ShiftEndTime")); pickerEndTime.Value = TextUtils.ToDate3(grvData.GetRowCellValue(grvData.FocusedRowHandle, "ShiftEndTime")); cbxShiftType.SelectedValue = TextUtils.ToInt(grvData.GetRowCellValue(grvData.FocusedRowHandle, "ShiftID")); }
private void btnDeadlineSXLR_Click(object sender, EventArgs e) { string projectCode = TextUtils.ToString(grvProject.GetFocusedRowCellValue(colProjectCode)); if (dtpSXLRDeadline.EditValue != null && projectCode != "") { DateTime date = TextUtils.ToDate3(dtpSXLRDeadline.EditValue); LibQLSX.ExcuteSQL("update Project set AssemblyDeadline = '" + date.Year + "-" + date.Month + "-" + date.Day + "' where [ProjectCode] = '" + projectCode + "'"); string id = TextUtils.ToString(cboProject.EditValue); loadProject(); cboProject.EditValue = id; MessageBox.Show("Thay đổi deadline SXLR thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
bool saveData() { if (!ValidateForm()) { return(false); } ProductionPlan.Stt = TextUtils.ToInt(txtStt.Text); ProductionPlan.AssemblyProduct = txtAssembly.Text.Trim(); ProductionPlan.JgDate = TextUtils.ToDate3(dtpJgDate.Value); ProductionPlan.OrderCode = txtOrderCode.Text.Trim(); ProductionPlan.Cnt = TextUtils.ToInt(txtCnt.Text); ProductionPlan.ProductCode = txtProductcode.Text.Trim(); ProductionPlan.Description = txtDescription.Text.Trim(); ProductionPlan.Qty = TextUtils.ToInt(txtQty.Text); ProductionPlan.SalesOrder = txtSalesOrder.Text.Trim(); ProductionPlan.ShipTo = txtShipTo.Text.Trim(); ProductionPlan.SVia = txtSVia.Text.Trim(); ProductionPlan.Note = txtNote.Text.Trim(); ProductionPlan.Code = txtCode.Text.Trim(); ProductionPlan.OrderNew = txtOrderNew.Text.Trim(); ProductionPlan.ProductCodeNew = txtProductCodeNew.Text.Trim(); ProductionPlan.RequestDate = TextUtils.ToDate3(dtpRequestDate.Value); ProductionPlan.MaMoto = txtMaMoto.Text.Trim(); ProductionPlan.MaMoto1 = txtMaMoto1.Text.Trim(); ProductionPlan.DeliveryDate = TextUtils.ToDate3(dtpDeliveryDate.Value); ProductionPlan.AssemblyDate = TextUtils.ToDate3(dtpAssemblyDate.Value); ProductionPlan.OrderCodeFull = txtOrderCode.Text.Trim() + txtCnt.Text.Trim(); ProductionPlan.Prints = checkPrints.Checked; if (ProductionPlan.ID > 0) { ProductionPlan.UpdatedAt = DateTime.Now; ProductionPlanBO.Instance.Update(ProductionPlan); MessageBox.Show("Update thành công").ToString(); } else { ProductionPlan.CreatedAt = DateTime.Now; ProductionPlan.UpdatedAt = DateTime.Now; ProductionPlanBO.Instance.Insert(ProductionPlan); MessageBox.Show("Thêm mới thành công").ToString(); } return(true); }
private void grvData_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e) { decimal percentVT = TextUtils.ToDecimal(grvData.GetRowCellValue(e.RowHandle, colPercentVT)); decimal qty = TextUtils.ToDecimal(grvData.GetRowCellValue(e.RowHandle, colQty)); if (e.Column == colPercentExport || e.Column == colPercentVT) { decimal percentExport = TextUtils.ToDecimal(grvData.GetRowCellValue(e.RowHandle, colPercentExport)); if (percentVT >= 100 && percentExport >= 100) { e.Appearance.BackColor = Color.GreenYellow; } if (percentVT >= 100 && percentExport < 100) { e.Appearance.BackColor = Color.Yellow; } //if (percentVT == 0) //{ // e.Appearance.BackColor = Color.MediumTurquoise; //} } if (e.Column == colDateAboutE && percentVT < 100) { if (qty == 0) { return; } if (TextUtils.ToDate3(grvData.GetRowCellValue(e.RowHandle, colDateAboutE)).Date > TextUtils.ToDate3(dtpSXLRDeadline.EditValue).Date) { e.Appearance.BackColor = Color.Red; } else { if (TextUtils.ToInt(grvData.GetRowCellValue(e.RowHandle, colTotalDateAboutENull)) > 0) { e.Appearance.BackColor = Color.Orange; } } } }
private void btnEdit_Click(object sender, EventArgs e) { if (!grvData.IsDataRow(grvData.FocusedRowHandle)) { return; } SetInterface(true); _isAdd = false; txtName.Text = TextUtils.ToString(grvData.GetRowCellValue(grvData.FocusedRowHandle, "Name")); pickerStart.Value = TextUtils.ToDate3(grvData.GetRowCellValue(grvData.FocusedRowHandle, "StartTime")); pickerEnd.Value = TextUtils.ToDate3(grvData.GetRowCellValue(grvData.FocusedRowHandle, "EndTime")); pickerStartBreak1.Value = TextUtils.ToDate3(grvData.GetRowCellValue(grvData.FocusedRowHandle, "StartTimeBreak1")); pickerEndBreak1.Value = TextUtils.ToDate3(grvData.GetRowCellValue(grvData.FocusedRowHandle, "EndTimeBreak1")); pickerStartBreak2.Value = TextUtils.ToDate3(grvData.GetRowCellValue(grvData.FocusedRowHandle, "StartTimeBreak2")); pickerEndBreak2.Value = TextUtils.ToDate3(grvData.GetRowCellValue(grvData.FocusedRowHandle, "EndTimeBreak2")); pickerStartBreak3.Value = TextUtils.ToDate3(grvData.GetRowCellValue(grvData.FocusedRowHandle, "StartTimeBreak3")); pickerEndBreak3.Value = TextUtils.ToDate3(grvData.GetRowCellValue(grvData.FocusedRowHandle, "EndTimeBreak3")); pickerStartBreak4.Value = TextUtils.ToDate3(grvData.GetRowCellValue(grvData.FocusedRowHandle, "StartTimeBreak4")); pickerEndBreak4.Value = TextUtils.ToDate3(grvData.GetRowCellValue(grvData.FocusedRowHandle, "EndTimeBreak4")); }
void changeEndDateTime(DateTime startDate, DateTime startTime) { if (cbxShiftType.SelectedItem == null) { return; } DataRowView shift = cbxShiftType.SelectedItem as DataRowView; DateTime sTime = TextUtils.ToDate3(shift.Row["StartTime"]); DateTime eTime = TextUtils.ToDate3(shift.Row["EndTime"]); // check thời gian bắt đầu ca và thời gian kết thúc ca trong bảng Shift // trường hợp thời gian bắt đầu > thời gian kết thúc thì hiểu là thời gian kết thúc đã sang ngày khác if (sTime > eTime) { eTime = eTime.AddDays(1); } TimeSpan span = eTime - sTime; DateTime dateTimeStart = startDate.Date.AddHours(startTime.Hour).AddMinutes(startTime.Minute); DateTime dateTimeEnd = dateTimeStart.AddMinutes(span.TotalMinutes); pickerEndTime.Value = dateTimeEnd; }
void loadData() { txtStt.Text = TextUtils.ToString(ProductionPlan.Stt); txtProductcode.Text = ProductionPlan.ProductCode; txtAssembly.Text = ProductionPlan.AssemblyProduct; dtpJgDate.Value = TextUtils.ToDate3(ProductionPlan.JgDate); txtOrderCode.Text = ProductionPlan.OrderCode; txtCnt.Text = TextUtils.ToString(ProductionPlan.Cnt); txtDescription.Text = ProductionPlan.Description; txtQty.Text = TextUtils.ToString(ProductionPlan.Qty); txtSalesOrder.Text = ProductionPlan.SalesOrder; txtShipTo.Text = ProductionPlan.ShipTo; txtSVia.Text = ProductionPlan.SVia; txtNote.Text = ProductionPlan.Note; txtOrderNew.Text = ProductionPlan.OrderNew; txtProductCodeNew.Text = ProductionPlan.ProductCodeNew; txtCode.Text = ProductionPlan.Code; dtpRequestDate.Value = TextUtils.ToDate3(ProductionPlan.RequestDate);; txtMaMoto.Text = ProductionPlan.MaMoto; txtMaMoto1.Text = ProductionPlan.MaMoto1; dtpDeliveryDate.Value = TextUtils.ToDate3(ProductionPlan.DeliveryDate); dtpAssemblyDate.Value = TextUtils.ToDate3(ProductionPlan.AssemblyDate); checkPrints.Checked = ProductionPlan.Prints; }
private void btnSave_Click(object sender, EventArgs e) { ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); try { if (!ValidateForm()) { return; } Model.BankAccount = txtBankAccount.Text.Trim(); Model.BHXH = txtBHXH.Text.Trim(); Model.BHYT = txtBHYT.Text.Trim(); try { Model.BirthOfDate = TextUtils.ToDate3(dtpBirthOfDate.EditValue); } catch { Model.BirthOfDate = DateTime.Now; } Model.CMTND = txtCMTND.Text.Trim(); Model.Code = txtCode.Text.Trim(); Model.DepartmentID = TextUtils.ToInt(cboDepartment.SelectedValue); Model.Email = txtEmail.Text.Trim(); Model.EmailCom = txtEmailCom.Text.Trim(); Model.FullName = txtFullName.Text; Model.HandPhone = txtTelephone.Text; Model.HomeAddress = txtHomeAddress.Text; Model.JobDescription = txtJobDescription.Text.Trim(); Model.MST = txtMST.Text.Trim(); Model.Position = txtPosition.Text; Model.Qualifications = txtQualifications.Text.Trim(); Model.Sex = cboSex.SelectedIndex; Model.UserGroupID = TextUtils.ToInt(lookUpEdit1.EditValue); Model.UserGroupSXID = TextUtils.ToInt(cboGroup.EditValue); try { Model.StartWorking = TextUtils.ToDate3(dtpStartWorking.EditValue); } catch { Model.StartWorking = DateTime.Now; } Model.ImagePath = pictureBox1.ImageLocation; Model.Status = cboStatus.SelectedIndex; if (chkHasUser.Checked) { Model.LoginName = txtLoginName.Text.Trim(); Model.PasswordHash = MD5.EncryptPassword(txtPasswordHash.Text.Trim()); } else { Model.LoginName = ""; Model.PasswordHash = ""; } Model.UpdatedDate = Model.CreatedDate; Model.UpdatedBy = Global.AppUserName; if (Model.ID == 0) { Model.CreatedDate = TextUtils.GetSystemDate(); Model.CreatedBy = Global.AppUserName; Model.ID = (int)pt.Insert(Model); } else { pt.Update(Model); } pt.CommitTransaction(); //Update mã nhân viên cho bên QLSX if (Model.LoginName != "") { string pId = TextUtils.ToString(TextUtils.ExcuteScalar("select top 1 PId from [Department] with(nolock) where ID = " + TextUtils.ToInt(cboDepartment.SelectedValue))); LibQLSX.ExcuteSQL("update Users set Code = '" + Model.Code + "', UserGroup1ID = " + Model.UserGroupSXID + ", [DepartmentId1]= '" + pId + "' where Account = '" + Model.LoginName + "'"); } MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); if (this.LoadDataChange != null) { this.LoadDataChange(null, null); } } 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); }
private void btnReport_Click(object sender, EventArgs e) { if (cboYear.SelectedItem == null) { return; } string path = ""; FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { path = fbd.SelectedPath; } else { return; } string filePath = Application.StartupPath + "\\Templates\\PhongSXLR\\BaoCaoChatLuongVT.xlsx"; string currentPath = path + "\\BaoCaoChatLuongVT-" + TextUtils.ToInt(cboYear.SelectedItem) + ".xlsx"; try { File.Copy(filePath, currentPath, true); } catch (Exception ex) { MessageBox.Show("Có lỗi khi tạo biểu mẫu!" + Environment.NewLine + ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang tạo biểu mẫu...")) { //string sql = string.Format("select * from vImportMaterial a with(nolock) where (a.Status >= 3) and a.DateKCS is not null and a.Year = {0} {1} order by a.Year" // , TextUtils.ToInt(cboYear.SelectedItem), cboMonth.SelectedIndex > 0 ? " and a.Month = " + cboMonth.SelectedIndex : ""); string sql = string.Format("Exec spReportPartQuanlityNew {0},{1}", TextUtils.ToInt(cboYear.SelectedItem), cboMonth.SelectedIndex); DataTable dt = LibQLSX.Select(sql); if (dt.Rows.Count == 0) { return; } 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]; for (int i = dt.Rows.Count - 1; i >= 0; i--) { workSheet.Cells[4, 1] = i + 1; workSheet.Cells[4, 2] = TextUtils.ToString(dt.Rows[i]["PartsName"]); workSheet.Cells[4, 3] = TextUtils.ToString(dt.Rows[i]["PartsCode"]); workSheet.Cells[4, 4] = TextUtils.ToString(dt.Rows[i]["Specifications"]); workSheet.Cells[4, 5] = TextUtils.ToString(dt.Rows[i]["ManufacturerCode"]); workSheet.Cells[4, 6] = TextUtils.ToString(dt.Rows[i]["ProjectCode"]); workSheet.Cells[4, 7] = TextUtils.ToString(dt.Rows[i]["ProjectModuleCode"]); workSheet.Cells[4, 8] = TextUtils.ToString(dt.Rows[i]["ProposalCode"]); workSheet.Cells[4, 9] = TextUtils.ToString(dt.Rows[i]["OrderCode"]); workSheet.Cells[4, 10] = TextUtils.ToString(dt.Rows[i]["ImportCode"]); workSheet.Cells[4, 11] = TextUtils.ToDecimal(dt.Rows[i]["Total"]); workSheet.Cells[4, 12] = TextUtils.ToDecimal(dt.Rows[i]["TotalKCS"]); workSheet.Cells[4, 13] = TextUtils.ToDecimal(dt.Rows[i]["TotalOK"]); //workSheet.Cells[4, 14] = TextUtils.ToDecimal(dt.Rows[i]["TotalNG"]);TotalNGReal workSheet.Cells[4, 14] = TextUtils.ToDecimal(dt.Rows[i]["TotalNGReal"]); workSheet.Cells[4, 15] = TextUtils.ToDecimal(dt.Rows[i]["Total"]) - TextUtils.ToDecimal(dt.Rows[i]["TotalKCS"]); workSheet.Cells[4, 16] = TextUtils.ToString(dt.Rows[i]["UserNameKCS"]); workSheet.Cells[4, 17] = TextUtils.ToString(dt.Rows[i]["UserNameDNNK"]); workSheet.Cells[4, 18] = TextUtils.ToString(dt.Rows[i]["SupplierCode"]) + " - " + TextUtils.ToString(dt.Rows[i]["SupplierName"]); workSheet.Cells[4, 19] = dt.Rows[i]["DateCreate"] == null ? "" : TextUtils.ToDate3(dt.Rows[i]["DateCreate"]).ToString("dd/MM/yyyy"); workSheet.Cells[4, 20] = dt.Rows[i]["DateKCS"] == null ? "" : TextUtils.ToDate3(dt.Rows[i]["DateKCS"]).ToString("dd/MM/yyyy"); workSheet.Cells[4, 21] = dt.Rows[i]["DateAboutE"] == null ? "" : TextUtils.ToDate3(dt.Rows[i]["DateAboutE"]).ToString("dd/MM/yyyy"); workSheet.Cells[4, 22] = dt.Rows[i]["DateAboutF"] == null ? "" : TextUtils.ToDate3(dt.Rows[i]["DateAboutF"]).ToString("dd/MM/yyyy"); workSheet.Cells[4, 23] = ""; workSheet.Cells[4, 24] = TextUtils.ToDecimal(dt.Rows[i]["Price"]); workSheet.Cells[4, 25] = TextUtils.ToDecimal(dt.Rows[i]["Total"]) * TextUtils.ToDecimal(dt.Rows[i]["Price"]); decimal countError = TextUtils.ToDecimal(dt.Rows[i]["CountError"]); workSheet.Cells[4, 26] = countError; workSheet.Cells[4, 27] = countError == 0 ? "" : (TextUtils.ToInt(dt.Rows[i]["LevelError"]) == 0 ? "Sửa" : "Làm mới"); ((Excel.Range)workSheet.Rows[4]).Insert(); } ((Excel.Range)workSheet.Rows[3]).Delete(); ((Excel.Range)workSheet.Rows[3]).Delete(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (app != null) { app.ActiveWorkbook.Save(); app.Workbooks.Close(); app.Quit(); } } Process.Start(currentPath); } }
void save() { grvData.Focus(); ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); try { if (!ValidateForm()) { _isError = true; return; } WorkingDiaries.UserId = TextUtils.ToString(cboUser.EditValue); WorkingDiaries.UserName = txtUserName.Text.Trim(); WorkingDiaries.UserCode = txtUserCode.Text.Trim(); WorkingDiaries.DepartmentId = TextUtils.ToString(cboPhongBan.EditValue); WorkingDiaries.ProjectId = TextUtils.ToString(cboProject.EditValue); WorkingDiaries.ProjectCode = txtProjectCode.Text.Trim(); WorkingDiaries.ProjectName = txtProjectName.Text.Trim(); WorkingDiaries.ModuleCode = txtModuleCode.Text.Trim(); WorkingDiaries.ModuleName = txtModuleName.Text.Trim(); WorkingDiaries.WorkingContent = txtWorkingContent.Text.Trim(); DateTime cDate = TextUtils.ToDate3(dtpWorkingDate.EditValue); WorkingDiaries.WorkingDate = cDate; WorkingDiaries.StartTime = new DateTime(cDate.Year, cDate.Month, cDate.Day, TextUtils.ToDate3(dtpStartTime.EditValue).Hour, TextUtils.ToDate3(dtpStartTime.EditValue).Minute, 0); if (Global.AppUserName.ToLower() == "hien.n") { } else if (!validateTimeStart(WorkingDiaries.StartTime.Value)) { MessageBox.Show("Không thể nhập nhật ký do quá thời hạn.(Chậm nhất là mùng 2 tháng kế tiếp)", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); pt.CloseConnection(); return; } WorkingDiaries.EndTime = new DateTime(cDate.Year, cDate.Month, cDate.Day, TextUtils.ToDate3(dtpEndTime.EditValue).Hour, TextUtils.ToDate3(dtpEndTime.EditValue).Minute, 0); WorkingDiaries.WorkTime = TextUtils.ToDecimal(txtWorkTime.EditValue); WorkingDiaries.Status = cboStatus.SelectedIndex; WorkingDiaries.Note = txtNote.Text.Trim(); //WorkingDiaries.IsApproved = txtName.Text.Trim(); WorkingDiaries.IsNghiTrua = chkKhongNghiTrua.Checked; WorkingDiaries.IsAnToi = chkKhongAnToi.Checked; WorkingDiaries.WorkPercent = TextUtils.ToDecimal(txtWorkPercent.EditValue); WorkingDiaries.WorkingDiariesLocationID = TextUtils.ToInt(cboLocation.SelectedValue); WorkingDiaries.UpdatedBy = Global.AppUserName; WorkingDiaries.UpdatedDate = DateTime.Now; if (WorkingDiaries.ID == 0) { WorkingDiaries.CreatedBy = Global.AppUserName; WorkingDiaries.CreatedDate = DateTime.Now; WorkingDiaries.ID = (int)pt.Insert(WorkingDiaries); } else { pt.Update(WorkingDiaries); } pt.CommitTransaction(); _isSaved = true; loadData(); MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); _isError = false; if (this.LoadDataChange != null) { this.LoadDataChange(null, null); } } catch (Exception ex) { _isError = true; MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { pt.CloseConnection(); } }
bool ValidateForm() { //if (!TextUtils.HasPermission("frmWorkingDiariesManager_IsApproved") && cboStatus.SelectedIndex > 1) //{ // MessageBox.Show("Bạn chỉ có quyền nhập nhật ký công việc thời gian hành chính.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); // return false; //} if (WorkingDiaries.IsApproved) { MessageBox.Show("Nhật ký công việc đã được duyệt, bạn không thể sửa được nữa.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (cboPhongBan.EditValue == null) { MessageBox.Show("Xin hãy chọn một phòng ban.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (cboUser.EditValue == null) { MessageBox.Show("Xin hãy chọn một nhân viên.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (txtUserCode.Text.Trim() == "") { MessageBox.Show("Nhân viên chưa có mã.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (txtProjectCode.Text.Trim() == "" && cboStatus.SelectedIndex != 8) { MessageBox.Show("Dự án chưa có mã.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (cboProject.EditValue == null && cboStatus.SelectedIndex != 8) { MessageBox.Show("Xin hãy chọn một dự án.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (cboStatus.SelectedIndex <= 0) { MessageBox.Show("Xin hãy chọn một trạng thái.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (dtpWorkingDate.EditValue == null) { MessageBox.Show("Bạn chưa điền ngày làm việc.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (dtpStartTime.EditValue == null) { MessageBox.Show("Bạn chưa điền thời gian bắt đầu.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (dtpEndTime.EditValue == null) { MessageBox.Show("Bạn chưa điền thời gian kết thúc.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (TextUtils.ToString(cboModule.EditValue) == "") { MessageBox.Show("Bạn chưa chọn một module.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (TextUtils.ToDecimal(txtWorkTime.EditValue) == 0) { MessageBox.Show("Bạn chưa điền tổng thời gian.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (txtWorkingContent.Text.Trim() == "") { MessageBox.Show("Bạn chưa điền nội dung công việc.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (TextUtils.ToDecimal(txtWorkTime.EditValue) <= 0) { MessageBox.Show("Thời gian làm việc phải lớn hơn 0.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (TextUtils.ToInt(cboLocation.SelectedValue) == 0) { MessageBox.Show("Bạn chưa chọn một địa điểm làm việc.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } //1.Thời gian hành chính (8:00 - 17:00) //2.Tăng ca tối, thường (17:30 - 22:00, 6:00 - 8:00) //3.Tăng ca đêm ngày thường (22:00 - 6:00) //4.Tăng ca ngày nghỉ (6:00 - 22:00) //5.Tăng ca ngày lễ (6:00 - 22:00) //6.Tăng ca đêm ngày nghỉ (22:00 - 6:00) //7.Tăng ca đêm ngày lễ (22:00 - 6:00) //8.Nghỉ phép (8:00 - 17:00) //9.Nghỉ không lương (8:00 - 17:00) //10.Nghỉ chế độ (8:00 - 17:00) //List<int> listHour = new List<int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }); DateTime cDate = (DateTime)dtpWorkingDate.EditValue; DateTime startDate = new DateTime(cDate.Year, cDate.Month, cDate.Day, TextUtils.ToDate3(dtpStartTime.EditValue).Hour, TextUtils.ToDate3(dtpStartTime.EditValue).Minute, 0); DateTime endDate = new DateTime(cDate.Year, cDate.Month, cDate.Day, TextUtils.ToDate3(dtpEndTime.EditValue).Hour, TextUtils.ToDate3(dtpEndTime.EditValue).Minute, 0); string sql = ""; if (WorkingDiaries.ID > 0) { sql = "select top 1 ID from WorkingDiaries where ((StartTime <= '" + startDate.ToString("yyyy-MM-dd HH:mm") + "' and EndTime > '" + startDate.ToString("yyyy-MM-dd HH:mm") + "') or " + "(StartTime < '" + endDate.ToString("yyyy-MM-dd HH:mm") + "' and EndTime >= '" + endDate.ToString("yyyy-MM-dd HH:mm") + "')) " //+ "and (DATEDIFF(day, '" + cDate.ToString("yyyy-MM-dd") + "', WorkingDate) = 0 " + "and UserId = '" + TextUtils.ToString(cboUser.EditValue) + "' and ID <> " + WorkingDiaries.ID; } else { sql = "select top 1 ID from WorkingDiaries where ((StartTime <= '" + startDate.ToString("yyyy-MM-dd HH:mm") + "' and EndTime > '" + startDate.ToString("yyyy-MM-dd HH:mm") + "') or " + "(StartTime < '" + endDate.ToString("yyyy-MM-dd HH:mm") + "' and EndTime >= '" + endDate.ToString("yyyy-MM-dd HH:mm") + "')) " //+ "and (DATEDIFF(day, '" + cDate.ToString("yyyy-MM-dd") + "', WorkingDate) = 0 " + "and UserId = '" + TextUtils.ToString(cboUser.EditValue) + "'"; } DataTable dt = LibQLSX.Select(sql); if (dt.Rows.Count > 0) { MessageBox.Show("Khung thời gian đang bị trùng lặp.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (cboStatus.SelectedIndex == 1 || cboStatus.SelectedIndex == 8 || cboStatus.SelectedIndex == 9 || cboStatus.SelectedIndex == 10) { List <int> listHour = new List <int>(new int[] { 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }); if (!listHour.Contains(startDate.Hour) || !listHour.Contains(endDate.Hour) || startDate.Hour > endDate.Hour || (endDate.Hour == 17 && endDate.Minute > 0) || (startDate.Hour == 11 && startDate.Minute > 30) || (startDate.Hour == 12 && startDate.Minute < 30) || (endDate.Hour == 11 && endDate.Minute > 30) || (endDate.Hour == 12 && endDate.Minute < 30) ) { MessageBox.Show("Thời gian bắt đầu hoặc thời gian kết thúc không hợp lệ.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } } if (cboStatus.SelectedIndex == 2) { List <int> listHour = new List <int>(new int[] { 6, 7, 8, 17, 18, 19, 20, 21, 22 }); if (!listHour.Contains(startDate.Hour) || !listHour.Contains(endDate.Hour) || startDate.Hour > endDate.Hour || (startDate.Hour == 17 && startDate.Minute < 30)) { MessageBox.Show("Thời gian bắt đầu hoặc thời gian kết thúc không hợp lệ.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } } if (cboStatus.SelectedIndex == 4 || cboStatus.SelectedIndex == 5) { List <int> listHour = new List <int>(new int[] { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 }); if (!listHour.Contains(startDate.Hour) || !listHour.Contains(endDate.Hour) || startDate.Hour > endDate.Hour || (endDate.Hour == 22 && endDate.Minute > 0) || (startDate.Hour == 11 && startDate.Minute > 30) || (startDate.Hour == 12 && startDate.Minute < 30) || (endDate.Hour == 11 && endDate.Minute > 30) || (endDate.Hour == 12 && endDate.Minute < 30) ) { MessageBox.Show("Thời gian bắt đầu hoặc thời gian kết thúc không hợp lệ.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } } if (cboStatus.SelectedIndex == 3 || cboStatus.SelectedIndex == 6 || cboStatus.SelectedIndex == 7) { List <int> listHour = new List <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 22, 23 }); if (!listHour.Contains(startDate.Hour) || !listHour.Contains(endDate.Hour) || (endDate.Hour == 6 && endDate.Minute > 0)) { MessageBox.Show("Thời gian bắt đầu hoặc thời gian kết thúc không hợp lệ.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } } if (cboStatus.SelectedIndex == 7 || cboStatus.SelectedIndex == 6) { if (endDate.Hour - startDate.Hour < 0) { MessageBox.Show("Thời gian bắt đầu hoặc thời gian kết thúc không hợp lệ.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } } return(true); }
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ệ } }