private void GetBOMList(string findValue) { List <BOM> lstBOM = null; try { base.ExecutionStart(); base.BeginProcessing("Begin Load data...", "Please Waiting for Loading Data"); using (BOMBLL BOMBLL = new BOMBLL()) { lstBOM = BOMBLL.GetBOMList(findValue); } this.gcBOM.DataSource = lstBOM; this.dntRowNavigator.DataSource = lstBOM; base.ExecutionStop(); } catch (Exception ex) { base.FinishedProcessing(); XtraMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } finally { base.FinishedProcessing(); ((frmMainMenu)this.ParentForm).ExecuteTime.Caption = base.ExecuteTime; } }
private void btnSave_Click(object sender, EventArgs e) { //string result = String.Empty; //using (BOMBLL bomBll = new BOMBLL()) //{ // result = bomBll.InsertBOM(dtSrcUpload, ((frmMainMenu)this.ParentForm).UserID); //} //if (result == "OK") //{ // NotifierResult.Show("Insert Complete", "Result", 50, 1000, 50, NotifyType.Safe); //} //this.LockUploadScreen(); if (AlreadyAdded) { DialogResult dCliResTest = XtraMessageBox.Show(this, AleradyAddedMessage, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (dCliResTest == DialogResult.No) { return; } } string result = String.Empty; using (BOMBLL bomBll = new BOMBLL()) { result = bomBll.InsertBOM(dtSrcUpload, ((frmMainMenu)this.ParentForm).UserID); } if (result == "OK") { NotifierResult.Show("Insert Complete", "Result", 50, 1000, 50, NotifyType.Safe); AlreadyAdded = false; AleradyAddedMessage = ""; } this.LockUploadScreen(); }
private void btnBrowse_Click(object sender, EventArgs e) { string filePath = string.Empty; string fileExt = string.Empty; OpenFileDialog file = new OpenFileDialog(); file.Filter = "Excel Sheet(*.xlsx)|*.xlsx|Excel Sheet(*.xls)|*.xls|All Files(*.*)|*.*"; if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK) { filePath = file.FileName; fileExt = Path.GetExtension(filePath); //=== 1.Check file extension if (fileExt.CompareTo(".xls") == 0 || fileExt.CompareTo(".xlsx") == 0) { try { txtSrcPath.Text = filePath; DataTable dtExcel = new DataTable(); dtExcel = ReadExcel(filePath, fileExt); //=== 2. Check template if (dtExcel.Rows.Count > 0) { if (dtExcel.Rows[0][0].ToString() == "PRODUCT_NO" && dtExcel.Rows[0][1].ToString() == "MATERIAL_CODE" && dtExcel.Rows[0][2].ToString() == "BOM_QTY") { int counter = 0; List <string> productNoCollection = new List <string>(); List <string> materialCodeCollection = new List <string>(); dtSrcUpload.Rows.Clear(); foreach (DataRow row in dtExcel.Rows) { if (counter == 0) { counter++; continue; } else { //=== 3. Check each rows contains iilegal values or not if (row[0].Equals(System.DBNull.Value) || row[1].Equals(System.DBNull.Value)) { XtraMessageBox.Show(this, "Value at row# " + (counter + 1) + " is invalid, Please check", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.OnUploadFail(); return; } else { string value = row[2].ToString(); decimal number; if (Decimal.TryParse(value, out number)) { productNoCollection.Add(row[0] == null ? "" : row[0].ToString()); string matCodes = row[1].ToString(); string[] arrMatCodes = matCodes.Split(','); for (int i = 0; i < arrMatCodes.Length; i++) { materialCodeCollection.Add(arrMatCodes[i].Trim()); dtSrcUpload.Rows.Add(row.ItemArray[0], arrMatCodes[i].Trim(), row.ItemArray[2]); } } else { XtraMessageBox.Show(this, "BOM QTY at row# " + (counter + 1) + " is invalid, Please check", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.OnUploadFail(); return; } } counter++; } } using (BOMBLL bomBll = new BOMBLL()) { string products = String.Join(",", productNoCollection.ToArray()); string materials = String.Join(",", materialCodeCollection.ToArray()); string[] exitsItems = bomBll.CheckIsBOMExists(products, materials); if (!String.IsNullOrEmpty(exitsItems[0])) { XtraMessageBox.Show(this, "Product No. '" + exitsItems[0] + "' is not exists in product master", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.OnUploadFail(); } else if (!String.IsNullOrEmpty(exitsItems[1])) { XtraMessageBox.Show(this, "Material No. '" + exitsItems[1] + "' is not exists in material master", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.OnUploadFail(); } else { if (!String.IsNullOrEmpty(exitsItems[2])) { AlreadyAdded = true; AleradyAddedMessage = "Product No. '" + exitsItems[2] + "' is already added to BOM Master, Do you want replace it anyway?"; } else { AlreadyAdded = false; AleradyAddedMessage = ""; } this.btnSave.Enabled = true; gcBOMUpload.DataSource = dtSrcUpload; } } } else { XtraMessageBox.Show(this, "Excel template is not correct format.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.OnUploadFail(); } } else { XtraMessageBox.Show(this, "Excel template is not correct format.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.OnUploadFail(); } } catch (Exception ex) { XtraMessageBox.Show(this, "Excel template is not correct format.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.OnUploadFail(); } } else { XtraMessageBox.Show(this, "Please choose .xls or .xlsx file only.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.OnUploadFail(); } } }