public void InsertConsumption(Objects.Consumption obj) { try { SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "SP_ConsumptionInsert"; cmd.Parameters.AddWithValue("@ProductionID", obj.ProductionID); cmd.Parameters.AddWithValue("@ProducedProductID", obj.ProducedProductID); cmd.Parameters.AddWithValue("@ProductID", obj.ProductID); cmd.Parameters.AddWithValue("@Qty", obj.Qty); cmd.Parameters.AddWithValue("@Cost", obj.Cost); new Database(connectionstring).ExecuteNonQueryOnly(cmd); } catch (Exception exc) { throw exc; } }
private void btnSave_Click(object sender, EventArgs e) { try { if (Grid.Rows.Count == 0) { MessageBox.Show("Please Insert Consumed Products Information", "Detail Missing"); txt_ProductID.Focus(); return; } if (Grid1.Rows.Count == 0) { MessageBox.Show("Please Insert Produced Products Information", "Detail Missing"); txt_ProductID1.Focus(); return; } Objects.Production BAL = new Objects.Production(); BAL.ProductionID = int.Parse(txt_InvNo.Text); BAL.EntryDate = dt_Entry.Value; BAL.Narration = txt_Narration.Text; BAL.UserID = vUserID; if (vOpenMode) { objDAL.UpdateRecord(BAL); objDAL.DeleteConsumption(Int32.Parse(txt_InvNo.Text)); objDAL.DeleteProductionBody(Int32.Parse(txt_InvNo.Text)); } else { objDAL.InsertRecord(BAL); } //Save Detail Consumption foreach (DataGridViewRow dr in Grid.Rows) { if (dr.Cells[0].Value != null) { decimal tempValue = 0; Objects.Consumption objBody = new Objects.Consumption(); objBody.ProductionID = int.Parse(txt_InvNo.Text); objBody.ProductID = Int32.Parse(dr.Cells["ProductID"].Value.ToString()); objBody.ProducedProductID = Int32.Parse(dr.Cells["ProductID"].Value.ToString()); decimal.TryParse(dr.Cells["Qty"].Value.ToString(), out tempValue); objBody.Qty = tempValue; decimal.TryParse(dr.Cells["Cost"].Value.ToString(), out tempValue); objBody.Cost = tempValue; objDAL.InsertConsumption(objBody); } } //Save Detail ProductionBody foreach (DataGridViewRow dr in Grid1.Rows) { if (dr.Cells[0].Value != null) { decimal tempValue = 0; Objects.ProductionBody objBody = new Objects.ProductionBody(); objBody.ProductionID = int.Parse(txt_InvNo.Text); objBody.ProductID = Int32.Parse(dr.Cells["ProductID1"].Value.ToString()); decimal.TryParse(dr.Cells["Qty1"].Value.ToString(), out tempValue); objBody.Qty = tempValue; decimal.TryParse(dr.Cells["Cost1"].Value.ToString(), out tempValue); objBody.Cost = tempValue; objBody.Remarks = string.Empty; objDAL.InsertRecordBody(objBody); } } MessageBox.Show("Record Saved Successfully.", "Task Completed"); SetMode(false); } catch (Exception exc) { MessageBox.Show(exc.Message.ToString(), "Error"); } }