protected void Successbtnadd_Click(object sender, EventArgs e) { Labelstatus.Text = ""; if (DropDownListcontac.SelectedValue != "0") { Invoice object1 = new Invoice(); object1.Invoice_AfterDiscountprice = 0; object1.Invoice_AfterDiscountprice_ATax = 0; object1.Invoice_Date = Convert.ToDateTime(datepicker.Text); //object1.Invoice_IsDone = Convert.ToByte(CheckBoxDone.Checked); object1.Invoice_No = Convert.ToInt32(Convert.ToString(Convert.ToInt32(DB.Invoice_Serial_Collects.Where(a => a.Invoice_Serial_Collect_Collecting.Equals(DropDownListinvoicetype.SelectedValue)).SingleOrDefault().Invoice) + 1)); object1.Invoice_Price = Convert.ToDouble(0); object1.Invoice_Rectime = DateTime.Now; object1.Invoice_TotalCost = Convert.ToDouble(0); object1.Invoice_Type_Id = Convert.ToInt32(DropDownListinvoicetype.SelectedValue); object1.Contact_Id = Convert.ToInt32(DropDownListcontac.SelectedValue); object1.IsDisable = false; DB.Invoices.InsertOnSubmit(object1); DB.SubmitChanges(); bsclass bs = new bsclass(); //if (object1.Invoice_Type_Id == 1) // bs.Addtransaction(2, "Invoice+", object1.Invoice_Id, object1.Invoice_Date, object1.Invoice_TotalCost, object1.Invoice_Price, object1.Invoice_Price - object1.Invoice_TotalCost, ""); //else if (object1.Invoice_Type_Id == 2) // bs.Addtransaction(4, "Invoice-", object1.Invoice_Id, object1.Invoice_Date, object1.Invoice_TotalCost, object1.Invoice_Price, object1.Invoice_Price - object1.Invoice_TotalCost, ""); bs.invoicetransaction(Convert.ToString(object1.Invoice_Id)); var serical = DB.Invoice_Serial_Collects.Where(a => a.Invoice_Serial_Collect_Collecting.Equals(DropDownListinvoicetype.SelectedValue)).SingleOrDefault(); serical.Invoice++; DB.Invoice_Serial_Collects.DefaultIfEmpty(serical); DB.SubmitChanges(); Response.Redirect("AddInvoice.aspx?ID=" + object1.Invoice_Id); } else { Labelstatus.Text = "Please Choose A Contact "; } }
private void editinvoicemoney(string id) { decimal amount = 0; decimal percentage = 0; decimal taxamount = 0; decimal taxpercentage = 0; var invoice = DB.Invoices.Where(a => a.Invoice_Id.Equals(Labelid.Text)).SingleOrDefault(); var discount = DB.DiscountInvoice2s.Where(a => a.Invoice_Id.Equals(invoice.Invoice_Id) && a.IsDisable.Equals(false)); foreach (var item in discount) { amount = amount + Convert.ToDecimal(item.DiscountInvoice_Amount); percentage = percentage + (Convert.ToDecimal(item.DiscountInvoice_Percentage) * Convert.ToDecimal(invoice.Invoice_Price)) / 100; } invoice.Invoice_AfterDiscountprice = Convert.ToDouble(Convert.ToDecimal(invoice.Invoice_Price) - Convert.ToDecimal(amount + percentage)); var taxvalue = DB.InvoiceTaxes.Where(a => a.Invoice_ID.Equals(invoice.Invoice_Id) && a.IsDisable.Equals(false)); foreach (var item in taxvalue) { taxamount = taxamount + Convert.ToDecimal(item.InvoiceTax_Amount); taxpercentage = taxpercentage + (Convert.ToDecimal(item.InvoiceTax_Percentage) * Convert.ToDecimal(invoice.Invoice_AfterDiscountprice)) / 100; } invoice.Invoice_AfterDiscountprice_ATax = Convert.ToDouble(Convert.ToDecimal(invoice.Invoice_AfterDiscountprice) + Convert.ToDecimal(taxamount + taxpercentage)); DB.Invoices.DefaultIfEmpty(invoice); DB.SubmitChanges(); bsclass bs = new bsclass(); bs.invoicetransaction(Labelid.Text); }