Счет № должен начинаться с 1 за каждый финансовый год
у меня есть одна таблица доступа, имеющая счет-фактуру no, она имеет первичный ключ и автоматически увеличенное значение(принимая Max no в cloumn и Inctrement +1 в коде только я пишу), я хочу, чтобы счет-фактура no запускался для каждого финансового года (с 1 апреля по 31 марта-это финансовый год )
Имя Поля Тип Данных:
Номер счета-фактуры
Государственный текст
CUSTOMERNAME текстовый
АДРЕС1 ТЕКСТ
АДРЕС2 текст
Тинно текст
Поно текст
Транспортный текст
BILLDATE Dtae / Time
Текст Типа Счета-Фактуры
PODATE дата/время
totalGrossAmt текст
totalVatAmt текст
Текст BILLAMT
TRANSPORTAMT текст
OTHERAMT textr
FINALAMT текст
Текст округления
Всего текста
Текст состояния
Налоговый текст
Что я уже пробовал:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.OleDb; using System.Configuration; using System.Globalization; using System.Collections; using System.Threading; namespace Victory_Printing { public partial class TAXINVOICE : Form { public TAXINVOICE() { InitializeComponent(); ddlTransaction.SelectedIndex = 1; FillInvoiceID(); this.ActiveControl = txtCustName; } int Ocredit; int invoice = 1; int rupees; string text; public static string numb; DataTable Products = new DataTable(); DataTable productdt = new DataTable(); public static int productnum; AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection(); AutoCompleteStringCollection descriptionCollection = new AutoCompleteStringCollection(); private void btnSave_Click(object sender, EventArgs e) { //PopupForm popup = new PopupForm(); // DialogResult dialogresult = popup.ShowDialog(); // if (dialogresult == DialogResult.OK) // { // Console.WriteLine("You clicked OK"); // } // else if (dialogresult == DialogResult.Cancel) // { // Console.WriteLine("You clicked either Cancel or X button in the top right corner"); // } // popup.Dispose(); //DataTable dt = new DataTable(); DataTable dtb = new DataTable(); DataRow dr0 = dtb.NewRow(); DataRow dr1 = dtb.NewRow(); DataRow dr2 = dtb.NewRow(); DataRow dr3 = dtb.NewRow(); DataRow dr4 = dtb.NewRow(); DataRow dr5 = dtb.NewRow(); DataRow dr6 = dtb.NewRow(); DataRow dr7 = dtb.NewRow(); DataRow dr8 = dtb.NewRow(); DataRow dr9 = dtb.NewRow(); DataRow dr10 = dtb.NewRow(); DataRow dr11 = dtb.NewRow(); DataRow dr12 = dtb.NewRow(); DataRow dr13 = dtb.NewRow(); DataRow dr14 = dtb.NewRow(); DataRow dr15 = dtb.NewRow(); DataRow dr16 = dtb.NewRow(); DataRow dr17 = dtb.NewRow(); DataRow dr18 = dtb.NewRow(); // DataRow dr16 = dt.NewRow(); /* Row 1 */ dtb.Columns.Add("SNo"); dtb.Columns.Add("DESCRIPTION"); dtb.Columns.Add("QTY"); dtb.Columns.Add("UOM"); dtb.Columns.Add("PRICE"); dtb.Columns.Add("GROSS AMT"); dtb.Columns.Add("VAT%"); dtb.Columns.Add("VAT AMT"); dtb.Columns.Add("TOTAL"); dr0[0] = txtSno1.Text; dr0[1] = txtDescription1.Text; dr0[2] = txtqty1.Text; dr0[3] = cbUOM1.SelectedItem; dr0[4] = txtPrice1.Text; dr0[5] = txtGrossAmt1.Text; dr0[6] = txtVAT1.Text; dr0[7] = txtVatAmt1.Text; dr0[8] = txtTotal1.Text; dr1[0] = txtSno2.Text; dr1[1] = txtDescription2.Text; dr1[2] = txtqty2.Text; dr1[3] = cbUOM2.SelectedItem; dr1[4] = txtPrice2.Text; dr1[5] = txtGrossAmt2.Text; dr1[6] = txtVAT2.Text; dr1[7] = txtVatAmt2.Text; dr1[8] = txtTotal2.Text; dr2[0] = txtSno3.Text; dr2[1] = txtDescription3.Text; dr2[2] = txtqty3.Text; dr2[3] = cbUOM3.SelectedItem; dr2[4] = txtPrice3.Text; dr2[5] = txtGrossAmt3.Text; dr2[6] = txtVAT3.Text; dr2[7] = txtVatAmt3.Text; dr2[8] = txtTotal3.Text; dr3[0] = txtSno4.Text; dr3[1] = txtDescription4.Text; dr3[2] = txtqty4.Text; dr3[3] = cbUOM4.SelectedItem; dr3[4] = txtPrice4.Text; dr3[5] = txtGrossAmt4.Text; dr3[6] = txtVAT4.Text; dr3[7] = txtVatAmt4.Text; dr3[8] = txtTotal4.Text; dr4[0] = txtSno5.Text; dr4[1] = txtDescription5.Text; dr4[2] = txtqty5.Text; dr4[3] = cbUOM5.SelectedItem; dr4[4] = txtPrice5.Text; dr4[5] = txtGrossAmt5.Text; dr4[6] = txtVAT5.Text; dr4[7] = txtVatAmt5.Text; dr4[8] = txtTotal5.Text; dr5[0] = txtSno6.Text; dr5[1] = txtDescription6.Text; dr5[2] = txtqty6.Text; dr5[3] = cbUOM6.SelectedItem; dr5[4] = txtPrice6.Text; dr5[5] = txtGrossAmt6.Text; dr5[6] = txtVAT6.Text; dr5[7] = txtVatAmt6.Text; dr5[8] = txtTotal6.Text; dr6[0] = txtSno7.Text; dr6[1] = txtDescription7.Text; dr6[2] = txtqty7.Text; dr6[3] = cbUOM7.SelectedItem; dr6[4] = txtPrice7.Text; dr6[5] = txtGrossAmt7.Text; dr6[6] = txtVAT7.Text; dr6[7] = txtVatAmt7.Text; dr6[8] = txtTotal7.Text; dr7[0] = txtSno8.Text; dr7[1] = txtDescription8.Text; dr7[2] = txtqty8.Text; dr7[3] = cbUOM8.SelectedItem; dr7[4] = txtPrice8.Text; dr7[5] = txtGrossAmt8.Text; dr7[6] = txtVAT8.Text; dr7[7] = txtVatAmt8.Text; dr7[8] = txtTotal8.Text; dr8[0] = txtSno9.Text; dr8[1] = txtDescription9.Text; dr8[2] = txtqty9.Text; dr8[3] = cbUOM9.SelectedItem; dr8[4] = txtPrice9.Text; dr8[5] = txtGrossAmt9.Text; dr8[6] = txtVAT9.Text; dr8[7] = txtVatAmt9.Text; dr8[8] = txtTotal9.Text; dr9[0] = txtSno10.Text; dr9[1] = txtDescription10.Text; dr9[2] = txtqty10.Text; dr9[3] = cbUOM10.SelectedItem; dr9[4] = txtPrice10.Text; dr9[5] = txtGrossAmt10.Text; dr9[6] = txtVAT10.Text; dr9[7] = txtVatAmt10.Text; dr9[8] = txtTotal10.Text; dr10[0] = txtSno11.Text; dr10[1] = txtDescription11.Text; dr10[2] = txtqty11.Text; dr10[3] = cbUOM11.SelectedItem; dr10[4] = txtPrice11.Text; dr10[5] = txtGrossAmt11.Text; dr10[6] = txtVAT11.Text; dr10[7] = txtVatAmt11.Text; dr10[8] = txtTotal11.Text; dr11[0] = txtSno12.Text; dr11[1] = txtDescription12.Text; dr11[2] = txtqty12.Text; dr11[3] = cbUOM12.SelectedItem; dr11[4] = txtPrice12.Text; dr11[5] = txtGrossAmt12.Text; dr11[6] = txtVAT12.Text; dr11[7] = txtVatAmt12.Text; dr11[8] = txtTotal12.Text; dr12[0] = txtSno13.Text; dr12[1] = txtDescription13.Text; dr12[2] = txtqty13.Text; dr12[3] = cbUOM13.SelectedItem; dr12[4] = txtPrice13.Text; dr12[5] = txtGrossAmt13.Text; dr12[6] = txtVAT13.Text; dr12[7] = txtVatAmt13.Text; dr12[8] = txtTotal13.Text; dr13[0] = txtSno14.Text; dr13[1] = txtDescription14.Text; dr13[2] = txtqty14.Text; dr13[3] = cbUOM14.SelectedItem; dr13[4] = txtPrice14.Text; dr13[5] = txtGrossAmt14.Text; dr13[6] = txtVAT14.Text; dr13[7] = txtVatAmt14.Text; dr13[8] = txtTotal14.Text; dr14[0] = txtSno15.Text; dr14[1] = txtDescription15.Text; dr14[2] = txtqty15.Text; dr14[3] = cbUOM15.SelectedItem; dr14[4] = txtPrice15.Text; dr14[5] = txtGrossAmt15.Text; dr14[6] = txtVAT15.Text; dr14[7] = txtVatAmt15.Text; dr14[8] = txtTotal15.Text; dr15[0] = txtSno16.Text; dr15[1] = txtDescription16.Text; dr15[2] = txtqty16.Text; dr15[3] = cbUOM16.SelectedItem; dr15[4] = txtPrice16.Text; dr15[5] = txtGrossAmt16.Text; dr15[6] = txtVAT16.Text; dr15[7] = txtVatAmt16.Text; dr15[8] = txtTotal16.Text; dr16[0] = txtSno17.Text; dr16[1] = txtDescription17.Text; dr16[2] = txtqty17.Text; dr16[3] = cbUOM17.SelectedItem; dr16[4] = txtPrice17.Text; dr16[5] = txtGrossAmt17.Text; dr16[6] = txtVAT17.Text; dr16[7] = txtVatAmt17.Text; dr16[8] = txtTotal17.Text; dr17[0] = txtSno18.Text; dr17[1] = txtDescription18.Text; dr17[2] = txtqty18.Text; dr17[3] = cbUOM18.SelectedItem; dr17[4] = txtPrice18.Text; dr17[5] = txtGrossAmt18.Text; dr17[6] = txtVAT18.Text; dr17[7] = txtVatAmt18.Text; dr17[8] = txtTotal18.Text; dr18[0] = txtSno19.Text; dr18[1] = txtDescription19.Text; dr18[2] = txtqty19.Text; dr18[3] = cbUOM19.SelectedItem; dr18[4] = txtPrice19.Text; dr18[5] = txtGrossAmt19.Text; dr18[6] = txtVAT19.Text; dr18[7] = txtVatAmt19.Text; dr18[8] = txtTotal19.Text; if (cbUOM1.SelectedValue != "Select") { dtb.Rows.Add(dr0); } if (cbUOM2.SelectedValue != "Select") { dtb.Rows.Add(dr1); } if (cbUOM3.SelectedValue != "Select") { dtb.Rows.Add(dr2); } if (cbUOM4.SelectedValue != "Select") { dtb.Rows.Add(dr3); } if (cbUOM5.SelectedValue != "Select") { dtb.Rows.Add(dr4); } if (cbUOM6.SelectedValue != "Select") { dtb.Rows.Add(dr5); } if (cbUOM7.SelectedValue != "Select") { dtb.Rows.Add(dr6); } if (cbUOM8.SelectedValue != "Select") { dtb.Rows.Add(dr7); } if (cbUOM9.SelectedValue != "Select") { dtb.Rows.Add(dr8); } if (cbUOM10.SelectedValue != "Select") { dtb.Rows.Add(dr9); } if (cbUOM11.SelectedValue != "Select") { dtb.Rows.Add(dr10); } if (cbUOM12.SelectedValue != "Select") { dtb.Rows.Add(dr11); } if (cbUOM13.SelectedValue != "Select") { dtb.Rows.Add(dr12); } if (cbUOM14.SelectedValue != "Select") { dtb.Rows.Add(dr13); } if (cbUOM15.SelectedValue != "Select") { dtb.Rows.Add(dr14); } if (cbUOM16.SelectedValue != "Select") { dtb.Rows.Add(dr15); } if (cbUOM17.SelectedValue != "Select") { dtb.Rows.Add(dr16); } if (cbUOM18.SelectedValue != "Select") { dtb.Rows.Add(dr17); } if (cbUOM19.SelectedValue != "Select") { dtb.Rows.Add(dr18); } //if (printDlg.ShowDialog() == DialogResult.OK) // printDoc.Print(); decimal a = 0, b = String.IsNullOrEmpty(txtFinalAmt.Text) ? 0 : decimal.Parse(txtFinalAmt.Text.Trim()); rupees = Convert.ToInt32(b); DialogResult dialogResult = MessageBox.Show("Are You Sure??", "Do you want to save?", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { //do something int num = Convert.ToInt32(txtInvoice.Text); string counterSales_InsertRow = "INSERT INTO TAXINVOICE(INVOICENO,STATE ,CUSTOMERNAME ,ADDRESS1,ADDRESS2,TINNO,PONO,TRANSPORT,InvoiceType,BILLDATE,PODATE,totalGrossAmt,totalVatAmt,BILLAMT,TRANSPORTAMT,OTHERAMT,FINALAMT,ROUNDOFF,GRANDTOTAL,TAX,CurrentYear,CreatedOn)VALUES (@INVOICENO,@STATE,@CUSTOMERNAME,@ADDRESS1,@ADDRESS2,@TINNO,@PONO,@TRANSPORT,@InvoiceType,@BILLDATE,@PODATE,@totalGrossAmt,@totalVatAmt,@BILLAMT,@TRANSPORTAMT,@OTHERAMT,@FINALAMT,@ROUNDOFF,@GRANDTOTAL,@TAX,@CurrentYear,@CreatedOn);"; OleDbParameter[] parameters = new OleDbParameter[22]; parameters[0] = new OleDbParameter("@INVOICENO", num); //parameters[0] = new OleDbParameter("@INVOICENO", OleDbType.Integer).Value = num; parameters[1] = new OleDbParameter("@STATE", comboBox1.Text); parameters[2] = new OleDbParameter("@CUSTOMERNAME", txtCustName.Text.ToUpper()); parameters[3] = new OleDbParameter("@ADDRESS1", txtAddress1.Text); parameters[4] = new OleDbParameter("@ADDRESS2", txtAddress2.Text); parameters[5] = new OleDbParameter("@TINNO", txtTINnum.Text); parameters[6] = new OleDbParameter("@PONO", txtPOnum.Text); parameters[7] = new OleDbParameter("@TRANSPORT", tbTransportValue.Text.ToUpper()); parameters[8] = new OleDbParameter("@InvoiceType", ddlTransaction.SelectedItem); parameters[9] = new OleDbParameter("@BILLDATE", Convert.ToDateTime(dtToday.Text)); parameters[10] = new OleDbParameter("@PODATE", CreatedDate.Text); parameters[11] = new OleDbParameter("@totalGrossAmt", txtTotalGrossAmt.Text); parameters[12] = new OleDbParameter("@totalVatAmt", txtTotalVATAMT.Text); parameters[13] = new OleDbParameter("@BILLAMT", txtTotals.Text); parameters[14] = new OleDbParameter("@TRANSPORTAMT", txtTransport.Text); parameters[15] = new OleDbParameter("@OTHERAMT", txtOthers.Text); parameters[16] = new OleDbParameter("@FINALAMT", txtTotals.Text); parameters[17] = new OleDbParameter("@ROUNDOFF", txtRoundOff.Text); parameters[18] = new OleDbParameter("@GRANDTOTAL", txtGrandTotal.Text); parameters[19] = new OleDbParameter("@TAX", txtVAT1.Text); parameters[20] = new OleDbParameter("@CurrentYear", DateTime.Now.Year); parameters[21] = new OleDbParameter("@CreatedOn", Convert.ToDateTime(dtToday.Text)); ExecuteOtherGoodsDatabaseTransaction(counterSales_InsertRow, parameters); InsertAllInvoiceItems(); // string Productscount = "select count()"; GlobalClass.dtHeaders = new DataTable(); Headers dsh = new Headers(); GlobalClass.dtHeaders = dsh.Tables[0]; //numb = ConvertNumbertoWords(number) + "Only"; //for (int i = 0; i < 5; i++) numb = rupeestoword(rupees); // rupees(rupees); foreach (DataRow Datarow in dtb.Rows) { DataRow dr = GlobalClass.dtHeaders.NewRow(); dr["CustomerName"] = " " + txtCustName.Text.ToUpper(); dr["Address1"] = " " + txtAddress1.Text; dr["Address2"] = " " + txtAddress2.Text; dr["TIN"] = txtTINnum.Text.ToUpper(); dr["InvoiceNo"] = txtInvoice.Text.ToUpper(); dr["InvoiceDate"] = Convert.ToDateTime(dtToday.Text).ToString("dd/MM/yy"); dr["PONo"] = txtPOnum.Text.ToUpper(); dr["Dated"] = CreatedDate.Text; dr["Transport"] = tbTransportValue.Text.Trim().ToUpper(); dr["SNO"] = Datarow.ItemArray[0]; dr["DESCRIPTION"] = Datarow.ItemArray[1].ToString().ToUpper(); dr["QTY"] = Datarow.ItemArray[2].ToString(); dr["UOM"] = Datarow.ItemArray[3].ToString(); dr["PRICE"] = Datarow.ItemArray[4].ToString(); dr["GROSSAMT"] = Datarow.ItemArray[5].ToString(); dr["VAT"] = Datarow.ItemArray[6].ToString(); dr["VATAMT"] = Datarow.ItemArray[7].ToString(); dr["TOTAL"] = Datarow.ItemArray[8].ToString(); dr["GROSSTOTAL"] = txtTotalGrossAmt.Text; dr["VATTOTAL"] = txtTotalVATAMT.Text; dr["TOTALAMT"] = txtTotals.Text; dr["FINALAMOUNT"] = txtTotals.Text; dr["AMTINWORDS"] = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(numb.ToLower()); dr["TRANSPORT"] = txtTransport.Text.ToUpper(); dr["OTHERS"] = txtOthers.Text; dr["ROUNDOFF"] = txtRoundOff.Text; dr["GRANDTOTAL"] = txtGrandTotal.Text + ".00"; dr["INVOICETYPE"] = ddlTransaction.Text.ToUpper(); GlobalClass.dtHeaders.Rows.Add(dr); } Form4 frm = new Form4(); frm.Show(); this.Hide(); clear(); } else if (dialogResult == DialogResult.No) { //this.Close(); } } public void clear() { // textBox1.Text = ""; txtAddress1.Text = ""; txtAddress2.Text = ""; txtCustName.Text = ""; txtPOnum.Text = ""; txtTINnum.Text = ""; txtTransport.Text = "0.00"; txtOthers.Text = "0.00"; txtFinalAmt.Text = "0.00"; txtGrandTotal.Text = "0.00"; txtRoundOff.Text = ""; tbTransportValue.Text = ""; txtDescription1.Text = ""; txtDescription2.Text = ""; txtDescription3.Text = ""; txtDescription4.Text = ""; txtDescription5.Text = ""; txtDescription6.Text = ""; txtDescription7.Text = ""; txtDescription8.Text = ""; txtDescription9.Text = ""; txtDescription10.Text = ""; txtDescription11.Text = ""; txtDescription12.Text = ""; txtDescription13.Text = ""; txtDescription15.Text = ""; txtDescription14.Text = ""; txtDescription16.Text = ""; txtDescription18.Text = ""; txtDescription17.Text = ""; txtDescription19.Text = ""; txtqty1.Text = ""; txtqty2.Text = ""; txtqty3.Text = ""; txtqty4.Text = ""; txtqty5.Text = ""; txtqty6.Text = ""; txtqty7.Text = ""; txtqty8.Text = ""; txtqty9.Text = ""; txtqty10.Text = ""; txtqty11.Text = ""; txtqty12.Text = ""; txtqty13.Text = ""; txtqty14.Text = ""; txtqty15.Text = ""; txtqty16.Text = ""; txtqty17.Text = ""; txtqty18.Text = ""; txtqty19.Text = ""; txtPrice1.Text = ""; txtPrice2.Text = ""; txtPrice3.Text = ""; txtPrice4.Text = ""; txtPrice5.Text = ""; txtPrice6.Text = ""; txtPrice7.Text = ""; txtPrice8.Text = ""; txtPrice9.Text = ""; txtPrice10.Text = ""; txtPrice11.Text = ""; txtPrice12.Text = ""; txtPrice13.Text = ""; txtPrice14.Text = ""; txtPrice15.Text = ""; txtPrice16.Text = ""; txtPrice17.Text = ""; txtPrice18.Text = ""; txtPrice19.Text = ""; txtSno1.Text = ""; txtSno2.Text = ""; txtSno3.Text = ""; txtSno4.Text = ""; txtSno5.Text = ""; txtSno6.Text = ""; txtSno7.Text = ""; txtSno8.Text = ""; txtSno9.Text = ""; txtSno10.Text = ""; txtSno11.Text = ""; txtSno12.Text = ""; txtSno13.Text = ""; txtSno14.Text = ""; txtSno15.Text = ""; txtSno16.Text = ""; txtSno17.Text = ""; txtSno18.Text = ""; txtSno19.Text = ""; txtGrossAmt1.Text = ""; txtGrossAmt2.Text = ""; txtGrossAmt3.Text = ""; txtGrossAmt4.Text = ""; txtGrossAmt5.Text = ""; txtGrossAmt6.Text = ""; txtGrossAmt7.Text = ""; txtGrossAmt8.Text = ""; txtGrossAmt9.Text = ""; txtGrossAmt10.Text = ""; txtGrossAmt11.Text = ""; txtGrossAmt12.Text = ""; txtGrossAmt13.Text = ""; txtGrossAmt14.Text = ""; txtGrossAmt15.Text = ""; txtGrossAmt16.Text = ""; txtGrossAmt17.Text = ""; txtGrossAmt18.Text = ""; txtGrossAmt19.Text = ""; txtVatAmt1.Text = ""; txtVatAmt2.Text = ""; txtVatAmt3.Text = ""; txtVatAmt4.Text = ""; txtVatAmt5.Text = ""; txtVatAmt6.Text = ""; txtVatAmt7.Text = ""; txtVatAmt8.Text = ""; txtVatAmt9.Text = ""; txtVatAmt10.Text = ""; txtVatAmt11.Text = ""; txtVatAmt12.Text = ""; txtVatAmt13.Text = ""; txtVatAmt14.Text = ""; txtVatAmt15.Text = ""; txtVatAmt16.Text = ""; txtVatAmt17.Text = ""; txtVatAmt18.Text = ""; txtVatAmt19.Text = ""; txtTotal1.Text = ""; txtTotal2.Text = ""; txtTotal3.Text = ""; txtTotal4.Text = ""; txtTotal5.Text = ""; txtTotal6.Text = ""; txtTotal7.Text = ""; txtTotal8.Text = ""; txtTotal9.Text = ""; txtTotal10.Text = ""; txtTotal11.Text = ""; txtTotal12.Text = ""; txtTotal13.Text = ""; txtTotal14.Text = ""; txtTotal15.Text = ""; txtTotal16.Text = ""; txtTotal17.Text = ""; txtTotal18.Text = ""; txtTotal19.Text = ""; txtVAT1.Text = ""; txtVAT2.Text = ""; txtVAT3.Text = ""; txtVAT4.Text = ""; txtVAT5.Text = ""; txtVAT6.Text = ""; txtVAT7.Text = ""; txtVAT8.Text = ""; txtVAT9.Text = ""; txtVAT10.Text = ""; txtVAT11.Text = ""; txtVAT12.Text = ""; txtVAT13.Text = ""; txtVAT14.Text = ""; txtVAT15.Text = ""; txtVAT16.Text = ""; txtVAT17.Text = ""; txtVAT18.Text = ""; txtVAT19.Text = ""; cbUOM1.SelectedValue = ""; cbUOM2.SelectedValue = ""; cbUOM3.SelectedValue = ""; cbUOM4.SelectedValue = ""; cbUOM5.SelectedValue = ""; cbUOM6.SelectedValue = ""; cbUOM7.SelectedValue = ""; cbUOM8.SelectedValue = ""; cbUOM9.SelectedValue = ""; cbUOM10.SelectedValue = ""; cbUOM11.SelectedValue = ""; cbUOM12.SelectedValue = ""; cbUOM13.SelectedValue = ""; cbUOM14.SelectedValue = ""; cbUOM15.SelectedValue = ""; cbUOM16.SelectedValue = ""; cbUOM17.SelectedValue = ""; cbUOM18.SelectedValue = ""; cbUOM19.SelectedValue = ""; FillInvoiceID(); } private void ExecuteOtherGoodsDatabaseTransaction(string command, OleDbParameter[] parameter) { string @filelocation = ConfigurationManager.AppSettings["FilePath"].ToString(); OleDbConnection conn = new OleDbConnection(@filelocation); //OleDbConnection con = new OleDbConnection(@filelocation); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = conn; cmd.CommandText = command; cmd.Parameters.AddRange(parameter); cmd.CommandType = CommandType.Text; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); } private void InsertAllInvoiceItems() { for (int controlIndex = 1; controlIndex <= 19; controlIndex++) { string name = "txtDescription" + controlIndex; TextBox txtBox = this.Controls.Find(name, true)[0] as TextBox; string insertedproductName = txtBox.Text; name = "txtqty" + controlIndex; txtBox = this.Controls.Find(name, true)[0] as TextBox; string insertedquantity = txtBox.Text; name = "cbUOM" + controlIndex; ComboBox cmb = this.Controls.Find(name, true)[0] as ComboBox; string uom = cmb.Text; name = "txtPrice" + controlIndex; txtBox = this.Controls.Find(name, true)[0] as TextBox; string insertedprice = txtBox.Text; name = "txtGrossAmt" + controlIndex; txtBox = this.Controls.Find(name, true)[0] as TextBox; string insertedGrossAmt = txtBox.Text; name = "txtVAT" + controlIndex; txtBox = this.Controls.Find(name, true)[0] as TextBox; string insertedvat = txtBox.Text; name = "txtVatAmt" + controlIndex; txtBox = this.Controls.Find(name, true)[0] as TextBox; string insertedVATamt = txtBox.Text; name = "txtTotal" + controlIndex; txtBox = this.Controls.Find(name, true)[0] as TextBox; string insertedtotal = txtBox.Text; if (!string.IsNullOrEmpty(insertedproductName)) { int insertedProductId = GetProductId(insertedproductName); //InsertIntoInvoiceItems(txtInvoice.Text.Trim(), insertedProductId, insertedquantity, insertedprice, insertedGrossAmt, insertedvat, insertedVATamt, insertedtotal); InsertIntoInvoiceItems(txtInvoice.Text.Trim(), insertedProductId, insertedquantity, uom, insertedprice, insertedGrossAmt, insertedvat, insertedVATamt, insertedtotal); } } } private void InsertIntoInvoiceItems(string invoiceNumber, int productId, string quantity, string uom, string price, string GrossAmt, string vat, string vatamount, string total) { string InsertInvoiceItems = "INSERT INTO InvoiceItems(InvoiceNumber,ProductId ,Quantity,UOM ,UnitPrice,GrossAmount,VAT,VatAmount,Total)VALUES (@InvoiceNumber,@ProductId,@Quantity,@Uom,@UnitPrice,@GrossAmount,@VAT,@VatAmount,@Total);"; OleDbParameter[] paramet = new OleDbParameter[9]; paramet[0] = new OleDbParameter("@InvoiceNumber", invoiceNumber); paramet[1] = new OleDbParameter("@ProductId", productId); paramet[2] = new OleDbParameter("@Quantity", quantity); paramet[3] = new OleDbParameter("@Uom", uom); paramet[4] = new OleDbParameter("@UnitPrice", price); paramet[5] = new OleDbParameter("@GrossAmount", GrossAmt); paramet[6] = new OleDbParameter("@VAT", vat); paramet[7] = new OleDbParameter("@VatAmount", vatamount); paramet[8] = new OleDbParameter("@Total", total); ExecuteOtherGoodsDatabaseTransaction(InsertInvoiceItems, paramet); } private void InsertIntoInvoiceItems(string invoiceNumber, int productId, string quantity, string price, string GrossAmt, string vat, string vatamount, string total) { string InsertInvoiceItems = "INSERT INTO InvoiceItems(InvoiceNumber,ProductId ,Quantity ,UnitPrice,GrossAmount,VAT,VatAmount,Total)VALUES (@InvoiceNumber,@ProductId,@Quantity,@UnitPrice,@GrossAmount,@VAT,@VatAmount,@Total);"; OleDbParameter[] paramet = new OleDbParameter[8]; paramet[0] = new OleDbParameter("@InvoiceNumber", invoiceNumber); paramet[1] = new OleDbParameter("@ProductId", productId); paramet[2] = new OleDbParameter("@Quantity", quantity); paramet[3] = new OleDbParameter("@UnitPrice", price); paramet[4] = new OleDbParameter("@GrossAmount", GrossAmt); paramet[5] = new OleDbParameter("@VAT", vat); paramet[6] = new OleDbParameter("@VatAmount", vatamount); paramet[7] = new OleDbParameter("@Total", total); ExecuteOtherGoodsDatabaseTransaction(InsertInvoiceItems, paramet); } private int GetProductId(string name) { int productId = 0; try { productId = fetchProductId(name); if (productId == 0) { if (insertProduct(name)) { Thread.Sleep(750); productId = fetchProductId(name); } } } catch (Exception ex) { } return productId; } private bool insertProduct(string name) { bool isInsert = false; string connectionstring = ConfigurationManager.AppSettings["FilePath"].ToString(); string getproductid = "INSERT INTO Products(ProductName) VALUES('" + name.ToString().ToUpper() + "')"; OleDbConnection oledproductidcon = new OleDbConnection(connectionstring); //OleDbConnection c2 = new OleDbConnection(co); if (oledproductidcon.State == ConnectionState.Open) { oledproductidcon.Close(); } oledproductidcon.Open(); OleDbCommand oledbproductcmd = new OleDbCommand(getproductid, oledproductidcon); int rows = oledbproductcmd.ExecuteNonQuery(); if (rows > 0) { isInsert = true; } return isInsert; } private int fetchProductId(string name) { int returnProductId = 0; string connectionstring = ConfigurationManager.AppSettings["FilePath"].ToString(); string getproductid = "SELECT ProductId FROM Products where lcase(ProductName)='" + name.ToLower().ToString() + "'"; OleDbConnection oledproductidcon = new OleDbConnection(connectionstring); //OleDbConnection c2 = new OleDbConnection(co); if (oledproductidcon.State == ConnectionState.Open) { oledproductidcon.Close(); } oledproductidcon.Open(); OleDbCommand oledbproductcmd = new OleDbCommand(getproductid, oledproductidcon); object obj = oledbproductcmd.ExecuteScalar(); if (obj != null) { returnProductId = int.Parse(obj.ToString()); } oledproductidcon.Close(); return returnProductId; } private DataTable getqtyandprice(string name) { // CommandText = @"SELECT i.Quantity,i.UnitPrice FROM InvoiceItems i INNER JOIN (Products INNER JOIN " //+ " InvoiceItems ON Products.ProductId = InvoiceItems.ProductId) ON TAXINVOICE.INVOICENO = " //+ " InvoiceItems.InvoiceNumber WHERE TAXINVOICE.CUSTOMERNAME = '" + customerName + "'"; string s = "SELECT top 1 InvoiceItems.Quantity, InvoiceItems.UnitPrice,InvoiceItems.UOM ,InvoiceItems.Total FROM TAXINVOICE INNER JOIN (InvoiceItems INNER JOIN Products ON InvoiceItems.ProductId = Products.ProductId) ON TAXINVOICE.INVOICENO = InvoiceItems.InvoiceNumber WHERE TAXINVOICE.customername ='" + txtCustName.Text.ToString() + "' AND Products.ProductName ='" + name.ToString() + " 'order by TAXINVOICE.invoiceno desc"; //string s = "SELECT i.UnitPrice FROM Products p INNER JOIN InvoiceItems i on p.ProductId = i.ProductId where ProductName='" + name.ToString() + "'"; string @filelocations = ConfigurationManager.AppSettings["FilePath"].ToString(); OleDbConnection connections = new OleDbConnection(@filelocations); //OleDbConnection qpcon = new OleDbConnection(); OleDbCommand qpcmd = new OleDbCommand(s, connections); OleDbDataAdapter qpdatadpter = new OleDbDataAdapter(qpcmd); //DataSet datset = new DataSet(); DataTable qpdataset = new DataTable(); qpdatadpter.Fill(qpdataset); return qpdataset; } private void Quantity_Changed(object sender, EventArgs e) { TextBox txtqty = (TextBox)sender; string txtName = txtqty.Name.Replace("txtqty", ""); //GetAndCalculateTotal(txtqty.Name.Substring(txtqty.Name.Length - 1)); GetAndCalculateTotal(txtName); } private void Price_Changed(object sender, EventArgs e) { TextBox txtqty = (TextBox)sender; string txtName = txtqty.Name.Replace("txtPrice", ""); //GetAndCalculateTotal(txtqty.Name.Substring(txtqty.Name.Length - 1)); GetAndCalculateTotal(txtName); } private decimal CalculateGrossAmt(decimal qty, decimal price) { decimal value = qty * price; return value; } private void TextBoxAcceptOnlyNumbers(object sender, KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.') { e.Handled = true; } if (e.KeyChar == '.' && (sender as TextBox).Text.IndexOf('.') > -1) { e.Handled = true; } } private decimal CalculateVATAmt(decimal GrossAmt, decimal vat) { //int vat = 5; decimal value = ((GrossAmt * vat) / 100); return value; } private decimal CalculateTotal(decimal GrossAmt, decimal totalamount) { //int vat = 5; decimal value = GrossAmt + totalamount; return value; } private void GetAndCalculateTotal(string selectedNumber) { decimal qtyValue = 0; decimal priceValue = 0; //decimal discValue = 0; string ItemVal = ""; decimal GrossAmt = 0; decimal totalamount = 0; decimal vatpercent = 0; switch (selectedNumber) { case "1": qtyValue = String.IsNullOrEmpty(txtqty1.Text) ? 0 : decimal.Parse(txtqty1.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice1.Text) ? 0 : decimal.Parse(txtPrice1.Text.Trim()); txtGrossAmt1.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt1.Text); vatpercent = String.IsNullOrEmpty(txtVAT1.Text) ? 0 : decimal.Parse(txtVAT1.Text.Trim()); txtVatAmt1.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt1.Text); txtTotal1.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); break; case "2": qtyValue = String.IsNullOrEmpty(txtqty2.Text) ? 0 : decimal.Parse(txtqty2.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice2.Text) ? 0 : decimal.Parse(txtPrice2.Text.Trim()); txtGrossAmt2.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt2.Text); vatpercent = String.IsNullOrEmpty(txtVAT2.Text) ? 0 : decimal.Parse(txtVAT2.Text.Trim()); txtVatAmt2.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt2.Text); txtTotal2.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); // lblTotal.Text = (decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal2.Text.Trim())).ToString(); break; case "3": qtyValue = String.IsNullOrEmpty(txtqty3.Text) ? 0 : decimal.Parse(txtqty3.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice3.Text) ? 0 : decimal.Parse(txtPrice3.Text.Trim()); txtGrossAmt3.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt3.Text); vatpercent = String.IsNullOrEmpty(txtVAT3.Text) ? 0 : decimal.Parse(txtVAT3.Text.Trim()); txtVatAmt3.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt3.Text); txtTotal3.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); // lblTotal.Text = decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal3.Text.Trim()).ToString(); break; case "4": qtyValue = String.IsNullOrEmpty(txtqty4.Text) ? 0 : decimal.Parse(txtqty4.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice4.Text) ? 0 : decimal.Parse(txtPrice4.Text.Trim()); txtGrossAmt4.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt4.Text); vatpercent = String.IsNullOrEmpty(txtVAT4.Text) ? 0 : decimal.Parse(txtVAT4.Text.Trim()); txtVatAmt4.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt4.Text); txtTotal4.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); //tbFTotal4.Text = CalculateTotal(qtyValue, priceValue, discValue).ToString(); // lblTotal.Text = decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal4.Text.Trim()).ToString(); break; case "5": qtyValue = String.IsNullOrEmpty(txtqty5.Text) ? 0 : decimal.Parse(txtqty5.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice5.Text) ? 0 : decimal.Parse(txtPrice5.Text.Trim()); txtGrossAmt5.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt5.Text); vatpercent = String.IsNullOrEmpty(txtVAT5.Text) ? 0 : decimal.Parse(txtVAT5.Text.Trim()); txtVatAmt5.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt5.Text); txtTotal5.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); // lblTotal.Text = decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal5.Text.Trim()).ToString(); break; case "6": qtyValue = String.IsNullOrEmpty(txtqty6.Text) ? 0 : decimal.Parse(txtqty6.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice6.Text) ? 0 : decimal.Parse(txtPrice6.Text.Trim()); txtGrossAmt6.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt6.Text); vatpercent = String.IsNullOrEmpty(txtVAT6.Text) ? 0 : decimal.Parse(txtVAT6.Text.Trim()); txtVatAmt6.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt6.Text); txtTotal6.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); // lblTotal.Text = decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal6.Text.Trim()).ToString(); break; case "7": qtyValue = String.IsNullOrEmpty(txtqty7.Text) ? 0 : decimal.Parse(txtqty7.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice7.Text) ? 0 : decimal.Parse(txtPrice7.Text.Trim()); txtGrossAmt7.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt7.Text); vatpercent = String.IsNullOrEmpty(txtVAT7.Text) ? 0 : decimal.Parse(txtVAT7.Text.Trim()); txtVatAmt7.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt7.Text); txtTotal7.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); //lblTotal.Text = decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal7.Text.Trim()).ToString(); break; case "8": qtyValue = String.IsNullOrEmpty(txtqty8.Text) ? 0 : decimal.Parse(txtqty8.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice8.Text) ? 0 : decimal.Parse(txtPrice8.Text.Trim()); txtGrossAmt8.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt8.Text); vatpercent = String.IsNullOrEmpty(txtVAT8.Text) ? 0 : decimal.Parse(txtVAT8.Text.Trim()); txtVatAmt8.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt8.Text); txtTotal8.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); // lblTotal.Text = decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal8.Text.Trim()).ToString(); break; case "9": qtyValue = String.IsNullOrEmpty(txtqty9.Text) ? 0 : decimal.Parse(txtqty9.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice9.Text) ? 0 : decimal.Parse(txtPrice9.Text.Trim()); txtGrossAmt9.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt9.Text); vatpercent = String.IsNullOrEmpty(txtVAT9.Text) ? 0 : decimal.Parse(txtVAT9.Text.Trim()); txtVatAmt9.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt9.Text); txtTotal9.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); //lblTotal.Text = (decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal1.Text.Trim())).ToString(); break; case "10": qtyValue = String.IsNullOrEmpty(txtqty10.Text) ? 0 : decimal.Parse(txtqty10.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice10.Text) ? 0 : decimal.Parse(txtPrice10.Text.Trim()); txtGrossAmt10.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt10.Text); vatpercent = String.IsNullOrEmpty(txtVAT10.Text) ? 0 : decimal.Parse(txtVAT10.Text.Trim()); txtVatAmt10.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt10.Text); txtTotal10.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); // lblTotal.Text = (decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal2.Text.Trim())).ToString(); break; case "11": qtyValue = String.IsNullOrEmpty(txtqty11.Text) ? 0 : decimal.Parse(txtqty11.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice11.Text) ? 0 : decimal.Parse(txtPrice11.Text.Trim()); txtGrossAmt11.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt11.Text); vatpercent = String.IsNullOrEmpty(txtVAT11.Text) ? 0 : decimal.Parse(txtVAT11.Text.Trim()); txtVatAmt11.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt11.Text); txtTotal11.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); // lblTotal.Text = decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal3.Text.Trim()).ToString(); break; case "12": qtyValue = String.IsNullOrEmpty(txtqty12.Text) ? 0 : decimal.Parse(txtqty12.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice12.Text) ? 0 : decimal.Parse(txtPrice12.Text.Trim()); txtGrossAmt12.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt12.Text); vatpercent = String.IsNullOrEmpty(txtVAT12.Text) ? 0 : decimal.Parse(txtVAT12.Text.Trim()); txtVatAmt12.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt12.Text); txtTotal12.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); //tbFTotal4.Text = CalculateTotal(qtyValue, priceValue, discValue).ToString(); // lblTotal.Text = decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal4.Text.Trim()).ToString(); break; case "13": qtyValue = String.IsNullOrEmpty(txtqty13.Text) ? 0 : decimal.Parse(txtqty13.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice13.Text) ? 0 : decimal.Parse(txtPrice13.Text.Trim()); txtGrossAmt13.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt13.Text); vatpercent = String.IsNullOrEmpty(txtVAT13.Text) ? 0 : decimal.Parse(txtVAT13.Text.Trim()); txtVatAmt13.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt13.Text); txtTotal13.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); // lblTotal.Text = decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal5.Text.Trim()).ToString(); break; case "14": qtyValue = String.IsNullOrEmpty(txtqty14.Text) ? 0 : decimal.Parse(txtqty14.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice14.Text) ? 0 : decimal.Parse(txtPrice14.Text.Trim()); txtGrossAmt14.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt14.Text); vatpercent = String.IsNullOrEmpty(txtVAT14.Text) ? 0 : decimal.Parse(txtVAT14.Text.Trim()); txtVatAmt14.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt14.Text); txtTotal14.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); // lblTotal.Text = decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal6.Text.Trim()).ToString(); break; case "15": qtyValue = String.IsNullOrEmpty(txtqty15.Text) ? 0 : decimal.Parse(txtqty15.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice15.Text) ? 0 : decimal.Parse(txtPrice15.Text.Trim()); txtGrossAmt15.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt15.Text); vatpercent = String.IsNullOrEmpty(txtVAT15.Text) ? 0 : decimal.Parse(txtVAT15.Text.Trim()); txtVatAmt15.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt15.Text); txtTotal15.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); //lblTotal.Text = decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal7.Text.Trim()).ToString(); break; case "16": qtyValue = String.IsNullOrEmpty(txtqty16.Text) ? 0 : decimal.Parse(txtqty16.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice16.Text) ? 0 : decimal.Parse(txtPrice16.Text.Trim()); txtGrossAmt16.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt16.Text); vatpercent = String.IsNullOrEmpty(txtVAT16.Text) ? 0 : decimal.Parse(txtVAT16.Text.Trim()); txtVatAmt16.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt16.Text); txtTotal16.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); // lblTotal.Text = decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal8.Text.Trim()).ToString(); break; case "17": qtyValue = String.IsNullOrEmpty(txtqty17.Text) ? 0 : decimal.Parse(txtqty17.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice17.Text) ? 0 : decimal.Parse(txtPrice17.Text.Trim()); txtGrossAmt17.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt17.Text); vatpercent = String.IsNullOrEmpty(txtVAT17.Text) ? 0 : decimal.Parse(txtVAT17.Text.Trim()); txtVatAmt17.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt17.Text); txtTotal17.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); // lblTotal.Text = decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal8.Text.Trim()).ToString(); break; case "18": qtyValue = String.IsNullOrEmpty(txtqty18.Text) ? 0 : decimal.Parse(txtqty18.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice18.Text) ? 0 : decimal.Parse(txtPrice18.Text.Trim()); txtGrossAmt18.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt18.Text); vatpercent = String.IsNullOrEmpty(txtVAT18.Text) ? 0 : decimal.Parse(txtVAT18.Text.Trim()); txtVatAmt18.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt18.Text); txtTotal18.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); // lblTotal.Text = decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal8.Text.Trim()).ToString(); break; case "19": qtyValue = String.IsNullOrEmpty(txtqty19.Text) ? 0 : decimal.Parse(txtqty19.Text.Trim()); priceValue = String.IsNullOrEmpty(txtPrice19.Text) ? 0 : decimal.Parse(txtPrice19.Text.Trim()); txtGrossAmt19.Text = ((float)CalculateGrossAmt(qtyValue, priceValue)).ToString("0.00"); GrossAmt = Convert.ToDecimal(txtGrossAmt19.Text); vatpercent = String.IsNullOrEmpty(txtVAT19.Text) ? 0 : decimal.Parse(txtVAT19.Text.Trim()); txtVatAmt19.Text = ((float)CalculateVATAmt(GrossAmt, vatpercent)).ToString("0.00"); totalamount = Convert.ToDecimal(txtVatAmt19.Text); txtTotal19.Text = ((float)CalculateTotal(GrossAmt, totalamount)).ToString("0.00"); // lblTotal.Text = decimal.Parse(lblTotal.Text) + decimal.Parse(tbFTotal8.Text.Trim()).ToString(); break; } txtTotalGrossAmt.Text = ((string.IsNullOrEmpty(txtGrossAmt1.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt1.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt2.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt2.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt3.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt3.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt4.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt4.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt5.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt5.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt6.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt6.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt7.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt7.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt8.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt8.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt9.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt9.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt10.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt10.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt11.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt11.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt12.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt12.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt13.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt13.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt14.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt14.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt15.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt15.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt16.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt16.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt17.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt17.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt18.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt18.Text.Trim())) + (string.IsNullOrEmpty(txtGrossAmt19.Text.Trim()) ? 0 : decimal.Parse(txtGrossAmt19.Text.Trim()))).ToString(); txtTotalVATAMT.Text = ((string.IsNullOrEmpty(txtVatAmt1.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt1.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt2.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt2.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt3.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt3.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt4.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt4.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt5.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt5.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt6.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt6.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt7.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt7.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt8.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt8.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt9.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt9.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt10.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt10.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt11.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt11.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt12.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt12.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt13.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt13.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt14.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt14.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt15.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt15.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt16.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt16.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt17.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt17.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt18.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt18.Text.Trim())) + (string.IsNullOrEmpty(txtVatAmt19.Text.Trim()) ? 0 : decimal.Parse(txtVatAmt19.Text.Trim()))).ToString(); txtTotals.Text = ((string.IsNullOrEmpty(txtTotal1.Text.Trim()) ? 0 : decimal.Parse(txtTotal1.Text.Trim())) + (string.IsNullOrEmpty(txtTotal2.Text.Trim()) ? 0 : decimal.Parse(txtTotal2.Text.Trim())) + (string.IsNullOrEmpty(txtTotal3.Text.Trim()) ? 0 : decimal.Parse(txtTotal3.Text.Trim())) + (string.IsNullOrEmpty(txtTotal4.Text.Trim()) ? 0 : decimal.Parse(txtTotal4.Text.Trim())) + (string.IsNullOrEmpty(txtTotal5.Text.Trim()) ? 0 : decimal.Parse(txtTotal5.Text.Trim())) + (string.IsNullOrEmpty(txtTotal6.Text.Trim()) ? 0 : decimal.Parse(txtTotal6.Text.Trim())) + (string.IsNullOrEmpty(txtTotal7.Text.Trim()) ? 0 : decimal.Parse(txtTotal7.Text.Trim())) + (string.IsNullOrEmpty(txtTotal8.Text.Trim()) ? 0 : decimal.Parse(txtTotal8.Text.Trim())) + (string.IsNullOrEmpty(txtTotal9.Text.Trim()) ? 0 : decimal.Parse(txtTotal9.Text.Trim())) + (string.IsNullOrEmpty(txtTotal10.Text.Trim()) ? 0 : decimal.Parse(txtTotal10.Text.Trim())) + (string.IsNullOrEmpty(txtTotal11.Text.Trim()) ? 0 : decimal.Parse(txtTotal11.Text.Trim())) + (string.IsNullOrEmpty(txtTotal12.Text.Trim()) ? 0 : decimal.Parse(txtTotal12.Text.Trim())) + (string.IsNullOrEmpty(txtTotal13.Text.Trim()) ? 0 : decimal.Parse(txtTotal13.Text.Trim())) + (string.IsNullOrEmpty(txtTotal14.Text.Trim()) ? 0 : decimal.Parse(txtTotal14.Text.Trim())) + (string.IsNullOrEmpty(txtTotal15.Text.Trim()) ? 0 : decimal.Parse(txtTotal15.Text.Trim())) + (string.IsNullOrEmpty(txtTotal16.Text.Trim()) ? 0 : decimal.Parse(txtTotal16.Text.Trim())) + (string.IsNullOrEmpty(txtTotal17.Text.Trim()) ? 0 : decimal.Parse(txtTotal17.Text.Trim())) + (string.IsNullOrEmpty(txtTotal18.Text.Trim()) ? 0 : decimal.Parse(txtTotal18.Text.Trim())) + (string.IsNullOrEmpty(txtTotal19.Text.Trim()) ? 0 : decimal.Parse(txtTotal19.Text.Trim()))).ToString(); txtGrandTotal.Text = txtFinalAmt.Text; txtFinalAmt.Text = txtTotals.Text; //lbltotalamount.Text = txtTotals.Text; //decimal b = String.IsNullOrEmpty(txtTotals.Text) ? 0 : decimal.Parse(txtTotals.Text.Trim()); //decimal a = String.IsNullOrEmpty(lblOldBal.Text) ? 0 : decimal.Parse(lblOldBal.Text.Trim()); //txtFinalAmt.Text = (a+b).ToString(); //txtGrandTotal.Text = (a + b).ToString(); //finalcalculation(); //finalbill(); roundoff(); } public void roundoff() { string outPut = "0"; text = txtFinalAmt.Text; decimal value; if (decimal.TryParse(text, out value)) { if (value.ToString().Split('.').Length == 2) { outPut = value.ToString().Split('.')[1].Substring(0, value.ToString().Split('.')[1].Length); } if (Convert.ToInt32(outPut) >= 50) { value = Convert.ToInt32(value.ToString().Split('.')[0].Substring(0, value.ToString().Split('.')[0].Length)) + 1; } //else if (Convert.ToInt32(outPut) == 0) //{ // value = 0; //} else { value = Convert.ToInt32(value.ToString().Split('.')[0].Substring(0, value.ToString().Split('.')[0].Length)); } //value = Math.Round(value); decimal x = String.IsNullOrEmpty(txtFinalAmt.Text) ? 0 : decimal.Parse(txtFinalAmt.Text.Trim()); decimal y = (x - value); if (x <= value) { string var = y.ToString(); var = var.Replace("-", ""); txtRoundOff.Text = "+ " + var; //decimal add1 = Convert.ToDecimal(var); ////decimal add2 = String.IsNullOrEmpty(txtGrandTotal.Text) ? 0 : decimal.Parse(txtGrandTotal.Text.Trim()); //decimal add3 = String.IsNullOrEmpty(txtFinalAmt.Text) ? 0 : decimal.Parse(txtFinalAmt.Text.Trim()); //decimal sum = add3 + add1; text = value.ToString(); txtGrandTotal.Text = text.ToString(); } else { string var = y.ToString(); var = var.Replace("+", ""); txtRoundOff.Text = "- " + var; //decimal add1 = Convert.ToDecimal(var); ////decimal add2 = String.IsNullOrEmpty(txtGrandTotal.Text) ? 0 : decimal.Parse(txtGrandTotal.Text.Trim()); //decimal add3 = String.IsNullOrEmpty(txtFinalAmt.Text) ? 0 : decimal.Parse(txtFinalAmt.Text.Trim()); //decimal sum = add3 - add1; text = value.ToString(); txtGrandTotal.Text = text.ToString(); } //text = value.ToString(); } } private void txtTransport_TextChanged(object sender, EventArgs e) { //int a = Convert.ToInt32(txtTransport.Text); decimal a = String.IsNullOrEmpty(txtTransport.Text) ? 0 : decimal.Parse(txtTransport.Text.Trim()); decimal b = String.IsNullOrEmpty(txtOthers.Text) ? 0 : decimal.Parse(txtOthers.Text.Trim()); decimal c = String.IsNullOrEmpty(txtTotals.Text) ? 0 : decimal.Parse(txtTotals.Text.Trim()); // decimal d = String.IsNullOrEmpty(lblOldBal.Text) ? 0 : decimal.Parse(lblOldBal.Text.Trim()); txtFinalAmt.Text = (a + b + c).ToString(); //txtGrandTotal.Text = (a + b + c).ToString(); roundoff(); } private void txtOthers_TextChanged(object sender, EventArgs e) { decimal a = String.IsNullOrEmpty(txtTransport.Text) ? 0 : decimal.Parse(txtTransport.Text.Trim()); decimal b = String.IsNullOrEmpty(txtOthers.Text) ? 0 : decimal.Parse(txtOthers.Text.Trim()); decimal c = String.IsNullOrEmpty(txtTotals.Text) ? 0 : decimal.Parse(txtTotals.Text.Trim());
[no name]
И что именно, по-вашему, мы будем делать с этим массивным кодом?
https://www.codeproject.com/Questions/1175128/Invoice-no-should-starting-with-for-every-finacial
CHill60
Хорошо. Я удалил свое решение, так как теперь, отформатировав ваш дамп кода, я могу правильно прочитать вопрос.
Вы уже получаете максимальное число в столбце Id и добавляете 1 к id. Итак, получите максимальную дату в таблице и сравните ее с системной датой. Если системная дата попадает в следующий финансовый год, то сбросьте счетчик.
ZurdoDev
По-моему, это хорошее решение.
CHill60
Знаешь, ты прав. Я отправлю его.