// When ADDBOXID button is clicked, open frmModule by edit mode with delegate function private void btnAddBoxId_Click(object sender, EventArgs e) { string user = txtUser.Text; bool bl = ShGeneral.checkOpenFormExists("frmModule"); if (bl) { MessageBox.Show("Please close brows-mode form or finish the current edit form.", "BoxId DB", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2); } else { frmModule fM = new frmModule(); // Catch the child (frmModule) event, then update this form's datagridview fM.RefreshEvent += delegate(object sndr, EventArgs excp) { updateDataGripViews(ref dgvBoxId, false); this.Focus(); }; fM.updateControls(String.Empty, DateTime.Now, user, String.Empty, true); fM.Show(); } }
// Change the capacity of the box (only for the super user) private void btnChangeLimit_Click(object sender, EventArgs e) { // Open frmCapacity with delegate event bool bl = ShGeneral.checkOpenFormExists("frmCapacity"); if (bl) { MessageBox.Show("Please close or complete another form.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); } else { frmCapacity f4 = new frmCapacity(); // When the delegate event is triggered by child, update this form's datagridview f4.RefreshEvent += delegate(object sndr, EventArgs excp) { limit = f4.getLimit(); txtLimit.Text = limit.ToString(); updateDataGripViews(dtOverall, ref dgvProductSerial); this.Focus(); }; f4.updateControls(limit.ToString()); f4.Show(); } }
// OPEN button generate frmModule by view mode without delegate event. // SHIP button edit the shipping date for box id. private void dgvBoxId_CellContentClick(object sender, DataGridViewCellEventArgs e) { int currentRow = int.Parse(e.RowIndex.ToString()); // OPEN button generate frmModule by view mode without delegate event if (dgvBoxId.Columns[e.ColumnIndex] == openBoxId && currentRow >= 0) { // In case frmModule is already opened, close it first ShGeneral.closeOpenForm("frmModule"); string boxId = dgvBoxId["boxid", currentRow].Value.ToString(); DateTime printDate = DateTime.Parse(dgvBoxId["printdate", currentRow].Value.ToString()); string user = txtUser.Text == "User_9" ? txtUser.Text : dgvBoxId["suser", currentRow].Value.ToString(); string serialNo = txtProductSerial.Text; frmModule fM = new frmModule(); fM.updateControls(boxId, printDate, user, serialNo, false); fM.Show(); } // SHIP button edit the shipping date for box id if (dgvBoxId.Columns[e.ColumnIndex] == editShipDate && currentRow >= 0) { string boxId = dgvBoxId["boxid", currentRow].Value.ToString(); DateTime shipdate = dtpShipDate.Value; DialogResult result1 = MessageBox.Show("Do you want to update the shipping date of as follows:" + System.Environment.NewLine + boxId + ": " + shipdate, "Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result1 == DialogResult.Yes) { ShSQL tf = new ShSQL(); int count = tf.sqlExecuteScalarInt("select count(boxid) from shipment where boxid = '" + boxId + "'"); if (count > 0) { tf.sqlExecuteScalarString("delete from shipment where boxid = '" + boxId + "'"); } else if (count == -1) { return; } string sql = "update box_id SET shipdate = '" + shipdate + "' " + "WHERE boxid = '" + boxId + "'"; string sql_ship = "INSERT INTO shipment SELECT boxid, serialno, model, '" + shipdate + "', '" + txtShipStatus.Text + "' FROM product_serial WHERE boxid = '" + boxId + "'"; if (!String.IsNullOrEmpty(txtShipStatus.Text)) { int res = tf.sqlExecuteNonQueryInt(sql, false); tf.sqlExecuteScalarString(sql_ship); updateDataGripViews(ref dgvBoxId, false); } else { MessageBox.Show("Please input Shipping Status and try again.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtShipStatus.Focus(); } } } }
// Replace a product serial in already registered box id (only for super user) private void btnReplace_Click(object sender, EventArgs e) { // If more than 2 columns or more than 2 records are selected, leave the procedure if (dgvProductSerial.Columns.GetColumnCount(DataGridViewElementStates.Selected) >= 2 || dgvProductSerial.Rows.GetRowCount(DataGridViewElementStates.Selected) >= 2 || dgvProductSerial.CurrentCell.ColumnIndex != 0) { MessageBox.Show("Please select only one serial number.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); return; } // Open form frmModuleReplace with delegate function bool bl = ShGeneral.checkOpenFormExists("frmModuleReplace"); if (bl) { MessageBox.Show("Please close or complete another form.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); return; } updateRowIndex = dgvProductSerial.CurrentCell.RowIndex; frmModuleReplace f2 = new frmModuleReplace(); // Update this form's datagridview when child's delegate event is triggered f2.RefreshEvent += delegate(object sndr, EventArgs excp) { dtOverall.Clear(); readDatatable(ref dtOverall); updateDataGripViews(dtOverall, ref dgvProductSerial); dgvProductSerial.CurrentCell = dgvProductSerial[0, updateRowIndex]; dgvProductSerial.FirstDisplayedScrollingRowIndex = updateRowIndex; this.Focus(); }; string curSerial = dgvProductSerial.CurrentCell.Value.ToString(); int curRowIndex = dgvProductSerial.CurrentRow.Index; f2.updateControls(curSerial, curRowIndex + 1); f2.Show(); }
// OPEN button generate frmModule by view mode without delegate event. // SHIP button edit the shipping date for box id. private void dgvBoxId_CellContentClick(object sender, DataGridViewCellEventArgs e) { int currentRow = int.Parse(e.RowIndex.ToString()); // OPEN button generate frmModule by view mode without delegate event if (dgvBoxId.Columns[e.ColumnIndex] == openBoxId && currentRow >= 0) { // In case frmModule is already opened, close it first ShGeneral.closeOpenForm("frmModule"); string boxId = dgvBoxId["boxid", currentRow].Value.ToString(); DateTime printDate = DateTime.Parse(dgvBoxId["printdate", currentRow].Value.ToString()); string user = txtUser.Text == "User_9" ? txtUser.Text : dgvBoxId["suser", currentRow].Value.ToString(); string serialNo = txtProductSerial.Text; frmModule fM = new frmModule(); fM.updateControls(boxId, printDate, user, serialNo, false); fM.Show(); } // SHIP button edit the shipping date for box id if (dgvBoxId.Columns[e.ColumnIndex] == editShipDate && currentRow >= 0) { string boxId = dgvBoxId["boxid", currentRow].Value.ToString(); DateTime shipdate = dtpShipDate.Value; DialogResult result1 = MessageBox.Show("Do you want to update the shipping date of as follows:" + System.Environment.NewLine + boxId + ": " + shipdate, "Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result1 == DialogResult.Yes) { string sql = "update box_id SET shipdate ='" + shipdate + "' " + "WHERE boxid= '" + boxId + "'"; System.Diagnostics.Debug.Print(sql); ShSQL tf = new ShSQL(); int res = tf.sqlExecuteNonQueryInt(sql, false); updateDataGripViews(ref dgvBoxId, false); } } }