예제 #1
0
 /// <summary>
 /// grid CellValueChanged for do the basic calculation and unit selection
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvProductBOM_CellValueChanged(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         CheckInvalidEntries(e);
         ProductSP spProduct = new ProductSP();
         TransactionsGeneralFill trstGnFill = new TransactionsGeneralFill();
         if (e.RowIndex > -1)
         {
             if (e.ColumnIndex == dgvProductBOM.Columns["dgvcmbRawMaterial"].Index)
             {
                 if (dgvProductBOM.Rows[e.RowIndex].Cells["dgvcmbRawMaterial"] != null)
                 {
                     dgvProductBOM.Rows[e.RowIndex].Cells["dgvtxtUnit"].Value = spProduct.ProductUnit(Convert.ToDecimal(dgvProductBOM.Rows[e.RowIndex].Cells[1].Value));
                     DataTable dtblunitconversionViewAll = new DataTable();
                     decimal decProductId = Convert.ToDecimal(dgvProductBOM.Rows[e.RowIndex].Cells["dgvcmbRawMaterial"].Value);
                     dtblunitconversionViewAll = trstGnFill.UnitViewAllByProductId(dgvProductBOM, decProductId.ToString(), e.RowIndex);
                     DataRow drow = dtblunitconversionViewAll.NewRow();
                     drow["unitName"] = string.Empty;
                     drow["unitId"] = 0;
                     dtblunitconversionViewAll.Rows.InsertAt(drow, 0);
                     DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)(dgvProductBOM.Rows[e.RowIndex].Cells["dgvcmbUnit"]);
                     cell.DataSource = dtblunitconversionViewAll;
                     cell.ValueMember = "unitId";
                     cell.DisplayMember = "unitName";
                     if (dtblunitconversionViewAll.Rows[0][4] != null && dtblunitconversionViewAll.Rows[0][4] != DBNull.Value)
                     {
                         dgvProductBOM.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(dtblunitconversionViewAll.Rows[0][4].ToString());
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PB:21" + ex.Message, "Open Miracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }