public DataTable InsertRecord(Objects.StockSamples obj) { try { SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "SP_StockSamplesInsert"; cmd.Parameters.AddWithValue("@IssueDate", obj.IssueDate); cmd.Parameters.AddWithValue("@CustomerID", obj.CustomerID); cmd.Parameters.AddWithValue("@UserID", obj.UserID); cmd.Parameters.AddWithValue("@Remarks", obj.Remarks); return(new Database(connectionstring).ExecuteForDataTable(cmd)); } catch (Exception exc) { throw exc; } }
public void UpdateRecord(Objects.StockSamples obj) { try { SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "SP_StockSamplesUpdate"; cmd.Parameters.AddWithValue("@SampleID", obj.SampleID); cmd.Parameters.AddWithValue("@IssueDate", obj.IssueDate); cmd.Parameters.AddWithValue("@CustomerID", obj.CustomerID); cmd.Parameters.AddWithValue("@UserID", obj.UserID); cmd.Parameters.AddWithValue("@Remarks", obj.Remarks); new Database(connectionstring).ExecuteNonQueryOnly(cmd); } catch (Exception exc) { throw exc; } }
private void btnSave_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtCustomerID.Text.Trim())) { MessageBox.Show("Please Select Customer", "Information Missing"); txtCustomerID.Focus(); return; } if (Grid.Rows.Count == 0) { MessageBox.Show("Please Insert Products Information", "Detail Missing"); txt_ProductID.Focus(); return; } decimal vSecurity = 0; decimal.TryParse(txtSecurity.Text, out vSecurity); Objects.StockSamples BAL = new Objects.StockSamples(); BAL.SampleID = Int64.Parse(txtInvNo.Text); BAL.IssueDate = dtEntryDate.Value; BAL.CustomerID = int.Parse(txtCustomerID.Text); BAL.Remarks = txtRemarks.Text; BAL.UserID = vUserID; if (vOpenMode) { objDAL.UpdateRecord(BAL); objDAL.DeleteRecordBody(Int64.Parse(txtInvNo.Text)); } else { DataTable dt = objDAL.InsertRecord(BAL); BAL.SampleID = Int64.Parse(dt.Rows[0]["SampleID"].ToString()); } //Save Detail foreach (DataGridViewRow dr in Grid.Rows) { if (dr.Cells[0].Value != null) { Objects.StockSampleBody objBody = new Objects.StockSampleBody(); objBody.SampleID = BAL.SampleID; objBody.ProductID = Int32.Parse(dr.Cells["ProductID"].Value.ToString()); objBody.Qty = decimal.Parse(dr.Cells["Qty"].Value.ToString(), System.Globalization.NumberStyles.AllowDecimalPoint); objBody.Cost = decimal.Parse(dr.Cells["Cost"].Value.ToString(), System.Globalization.NumberStyles.AllowDecimalPoint); objDAL.InsertRecordBody(objBody); } } MessageBox.Show("Record Saved Successfully.", "Task Completed"); SetMode(false); } catch (Exception exc) { MessageBox.Show(exc.Message.ToString(), "Error"); } }