void loadData() { removeColumn(); DateTime from = new DateTime(dtpFromDate.Value.Year, dtpFromDate.Value.Month, dtpFromDate.Value.Day, 0, 0, 0); DateTime to = new DateTime(dtpEndDate.Value.Year, dtpEndDate.Value.Month, dtpEndDate.Value.Day, 23, 59, 59); if (txtFromOrder.Text.Trim() != "" && txtToOrder.Text.Trim() != "") { string sql = @"SELECT TOP 1 DateLR FROM dbo.ProductCheckHistoryDetail WHERE OrderCode LIKE '%{0}%' ORDER BY DateLR"; DateTime?date1 = TextUtils.ToDate2(TextUtils.ExcuteScalar(string.Format(sql, txtFromOrder.Text.Trim()))); DateTime?date2 = TextUtils.ToDate2(TextUtils.ExcuteScalar(string.Format(sql, txtToOrder.Text.Trim()))); if (date1.HasValue && date2.HasValue) { if (date2.Value >= date1.Value) { from = new DateTime(date1.Value.Year, date1.Value.Month, date1.Value.Day, 0, 0, 0); to = new DateTime(date2.Value.Year, date2.Value.Month, date2.Value.Day, 0, 0, 0); } else { to = new DateTime(date1.Value.Year, date1.Value.Month, date1.Value.Day, 0, 0, 0); from = new DateTime(date2.Value.Year, date2.Value.Month, date2.Value.Day, 0, 0, 0); } } } List <string> listColumnText = new List <string>(); if (txtFindText.Text.Trim() == "") { return; } string[] arr = txtFindText.Text.Trim().Split(';'); for (int i = 0; i < arr.Length; i++) { listColumnText.Add(string.Format("[{0}]", arr[i])); grvData.Columns[i + 1].VisibleIndex = i + 1; grvData.Columns[i + 1].Caption = arr[i]; grvData.Columns[i + 1].FieldName = arr[i]; grvData.Columns[i + 1].Width = 200; } DataTable dt = TextUtils.LoadDataFromSP("spThongKePhanTichData", "A" , new string[] { "@From", "@To", "@FistColumnText" } , new object[] { from, to, string.Join(",", listColumnText) }); //DataColumn c = new DataColumn(); //c.Caption = "STT"; //c.ColumnName = "STT"; //c.DataType = typeof(int); //c.AutoIncrement = true; //c.AutoIncrementSeed = 1; //c.AutoIncrementStep = 1; //c.AllowDBNull = false; ////c.Unique = true; //dt.Columns.Add(c); //dt.Columns["STT"].SetOrdinal(0); grdData.DataSource = dt; }
private bool ValidateForm() { if (txtStockName.Text.Trim() == "" || txtStockCode.Text.Trim() == "") { MessageBox.Show("Xin hãy nhập đầy đủ thông tin", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } string sql1 = ""; if (_Stock.ID > 0) { sql1 = $"SELECT top 1 ID from AssemblyStock WHERE Code = N'{txtStockCode.Text.Trim()}' and ID <>'{_Stock.ID}'"; } else { sql1 = $"SELECT top 1 ID from AssemblyStock WHERE Code = N'{txtStockCode.Text.Trim()}'"; } int id = TextUtils.ToInt(TextUtils.ExcuteScalar(sql1)); if (id > 0) { MessageBox.Show("Đã tồn tại vị trí", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } return(true); }
private void btnSave_Click(object sender, EventArgs e) { try { DateTime dateTimeStart = pickerStartDate.Value.Date.AddHours(pickerStartTime.Value.Hour).AddMinutes(pickerStartTime.Value.Minute); DateTime dateTimeEnd = pickerEndDate.Value.Date.AddHours(pickerEndTime.Value.Hour).AddMinutes(pickerEndTime.Value.Minute); if (checkValid(dateTimeStart, dateTimeEnd)) { AndonModel andon; if (_isAdd) { string sql = string.Format("exec spCheckAndonIsCreatedByTime @dateTimeStart = '{0}', @dateTimeEnd = '{1}'", dateTimeStart.ToString("yyyy-MM-dd HH:mm"), dateTimeEnd.ToString("yyyy-MM-dd HH:mm")); int check = TextUtils.ToInt(TextUtils.ExcuteScalar(sql)); if (check > 0) { MessageBox.Show(dateTimeStart.ToString("yyyy/MM/dd HH:mm") + " - " + dateTimeEnd.ToString("yyyy/MM/dd HH:mm") + " exist a another shift ", "Notice", MessageBoxButtons.OK); return; } andon = new AndonModel(); } else { int ID = Convert.ToInt32(grvData.GetRowCellValue(grvData.FocusedRowHandle, "ID").ToString()); string sql = string.Format("exec spCheckAndonIsUpdatedByTime @AndonID = {0}, @dateTimeStart = '{1}', @dateTimeEnd = '{2}'", ID, dateTimeStart.ToString("yyyy-MM-dd HH:mm"), dateTimeEnd.ToString("yyyy-MM-dd HH:mm")); int check = TextUtils.ToInt(TextUtils.ExcuteScalar(sql)); if (check > 0) { MessageBox.Show(dateTimeStart.ToString("yyyy/MM/dd HH:mm") + " - " + dateTimeEnd.ToString("yyyy/MM/dd HH:mm") + " had a another shift ", "Notice", MessageBoxButtons.OK); return; } andon = AndonBO.Instance.FindByPK(ID) as AndonModel; } DataRowView shiftRow = cbxShiftType.SelectedItem as DataRowView; TimeSpan timeSpan = dateTimeEnd - dateTimeStart; int totalSeconds = TextUtils.ToInt(timeSpan.TotalSeconds); andon.ShiftStartTime = dateTimeStart; andon.ShiftEndTime = dateTimeEnd; andon.TotalSeconds = totalSeconds; andon.Takt = TextUtils.ToInt(txtTakt.Text); andon.QtyPlanDay = TextUtils.ToInt(txtPlanDay.Text); andon.ShiftID = TextUtils.ToInt(shiftRow.Row["ID"]); if (_isAdd) { AndonBO.Instance.Insert(andon); LoadData(); MessageBox.Show("Add a shift successfully!", TextUtils.Caption, MessageBoxButtons.OK); } else { AndonBO.Instance.Update(andon); LoadData(); MessageBox.Show("Edit a shift successfully!", TextUtils.Caption, MessageBoxButtons.OK); } } } catch (Exception ex) { MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void loadCombo() { object takt = TextUtils.ExcuteScalar("Select Takt from AndonConfig"); txtTakt.Text = TextUtils.ToString(takt); DataTable data = TextUtils.LoadDataFromSP("spGetShift", "Shift", new string[] { }, new object[] { }); cbxShiftType.DataSource = data; cbxShiftType.DisplayMember = "hourTime"; cbxShiftType.ValueMember = "ID"; }
private void ClearInterface() { object takt = TextUtils.ExcuteScalar("Select Takt from AndonConfig"); txtTakt.Text = TextUtils.ToString(takt); DateTime date = DateTime.Now.Date; pickerStartDate.Value = date; pickerStartTime.Value = date.AddHours(8); pickerEndDate.Value = date; pickerEndTime.Value = date.AddHours(12); }
private void loadShiftAndTaktTime() { object takt = TextUtils.ExcuteScalar("Select Takt from dbo.AndonConfig with(nolock)"); txtTakt.Text = TextUtils.ToString(takt); DataTable data = TextUtils.Select("Select * from dbo.Shift with(nolock)"); //ArrayList arr = ShiftBO.Instance.FindAll( //DataTable data = TextUtils.LoadDataFromSP("spGetShift", "Shift", new string[] { }, new object[] { }); cbxShiftType.DataSource = data; cbxShiftType.DisplayMember = "Name"; cbxShiftType.ValueMember = "ID"; }
/// <summary> /// Validate trước khi cất dữ liệu /// </summary> /// <returns></returns> private bool ValidateForm() { if (cboGroup.EditValue == null) { MessageBox.Show("Xin hãy chọn nhóm sản phẩm.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (cboStep.EditValue == null) { MessageBox.Show("Xin hãy chọn công đoạn.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (cboValueType.SelectedIndex < 0) { MessageBox.Show("Xin hãy chọn kiểu kiểm tra.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } //if (cboCheckValueType.SelectedIndex < 1) //{ // MessageBox.Show("Xin hãy chọn loại giá trị kiểm tra.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); // return false; //} if (txtName.Text.Trim() == "") { MessageBox.Show("Xin hãy điền Mô tả công đoạn.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } string sql = ""; if (WorkingModel.ID > 0) { sql = $"select ID from Working w where SortOrder='{txtSortOrder}' and w.ID <> {WorkingModel.ID} and WorkingStepID={TextUtils.ToInt(cboStep.EditValue)}"; } else { sql = $"select ID from Working where SortOrder='{txtSortOrder}' and WorkingStepID={TextUtils.ToInt(cboStep.EditValue)}"; } int id = TextUtils.ToInt(TextUtils.ExcuteScalar(sql)); if (id > 0) { MessageBox.Show("Trùng STT", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop); //return false; } return(true); }
/// <summary> /// Validate trước khi cất dữ liệu /// </summary> /// <returns></returns> private bool ValidateForm() { if (cboStep.EditValue == null) { MessageBox.Show("Xin hãy chọn một công đoạn.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (txtName.Text.Trim() == "") { MessageBox.Show("Xin hãy điền Mô tả chi tiết kiểm tra.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (cboValueType.SelectedIndex < 0) { MessageBox.Show("Xin hãy chọn một kiểu kiểm tra.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } string sql = ""; if (ProductWorking.ID > 0) { sql = $"select ID from ProductWorking pw where pw.SortOrder={txtSortOrder.Value} and pw.ID <> {ProductWorking.ID} and pw.ProductStepID={TextUtils.ToInt(cboStep.EditValue)} and pw.ProductID={ProductID}"; } else { sql = $"select ID from ProductWorking pw where pw.SortOrder={txtSortOrder.Value} and pw.ProductStepID={TextUtils.ToInt(cboStep.EditValue)} and pw.ProductID={ProductID}"; } int id = TextUtils.ToInt(TextUtils.ExcuteScalar(sql)); if (id > 0) { MessageBox.Show("Trùng STT", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop); // return false; } //if (cboCheckValueType.SelectedIndex <= 0) //{ // MessageBox.Show("Xin hãy chọn một loại giá trị kiểm tra.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); // return false; //} return(true); }
private void ClearInterface() { object takt = TextUtils.ExcuteScalar("Select top 1 Takt from AndonConfig"); txtTakt.Text = TextUtils.ToString(takt); DateTime date = DateTime.Now.Date; pickerStartDate.Value = date; pickerStartTime.Value = date.AddHours(0); pickerEndTime.Value = date.AddHours(0); pickerStartBreak1.Value = date.AddHours(0); pickerEndBreak1.Value = date.AddHours(0); pickerStartBreak2.Value = date.AddHours(0); pickerEndBreak2.Value = date.AddHours(0); pickerStartBreak3.Value = date.AddHours(0); pickerEndBreak3.Value = date.AddHours(0); pickerStartBreak4.Value = date.AddHours(0); pickerEndBreak4.Value = date.AddHours(0); cbxShiftType.SelectedIndex = -1; }
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(); } }
private void btnSave_Click(object sender, EventArgs e) { try { textBox1.Focus(); 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); if (checkValid(dateTimes[0], dateTimes[1], dateTimes[2], dateTimes[3], dateTimes[4], dateTimes[5], dateTimes[6], dateTimes[7], dateTimes[8], dateTimes[9])) { AndonModel andon = new AndonModel(); if (!_isAdd) { // Check trong khoảng thời gian xem đã có ca nào được tạo chưa trừ ca đang chọn int ID = Convert.ToInt32(grvData.GetRowCellValue(grvData.FocusedRowHandle, "ID").ToString()); andon = AndonBO.Instance.FindByPK(ID) as AndonModel; } string sql = string.Format("exec spCheckAndonIsUpdatedByTime @AndonID = {0}, @dateTimeStart = '{1}', @dateTimeEnd = '{2}'", andon.ID, dateTimes[0].ToString("yyyy-MM-dd HH:mm"), dateTimes[1].ToString("yyyy-MM-dd HH:mm")); int check = TextUtils.ToInt(TextUtils.ExcuteScalar(sql)); if (check > 0) { MessageBox.Show(dateTimes[0].ToString("yyyy/MM/dd HH:mm") + " - " + dateTimes[1].ToString("yyyy/MM/dd HH:mm") + " had a another shift ", "Notice", MessageBoxButtons.OK); return; } //DataRowView shiftRow = cbxShiftType.SelectedItem as DataRowView; TimeSpan timeSpan = dateTimes[1] - dateTimes[0]; int totalSeconds = TextUtils.ToInt(timeSpan.TotalSeconds); andon.ShiftStartTime = dateTimes[0]; andon.ShiftEndTime = dateTimes[1]; andon.StartTimeBreak1 = dateTimes[2]; andon.EndTimeBreak1 = dateTimes[3]; andon.StartTimeBreak2 = dateTimes[4]; andon.EndTimeBreak2 = dateTimes[5]; andon.StartTimeBreak3 = dateTimes[6]; andon.EndTimeBreak3 = dateTimes[7]; andon.StartTimeBreak4 = dateTimes[8]; andon.EndTimeBreak4 = dateTimes[9]; andon.TotalSeconds = totalSeconds; andon.Takt = TextUtils.ToInt(txtTakt.Text); andon.QtyPlanDay = TextUtils.ToInt(txtPlanDay.Text); andon.ShiftID = TextUtils.ToInt(cbxShiftType.SelectedValue); if (_isAdd) { AndonBO.Instance.Insert(andon); } else { _UpdateAndon(false); AndonBO.Instance.Update(andon); _UpdateAndon(true); } LoadData(); SetInterface(false); ClearInterface(); } } catch (Exception ex) { MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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 btnSave_Click(object sender, EventArgs e) { if (grvData.RowCount == 0) { return; } int productID = TextUtils.ToInt(TextUtils.ExcuteScalar(string.Format("SELECT TOP 1 ID FROM dbo.Product WITH(NOLOCK) WHERE ProductCode = '{0}'", _productCode.Trim()))); int stepID = TextUtils.ToInt(cboWorkingStep.SelectedValue); if (productID == 0) { MessageBox.Show(string.Format("Không tồn tại sản phẩm có mã [{0}]!", _productCode.Trim()), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (stepID == 0) { MessageBox.Show(string.Format("Bạn chưa chọn công đoạn nào!", _productCode.Trim()), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(txtWorker.Text.Trim())) { MessageBox.Show(string.Format("Bạn chưa điền người làm!", _productCode.Trim()), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } bool isHasValue = false; for (int i = 1; i < 7; i++) { Control control = this.Controls.Find("textbox" + i, false)[0]; if (control.Text == "0" || control.Text == "1") { isHasValue = true; break; } } if (!isHasValue) { //MessageBox.Show("Bạn chưa nhập các giá trị kiểm tra!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult result = MessageBox.Show("Bạn có chắc muốn cất dữ liệu?", "Cất?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { return; } int count = _dtData.Rows.Count; for (int i = 3; i < 9; i++) { Control control = this.Controls.Find("textbox" + (i - 2), false)[0]; string columnCaption = grvData.Columns[i].Caption; string qrCode = ""; if (columnCaption == "#") { continue; } else { qrCode = _tienTo + columnCaption + " " + _productCode; } if (string.IsNullOrWhiteSpace(control.Text.Trim()) || TextUtils.ToInt(control.Text.Trim()) > 1 || TextUtils.ToInt(control.Text.Trim()) < 0) { continue; } /* * Xóa các giá trị đã lưu cũ */ ProductCheckHistoryDetailBO.Instance.DeleteByExpression(new Utils.Expression("QRCode", qrCode).And(new Utils.Expression("ProductStepID", stepID))); /* * Insert lại dữ liệu kiểm tra vào bảng */ for (int j = 0; j < count; j++) { ProductCheckHistoryDetailModel cModel = new ProductCheckHistoryDetailModel(); cModel.ProductStepID = stepID; cModel.ProductWorkingID = TextUtils.ToInt(grvData.GetRowCellValue(j, colWorkingID)); cModel.WorkerCode = txtWorker.Text.Trim(); cModel.StandardValue = TextUtils.ToString(grvData.GetRowCellValue(j, colStandardValue)); cModel.RealValue = TextUtils.ToString(grvData.GetRowCellValue(j, "RealValue" + (i - 2))); cModel.ValueType = TextUtils.ToInt(grvData.GetRowCellValue(j, colValueType)); cModel.EditValue1 = ""; cModel.EditValue2 = ""; cModel.StatusResult = TextUtils.ToInt(control.Text.Trim()); cModel.ProductID = productID; cModel.QRCode = qrCode; cModel.OrderCode = string.IsNullOrWhiteSpace(txtOrder.Text.Trim()) ? (_tienTo.Contains("-") ? _tienTo.Substring(0, _tienTo.Length - 1) : _order) : txtOrder.Text.Trim(); cModel.PackageNumber = _tienTo.Contains("-") ? _tienTo.Split('-')[1] : ""; cModel.QtyInPackage = columnCaption; cModel.Approved = ""; cModel.Monitor = ""; cModel.DateLR = DateTime.Now; cModel.EditContent = ""; cModel.EditDate = DateTime.Now; cModel.ProductOrder = _order; ProductCheckHistoryDetailBO.Instance.Insert(cModel); } } _stepIndex = cboWorkingStep.SelectedIndex; grdData.DataSource = null; txtQRCode.Text = ""; cboWorkingStep.DataSource = null; resetControl(); txtQRCode.Focus(); }