public static ExpenseItem GetExpenseItem(int Id) { SqlConnection connection = ExpenseItemsDB.GetConnection(); string selectStatement = "SELECT * " + "FROM tbl_ExpenseItems " + "WHERE Id = @Id"; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); selectCommand.Parameters.AddWithValue("@Id", Id); try { connection.Open(); SqlDataReader expenseReader = selectCommand.ExecuteReader(System.Data.CommandBehavior.SingleRow); if (expenseReader.Read()) { //public ExpenseItem (string date1, string description1, string miles1, string expenseType1, //string expenseCode1, string rate1, string totalExpense1, string mileageTotal1, System.Drawing.Image receiptImage1) byte[] data = (byte[])expenseReader["receipt_image"]; System.IO.MemoryStream stream = new System.IO.MemoryStream(data); System.Drawing.Image receiptImage = System.Drawing.Image.FromStream(stream); ExpenseItem expenseItem = new ExpenseItem(expenseReader["receipt_date"].ToString(), expenseReader["description"].ToString(), expenseReader["number_miles"].ToString(), expenseReader[null].ToString(), expenseReader["expense_code"].ToString(), expenseReader["rate"].ToString(), expenseReader["total_expense"].ToString(), expenseReader["number_miles"].ToString(), receiptImage); return expenseItem; } else { return null; } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
public void SendToGrid(ExpenseItem expenseItem) { DateTime? date = System.Convert.ToDateTime(expenseItem.date); decimal miles = System.Convert.ToDecimal(expenseItem.miles); decimal rate = System.Convert.ToDecimal(expenseItem.rate); decimal mileageDollars = System.Convert.ToDecimal(expenseItem.mileageTotal); //create the new row DataRow newRow = dat_ExpenseItems.tbl_ExpenseItems.NewRow(); newRow["first_name"] = txtFirstName.Text; newRow["last_name"] = txtLastName.Text; newRow["vendor_code"] = txtVendorCode.Text; newRow["start_date"] = dateTimePicker1.Value; newRow["end_date"] = dateTimePicker2.Value; newRow["receipt_date"] = date; newRow["description"] = expenseItem.description; newRow["expense_code"] = expenseItem.expenseCode; newRow["number_miles"] = miles; newRow["rate"] = rate; newRow["mileage_dollars"] = expenseItem.mileageTotal; newRow["total_expense"] = expenseItem.totalExpense; newRow["is_exported"] = "No"; if (expenseItem.receiptImage != null) { newRow["receipt_image"] = imageToByteArray(expenseItem.receiptImage); } else { newRow["receipt_image"] = null; } //add the row to the table this.dat_ExpenseItems.tbl_ExpenseItems.Rows.Add(newRow); //Save the row to the database this.tbl_ExpenseItemsTableAdapter.Update(this.dat_ExpenseItems.tbl_ExpenseItems); }
public void SendDataToForm2(ExpenseItem expenseItem) { txtDescription.Text = expenseItem.description; txtExpenseCode.Text = expenseItem.expenseCode; txtMileageTotal.Text = expenseItem.mileageTotal; txtRate.Text = expenseItem.rate; }
//submit button click event private void btnSubmit_Click(object sender, EventArgs e) { //Run this logic path if mileage? is NOT checked if (checkBox1.Checked == false) { //perform data validation and proceed only if true is returned from method if (NonMileageIsValidData()) { txtMileageTotal.Text = "0"; txtTotalMiles.Text = "0"; txtRate.Text = "0"; double totalExpense = 0.00; totalExpense = Convert.ToDouble(txtWriteInTotal.Text); txtTotalExpense.Text = totalExpense.ToString("c"); //assign the expense code based on the expense type selected switch (comboBox1.Text) { case "meals & entertainment": txtExpenseCode.Text = "m"; break; case "employee vehicle auto reimbursment": txtExpenseCode.Text = "a"; break; case "company vehicle fuel": txtExpenseCode.Text = "f"; break; case "company vehicle repairs & maintance": txtExpenseCode.Text = "rm"; break; case "employee relations": txtExpenseCode.Text = "e"; break; case "travel, cab fare, car rental, etc.": txtExpenseCode.Text = "t"; break; case "Selling Telecommunicatons": txtExpenseCode.Text = "o"; break; case "1 - other expenses to be itemized": txtExpenseCode.Text = "o1"; break; case "2 - other expenses to be itemized": txtExpenseCode.Text = "o2"; break; case "3 - other expenses to be itemized": txtExpenseCode.Text = "o3"; break; case "4 - other expenses to be itemized": txtExpenseCode.Text = "o4"; break; } /*Instantiate an object instance of the ExpenseItem class using the 8 argument contructor, pulling in the values from the form*/ ExpenseItem expenseItem = new ExpenseItem(dtpReceiptDate.Text.ToString(), txtDescription.Text.ToString(), txtTotalMiles.Text.ToString(), comboBox1.Text.ToString(), txtExpenseCode.Text.ToString(), txtRate.Text.ToString(), txtTotalExpense.Text.ToString(), txtMileageTotal.Text.ToString(), receipt); //call the method from the main form to send the object property values to the data //grid view on form one frmMain.SendToGrid(expenseItem); this.Close(); } } //Run this logic path if mileage? IS checked if (checkBox1.Checked == true) { //perform data validation and proceed only if true is returned from method if (MileageIsValidData()) { txtWriteInTotal.Text = ""; /*Instantiate an object instance of the ExpenseItem class using the 8 argument contructor, pulling in the values from the form*/ ExpenseItem expenseItem = new ExpenseItem(dtpReceiptDate.Text.ToString(), txtDescription.Text.ToString(), txtTotalMiles.Text.ToString(), comboBox1.Text.ToString(), txtExpenseCode.Text.ToString(), txtRate.Text.ToString(), txtTotalExpense.Text.ToString(), txtMileageTotal.Text.ToString(), receipt); //call the method from the main form to send the object property values to the data //grid view on form one frmMain.SendToGrid(expenseItem); this.Close(); } } }