//================================================================================================================================================// // LOAD EXPENSES // //================================================================================================================================================// private void LoadExpenses() { using (SqlConnection conn = DBUtils.GetDBConnection()) { conn.Open(); SqlDataAdapter da = new SqlDataAdapter("SELECT ID, Description, Travel, Accomodation, Subsistence, Tools, Programming_Hours, Install_Hours, " + "Date, User_Log FROM Project_Expenses WHERE Project_ID = '" + Proj_ID + "'", conn); dt = new DataTable(); da.Fill(dt); } decimal totRand = 0.00m; decimal totDol = 0.00m; decimal totHours = 0.00m; foreach (DataRow row in (InternalDataCollectionBase)dt.Rows) { if (row["Travel"].ToString() != "") { if (row["Travel"].ToString().Contains("R")) { totRand += Convert.ToDecimal(row["Travel"].ToString().Remove(0, 1)); } else if (row["Travel"].ToString().Contains("$")) { totDol += Convert.ToDecimal(row["Travel"].ToString().Remove(0, 1)); } } if (row["Accomodation"].ToString() != "") { if (row["Accomodation"].ToString().Contains("R")) { totRand += Convert.ToDecimal(row["Accomodation"].ToString().Remove(0, 1)); } else if (row["Accomodation"].ToString().Contains("$")) { totDol += Convert.ToDecimal(row["Accomodation"].ToString().Remove(0, 1)); } } if (row["Subsistence"].ToString() != "") { if (row["Subsistence"].ToString().Contains("R")) { totRand += Convert.ToDecimal(row["Subsistence"].ToString().Remove(0, 1)); } else if (row["Subsistence"].ToString().Contains("$")) { totDol += Convert.ToDecimal(row["Subsistence"].ToString().Remove(0, 1)); } } if (row["Tools"].ToString() != "") { if (row["Tools"].ToString().Contains("R")) { totRand += Convert.ToDecimal(row["Tools"].ToString().Remove(0, 1)); } else if (row["Tools"].ToString().Contains("$")) { totDol += Convert.ToDecimal(row["Tools"].ToString().Remove(0, 1)); } } if (row["Programming_Hours"].ToString() != "") { totHours += Convert.ToDecimal(row["Programming_Hours"].ToString()); } if (row["Install_Hours"].ToString() != "") { totHours += Convert.ToDecimal(row["Install_Hours"].ToString()); } } txt_PAE_TotRand.Text = totRand.ToString("C"); txt_PAE_TotDol.Text = totDol.ToString("C", (IFormatProvider)CultureInfo.GetCultureInfo("en-US")); txt_PAE_TotHours.Text = totHours.ToString(); bs.DataSource = dt; }
//================================================================================================================================================// // EDIT ORDER DETAILS // //================================================================================================================================================// private void Btn_OED_Done_Click(object sender, EventArgs e) { if (txt_OED_CONum.Text != string.Empty) { if (MessageBox.Show("Are you sure you want to update order?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (txt_OED_CONum.Text.Trim() == oldCONum) { using (SqlConnection conn = DBUtils.GetDBConnection()) { conn.Open(); try { string sql = "UPDATE Orders_Received SET Date = @Date, Description = @Desc, Amount = @Amt, Percentage_Invoiced = @PercInv, " + "Percentage_Received = @PercRec, Quote_Number = @QNum WHERE Client_Order_Number = @CONum"; using (SqlCommand cmd = new SqlCommand(sql, conn)) { decimal amt; if (isInter) { if (txt_OED_Amt.Text.Contains("$")) { if (txt_OED_Amt.Text.Replace("$", string.Empty) == "0.00") { amt = 0.00m; } else { amt = Decimal.Parse(txt_OED_Amt.Text.Replace("$", string.Empty), CultureInfo.GetCultureInfo("en-US")); } } else { amt = 0.00m; } } else { if (txt_OED_Amt.Text.Contains("R")) { if (txt_OED_Amt.Text.Replace("R", string.Empty) == "0.00") { amt = 0.00m; } else { amt = Decimal.Parse(txt_OED_Amt.Text.Replace("R", string.Empty), CultureInfo.GetCultureInfo("en-ZA")); } } else { amt = 0.00m; } } cmd.Parameters.AddWithValue("@Date", dtp_OED_Date.Value); cmd.Parameters.AddWithValue("@Desc", txt_OED_Desc.Text.Trim()); cmd.Parameters.AddWithValue("@Amt", amt); cmd.Parameters.AddWithValue("@PercInv", pInv); cmd.Parameters.AddWithValue("@PercRec", pRec); cmd.Parameters.AddWithValue("@QNum", txt_OED_QNum.Text.Trim()); cmd.Parameters.AddWithValue("@CONum", oldCONum); cmd.ExecuteNonQuery(); MessageBox.Show("Order successfully updated.", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else if (txt_OED_CONum.Text.Trim() != oldCONum) { using (SqlConnection conn = DBUtils.GetDBConnection()) { conn.Open(); try { string sql = "UPDATE Orders_Received SET Client_Order_Number = @CONum, Date = @Date, Description = @Desc, Amount = @Amt, Percentage_Invoiced = @PercInv, " + "Percentage_Received = @PercRec, Quote_Number = @QNum WHERE Client_Order_Number = @oldCONum"; using (SqlCommand cmd = new SqlCommand(sql, conn)) { decimal amt; if (isInter) { if (txt_OED_Amt.Text.Contains("$")) { if (txt_OED_Amt.Text.Replace("$", string.Empty) == "0.00") { amt = 0.00m; } else { amt = Decimal.Parse(txt_OED_Amt.Text.Replace("$", string.Empty), CultureInfo.GetCultureInfo("en-US")); } } else { amt = 0.00m; } } else { if (txt_OED_Amt.Text.Contains("R")) { if (txt_OED_Amt.Text.Replace("R", string.Empty) == "0.00") { amt = 0.00m; } else { amt = Decimal.Parse(txt_OED_Amt.Text.Replace("R", string.Empty), CultureInfo.GetCultureInfo("en-ZA")); } } else { amt = 0.00m; } } cmd.Parameters.AddWithValue("@CONum", txt_OED_CONum.Text.Trim()); cmd.Parameters.AddWithValue("@Date", dtp_OED_Date.Value); cmd.Parameters.AddWithValue("@Desc", txt_OED_Desc.Text.Trim()); cmd.Parameters.AddWithValue("@Amt", amt); cmd.Parameters.AddWithValue("@PercInv", pInv); cmd.Parameters.AddWithValue("@PercRec", pRec); cmd.Parameters.AddWithValue("@QNum", txt_OED_QNum.Text.Trim()); cmd.Parameters.AddWithValue("@oldCONum", oldCONum); cmd.ExecuteNonQuery(); MessageBox.Show("Order successfully updated.", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } else { MessageBox.Show("Please enter a Client Order Number to continue.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
//================================================================================================================================================// // BUTTON DONE CLICKED // //================================================================================================================================================// private void Btn_OA_Done_Click(object sender, EventArgs e) { string newCONum = txt_OA_CONum.Text; sb = new StringBuilder().Append("Are you sure you want to add order with Client Order Number: ").Append(newCONum).Append("?"); if (newCONum != string.Empty) { if (MessageBox.Show(sb.ToString(), "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { using (SqlConnection conn = DBUtils.GetDBConnection()) { conn.Open(); try { using (SqlCommand cmd = new SqlCommand("INSERT INTO Orders_Received VALUES (@Date, @Client, @CONum, @Desc, @Amt, @PercInv, @PercRec, @QNum)", conn)) { decimal amt; if (isInter) { if (txt_OA_Amt.Text.Contains("$")) { if (txt_OA_Amt.Text.Replace("$", string.Empty) == "0.00") { amt = 0.00m; } else { amt = Decimal.Parse(txt_OA_Amt.Text.Replace("$", string.Empty), CultureInfo.GetCultureInfo("en-US")); } } else { amt = 0.00m; } } else { if (txt_OA_Amt.Text.Contains("R")) { if (txt_OA_Amt.Text.Replace("R", string.Empty) == "0.00") { amt = 0.00m; } else { amt = Decimal.Parse(txt_OA_Amt.Text.Replace("R", string.Empty), CultureInfo.GetCultureInfo("en-ZA")); } } else { amt = 0.00m; } } cmd.Parameters.AddWithValue("@Date", dtp_OA_Date.Value); cmd.Parameters.AddWithValue("@Client", txt_OA_CName.Text.Trim()); cmd.Parameters.AddWithValue("@CONum", txt_OA_CONum.Text.Trim()); cmd.Parameters.AddWithValue("@Desc", txt_OA_Desc.Text.Trim()); cmd.Parameters.AddWithValue("@Amt", amt); cmd.Parameters.AddWithValue("@PercInv", pInv); cmd.Parameters.AddWithValue("@PercRec", pRec); cmd.Parameters.AddWithValue("@QNum", txt_OA_QNum.Text.Trim()); cmd.ExecuteNonQuery(); MessageBox.Show("New order successfully added.", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } else { MessageBox.Show("Please enter a Client Order Number to continue.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { try { app = new Microsoft.Office.Interop.Word.Application(); doc = null; backgroundWorker1.ReportProgress(10); object fileName = @"\\192.168.8.121\Contractors\Remittances\Remittance_Template.docx"; missing = Type.Missing; backgroundWorker1.ReportProgress(20); doc = app.Documents.Open(fileName, missing, missing); app.Selection.Find.ClearFormatting(); app.Selection.Find.Replacement.ClearFormatting(); backgroundWorker1.ReportProgress(30); app.Selection.Find.Execute("<code>", missing, missing, missing, missing, missing, missing, missing, missing, txt_HA_Code.Text.Trim(), 2); app.Selection.Find.Execute("<name>", missing, missing, missing, missing, missing, missing, missing, missing, txt_HA_Name.Text.Trim(), 2); app.Selection.Find.Execute("<surname>", missing, missing, missing, missing, missing, missing, missing, missing, txt_HA_Surname.Text.Trim(), 2); backgroundWorker1.ReportProgress(40); app.Selection.Find.Execute("<date>", missing, missing, missing, missing, missing, missing, missing, missing, DateTime.Now.ToShortDateString(), 2); app.Selection.Find.Execute("<desc>", missing, missing, missing, missing, missing, missing, missing, missing, "Week ending " + dtp_HA_To.Value.ToLongDateString(), 2); app.Selection.Find.Execute("<dolvalue>", missing, missing, missing, missing, missing, missing, missing, missing, txt_HA_TotBE.Text.Trim(), 2); app.Selection.Find.Execute("<excrate>", missing, missing, missing, missing, missing, missing, missing, missing, txt_HA_ExcRate.Text.Trim(), 2); backgroundWorker1.ReportProgress(50); app.Selection.Find.Execute("<total>", missing, missing, missing, missing, missing, missing, missing, missing, txt_HA_TotAE.Text.Trim(), 2); app.Selection.Find.Execute("<subtotal>", missing, missing, missing, missing, missing, missing, missing, missing, txt_HA_TotAE.Text.Trim(), 2); app.Selection.Find.Execute("<grandtotal>", missing, missing, missing, missing, missing, missing, missing, missing, txt_HA_TotAE.Text.Trim(), 2); backgroundWorker1.ReportProgress(60); object SaveAsFile = (object)@"\\192.168.8.121\Contractors\Remittances\Remittance_" + txt_HA_Code.Text.Trim() + ".docx"; doc.SaveAs2(SaveAsFile, missing, missing, missing); using (SqlConnection conn = DBUtils.GetDBConnection()) { backgroundWorker1.ReportProgress(70); conn.Open(); string sql = "UPDATE Contractor_Hours SET Remittance=@Rem WHERE Code=@Code AND Contractor_Code=@CCode"; backgroundWorker1.ReportProgress(80); using (SqlCommand cmd = new SqlCommand(sql, conn)) { cmd.Parameters.AddWithValue("@Rem", "Yes"); cmd.Parameters.AddWithValue("@Code", txt_HA_Code.Text.Trim()); backgroundWorker1.ReportProgress(90); cmd.Parameters.AddWithValue("@CCode", txt_HA_CCode.Text.Trim()); cmd.ExecuteNonQuery(); } } backgroundWorker1.ReportProgress(100); } catch (Exception ex) { error = ex.Message; isError = true; } }
private void DoUpdate() { using (SqlConnection conn = DBUtils.GetDBConnection()) { conn.Open(); try { using (SqlCommand cmd = new SqlCommand("UPDATE Contractor_Hours SET Date_Start = @DateS, Date_End = @DateE, Hours = @Hours, Rate_Per_Hour = @RPH, Total_$ = @TotBE, Exchange_Rate = @ER, Total_R = @TotAE, QTech_Cut = @QTC, Final_Total = @FTot, Paid = @P, Date_Paid = @DP WHERE Code = @Code", conn)) { decimal excRate; if (txt_HA_ExcRate.Text == "0,00000" || txt_HA_ExcRate.Text == "0.00000") { excRate = 0.00000m; } else { excRate = Decimal.Parse(txt_HA_ExcRate.Text.Replace(".", ","), CultureInfo.GetCultureInfo("en-ZA")); } decimal perHour; if (txt_HA_DolPH.Text.Contains("$")) { if (txt_HA_DolPH.Text.Replace("$", string.Empty) == "0.00") { perHour = 0.00m; } else { perHour = Decimal.Parse(txt_HA_DolPH.Text.Replace("$", string.Empty), CultureInfo.GetCultureInfo("en-US")); } } else { perHour = 0.00m; } decimal totBE; if (txt_HA_TotBE.Text.Replace("$", string.Empty) == "0.00") { totBE = 0.00m; } else { totBE = Decimal.Parse(txt_HA_TotBE.Text.Replace("$", string.Empty), CultureInfo.GetCultureInfo("en-US")); } decimal qtCut; if (txt_HA_QTCut.Text.Contains("R")) { if (txt_HA_QTCut.Text.Replace("R", string.Empty) == "0,00" || txt_HA_QTCut.Text.Replace("R", string.Empty) == "0.00") { qtCut = 0.00m; } else { qtCut = Decimal.Parse(txt_HA_QTCut.Text.Replace("R", string.Empty), CultureInfo.GetCultureInfo("en-ZA")); } } else { qtCut = 0.00m; } decimal totAE; if (txt_HA_TotAE.Text.Replace("R", string.Empty) == "0,00" || txt_HA_TotAE.Text.Replace("R", string.Empty) == "0.00") { totAE = 0.00m; } else { totAE = Decimal.Parse(txt_HA_TotAE.Text.Replace("R", string.Empty), CultureInfo.GetCultureInfo("en-ZA")); } decimal fTot; if (txt_HA_FTotal.Text.Replace("R", string.Empty) == "0,00" || txt_HA_FTotal.Text.Replace("R", string.Empty) == "0.00") { fTot = 0.00m; } else { fTot = Decimal.Parse(txt_HA_FTotal.Text.Replace("R", string.Empty), CultureInfo.GetCultureInfo("en-ZA")); } decimal hours; if (txt_HA_HW.Text == string.Empty) { hours = 0.00m; } else if (txt_HA_HW.Text.Contains(".")) { hours = Decimal.Parse(txt_HA_HW.Text.Replace(".", ",")); } else { hours = Decimal.Parse(txt_HA_HW.Text); } cmd.Parameters.AddWithValue("@Code", txt_HA_Code.Text.Trim()); cmd.Parameters.AddWithValue("@DateS", dtp_HA_From.Value); cmd.Parameters.AddWithValue("@DateE", dtp_HA_To.Value); cmd.Parameters.AddWithValue("@Hours", hours); cmd.Parameters.AddWithValue("@RPH", perHour); cmd.Parameters.AddWithValue("@TotBE", totBE); cmd.Parameters.AddWithValue("@ER", excRate); cmd.Parameters.AddWithValue("@TotAE", totAE); cmd.Parameters.AddWithValue("@QTC", qtCut); cmd.Parameters.AddWithValue("@FTot", fTot); if (cb_HA_Paid.Checked) { cmd.Parameters.AddWithValue("@P", "Yes"); cmd.Parameters.AddWithValue("@DP", dtp_HA_DatePaid.Value); } else { cmd.Parameters.AddWithValue("@P", "No"); cmd.Parameters.AddWithValue("@DP", DBNull.Value); } cmd.ExecuteNonQuery(); MessageBox.Show("Work week successfully updated.", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
//================================================================================================================================================// // BUTTON DONE CLICKED // //================================================================================================================================================// private void Btn_HA_Done_Click(object sender, EventArgs e) { string code = txt_HA_Code.Text; if (send is Button) { StringBuilder sb = new StringBuilder().Append("Are you sure you want to add work week with Code: ").Append(code).Append("?"); if (MessageBox.Show(sb.ToString(), "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { using (SqlConnection conn = DBUtils.GetDBConnection()) { conn.Open(); try { using (SqlCommand cmd = new SqlCommand("INSERT INTO Contractor_Hours VALUES (@Code, @Date_Start, @Date_End, @Hours, @RPHour, @TotBE, @ERate, @TotAE, @QTCut, @FTot, @Rem, @Inv, @Paid, @DPaid, @CCode)", conn)) { decimal excRate; if (txt_HA_ExcRate.Text == "0.00000") { excRate = 0.00000m; } else { excRate = Decimal.Parse(txt_HA_ExcRate.Text); } decimal perHour; if (txt_HA_DolPH.Text.Contains("$")) { if (txt_HA_DolPH.Text.Replace("$", string.Empty) == "0.00") { perHour = 0.00m; } else { perHour = Decimal.Parse(txt_HA_DolPH.Text.Replace("$", string.Empty), CultureInfo.GetCultureInfo("en-US")); } } else { perHour = 0.00m; } decimal totBE; if (txt_HA_TotBE.Text.Replace("$", string.Empty) == "0.00") { totBE = 0.00m; } else { totBE = Decimal.Parse(txt_HA_TotBE.Text.Replace("$", string.Empty), CultureInfo.GetCultureInfo("en-US")); } decimal qtCut; if (txt_HA_QTCut.Text.Contains("R")) { if (txt_HA_QTCut.Text.Replace("R", string.Empty) == "0.00") { qtCut = 0.00m; } else { qtCut = Decimal.Parse(txt_HA_QTCut.Text.Replace("R", string.Empty), CultureInfo.GetCultureInfo("en-ZA")); } } else { qtCut = 0.00m; } decimal totAE; if (txt_HA_TotAE.Text.Replace("R", string.Empty) == "0.00") { totAE = 0.00m; } else { totAE = Decimal.Parse(txt_HA_TotAE.Text.Replace("R", string.Empty), CultureInfo.GetCultureInfo("en-ZA")); } decimal fTot; if (txt_HA_FTotal.Text.Replace("R", string.Empty) == "0.00") { fTot = 0.00m; } else { fTot = Decimal.Parse(txt_HA_FTotal.Text.Replace("R", string.Empty), CultureInfo.GetCultureInfo("en-ZA")); } decimal hours; if (txt_HA_HW.Text == string.Empty) { hours = 0.00m; } else if (txt_HA_HW.Text.Contains(".")) { hours = Decimal.Parse(txt_HA_HW.Text.Replace(".", ",")); } else { hours = Decimal.Parse(txt_HA_HW.Text); } cmd.Parameters.AddWithValue("@Code", txt_HA_Code.Text.Trim()); cmd.Parameters.AddWithValue("@Date_Start", dtp_HA_From.Value); cmd.Parameters.AddWithValue("@Date_End", dtp_HA_To.Value); cmd.Parameters.AddWithValue("@Hours", hours); cmd.Parameters.AddWithValue("@RPHour", perHour); cmd.Parameters.AddWithValue("@TotBE", totBE); cmd.Parameters.AddWithValue("@ERate", excRate); cmd.Parameters.AddWithValue("@TotAE", totAE); cmd.Parameters.AddWithValue("@QTCut", qtCut); cmd.Parameters.AddWithValue("@FTot", fTot); cmd.Parameters.AddWithValue("@Rem", "No"); cmd.Parameters.AddWithValue("@Inv", "No"); if (cb_HA_Paid.Checked) { cmd.Parameters.AddWithValue("@Paid", "Yes"); cmd.Parameters.AddWithValue("@DPaid", dtp_HA_DatePaid.Value); } else { cmd.Parameters.AddWithValue("@Paid", "No"); cmd.Parameters.AddWithValue("@DPaid", DBNull.Value); } cmd.Parameters.AddWithValue("@CCode", txt_HA_CCode.Text.Trim()); cmd.ExecuteNonQuery(); MessageBox.Show("New work week successfully added.", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } else { StringBuilder sb = new StringBuilder().Append("Are you sure you want to update work week with Code: ").Append(code).Append("?"); if (MessageBox.Show(sb.ToString(), "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { DoUpdate(); } } }
//================================================================================================================================================// // BUTTON DONE CLICKED // //================================================================================================================================================// private void Btn_IRA_Done_Click(object sender, EventArgs e) { string newINum = txt_IRA_InvNum.Text; sb = new StringBuilder().Append("Are you sure you want to add invoice with Invoice Number: ").Append(newINum).Append("?"); if (newINum != string.Empty) { if (MessageBox.Show(sb.ToString(), "Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes) { using (SqlConnection conn = DBUtils.GetDBConnection()) { conn.Open(); try { using (SqlCommand cmd = new SqlCommand("INSERT INTO Invoices_Received VALUES (@Date, @InvNum, @Supp, @Desc, @Amt, @VAT, @Paid)", conn)) { decimal amt; if (txt_IRA_Amt.Text.Contains("R")) { if (txt_IRA_Amt.Text.Replace("R", string.Empty) == "0.00") { amt = 0.00m; } else { amt = Decimal.Parse(txt_IRA_Amt.Text.Replace("R", string.Empty), CultureInfo.GetCultureInfo("en-ZA")); } } else { amt = 0.00m; } decimal VAT; if (txt_IRA_VAT.Text.Contains("R")) { if (txt_IRA_VAT.Text.Replace("R", string.Empty) == "0.00") { VAT = 0.00m; } else { VAT = Decimal.Parse(txt_IRA_VAT.Text.Replace("R", string.Empty), CultureInfo.GetCultureInfo("en-ZA")); } } else { VAT = 0.00m; } cmd.Parameters.AddWithValue("@Date", dtp_IRA_Date.Value); cmd.Parameters.AddWithValue("@InvNum", txt_IRA_InvNum.Text.Trim()); cmd.Parameters.AddWithValue("@Supp", txt_IRA_SuppName.Text.Trim()); cmd.Parameters.AddWithValue("@Desc", txt_IRA_Desc.Text.Trim()); cmd.Parameters.AddWithValue("@Amt", amt); cmd.Parameters.AddWithValue("@VAT", VAT); if (cb_IRA_Paid.Checked) { cmd.Parameters.AddWithValue("@Paid", "Yes"); } else { cmd.Parameters.AddWithValue("@Paid", "No"); } cmd.ExecuteNonQuery(); MessageBox.Show("New invoice successfully added.", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } else { MessageBox.Show("Please enter an Invoice Number to continue.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void DoAdd() { if (!txt_NE_User.Text.Equals(string.Empty)) { if (MessageBox.Show(new StringBuilder().Append("Are you sure you want to add new line?").ToString(), "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { using (SqlConnection conn = DBUtils.GetDBConnection()) { conn.Open(); try { using (SqlCommand cmd = new SqlCommand("INSERT INTO Project_Expenses VALUES (@ProjID, @Desc, @Travel, @Acc, @Sub, @Tools, @ProgHrs, @InstHrs, @Date, @User)", conn)) { cmd.Parameters.AddWithValue("@ProjID", Proj_ID); cmd.Parameters.AddWithValue("@Desc", txt_NE_Desc.Text.Trim()); if (ddb_NE_Column.selectedValue.Equals("Travel")) { cmd.Parameters.AddWithValue("@Travel", txt_NE_Val.Text.Trim()); cmd.Parameters.AddWithValue("@Acc", DBNull.Value); cmd.Parameters.AddWithValue("@Sub", DBNull.Value); cmd.Parameters.AddWithValue("@Tools", DBNull.Value); cmd.Parameters.AddWithValue("@ProgHrs", DBNull.Value); cmd.Parameters.AddWithValue("@InstHrs", DBNull.Value); } else if (ddb_NE_Column.selectedValue.Equals("Accomodation")) { cmd.Parameters.AddWithValue("@Travel", DBNull.Value); cmd.Parameters.AddWithValue("@Acc", txt_NE_Val.Text.Trim()); cmd.Parameters.AddWithValue("@Sub", DBNull.Value); cmd.Parameters.AddWithValue("@Tools", DBNull.Value); cmd.Parameters.AddWithValue("@ProgHrs", DBNull.Value); cmd.Parameters.AddWithValue("@InstHrs", DBNull.Value); } else if (ddb_NE_Column.selectedValue.Equals("Subsistence")) { cmd.Parameters.AddWithValue("@Travel", DBNull.Value); cmd.Parameters.AddWithValue("@Acc", DBNull.Value); cmd.Parameters.AddWithValue("@Sub", txt_NE_Val.Text.Trim()); cmd.Parameters.AddWithValue("@Tools", DBNull.Value); cmd.Parameters.AddWithValue("@ProgHrs", DBNull.Value); cmd.Parameters.AddWithValue("@InstHrs", DBNull.Value); } else if (ddb_NE_Column.selectedValue.Equals("Tools")) { cmd.Parameters.AddWithValue("@Travel", DBNull.Value); cmd.Parameters.AddWithValue("@Acc", DBNull.Value); cmd.Parameters.AddWithValue("@Sub", DBNull.Value); cmd.Parameters.AddWithValue("@Tools", txt_NE_Val.Text.Trim()); cmd.Parameters.AddWithValue("@ProgHrs", DBNull.Value); cmd.Parameters.AddWithValue("@InstHrs", DBNull.Value); } else if (ddb_NE_Column.selectedValue.Equals("Programming_Hours")) { cmd.Parameters.AddWithValue("@Travel", DBNull.Value); cmd.Parameters.AddWithValue("@Acc", DBNull.Value); cmd.Parameters.AddWithValue("@Sub", DBNull.Value); cmd.Parameters.AddWithValue("@Tools", DBNull.Value); cmd.Parameters.AddWithValue("@ProgHrs", txt_NE_Val.Text.Trim()); cmd.Parameters.AddWithValue("@InstHrs", DBNull.Value); } else if (ddb_NE_Column.selectedValue.Equals("Install_Hours")) { cmd.Parameters.AddWithValue("@Travel", DBNull.Value); cmd.Parameters.AddWithValue("@Acc", DBNull.Value); cmd.Parameters.AddWithValue("@Sub", DBNull.Value); cmd.Parameters.AddWithValue("@Tools", DBNull.Value); cmd.Parameters.AddWithValue("@ProgHrs", DBNull.Value); cmd.Parameters.AddWithValue("@InstHrs", txt_NE_Val.Text.Trim()); } cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date); cmd.Parameters.AddWithValue("@User", txt_NE_User.Text.Trim()); cmd.ExecuteNonQuery(); MessageBox.Show("New line successfully added.", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } else { MessageBox.Show("Please enter name in user field.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }