public int UpdateInvoice() { DateTime InvoiceDate = DateTime.Now; DateTime?OrderDate = null; DateTime?DCNoDate = null; int intInvoiceID = 0; int intInvoiceNo = 0; bool blnEditFlag = false; try { InvoicerDataSetTableAdapters.InvoiceTableAdapter objInvoice = new InvoicerDataSetTableAdapters.InvoiceTableAdapter(); intInvoiceID = this.txtDiscount.Text != "" ? Convert.ToInt32(this.txtInvoiceID.Text) : 0; DataTable dtInvoice = objInvoice.GetDataByID(intInvoiceID); if (dtInvoice.Rows.Count > 0) { blnEditFlag = true; } intInvoiceNo = Convert.ToInt32(this.txtInvoiceNo.Text); int intClientID = Convert.ToInt32(cmbClient.SelectedValue); //Convert.ToInt32(txtClientID.Text); if (this.dtInvoiceDate.Text != "") { dtInvoiceDate.CustomFormat = "MM/dd/yyyy"; InvoiceDate = Convert.ToDateTime(dtInvoiceDate.Text); dtInvoiceDate.CustomFormat = "dd/MM/yyyy"; } else { dtInvoiceDate.Invalidate(false); } if (this.dtRefDate.Text != "") { dtRefDate.CustomFormat = "MM/dd/yyyy"; OrderDate = Convert.ToDateTime(dtRefDate.Text); dtRefDate.CustomFormat = "dd/MM/yyyy"; } if (this.dtDCDate.Text != "") { dtDCDate.CustomFormat = "MM/dd/yyyy"; DCNoDate = Convert.ToDateTime(dtDCDate.Text); dtDCDate.CustomFormat = "dd/MM/yyyy"; } double? Discount = this.txtDiscount.Text != "" ? Convert.ToDouble(txtDiscount.Text) : 0; double? CGST = this.txtCGST.Text != "" ? Convert.ToDouble(txtCGST.Text) : 0; double? SGST = this.txtSGST.Text != "" ? Convert.ToDouble(txtSGST.Text) : 0; double? IGST = this.txtIGST.Text != "" ? Convert.ToDouble(txtIGST.Text) : 0; decimal?LineAmount = this.txtLineAmount.Text != "" ? Convert.ToDecimal(txtLineAmount.Text) : 0; decimal?SubTotal = this.txtTotalDiscount.Text != "" ? Convert.ToDecimal(txtTotalDiscount.Text) : 0; decimal?TaxAmount = this.txtTaxAmount.Text != "" ? Convert.ToDecimal(txtTaxAmount.Text) : 0; decimal?TotalAmount = this.txtTotalAmount.Text != "" ? Convert.ToDecimal(txtTotalAmount.Text) : 0; string OrderNo = this.txtRefNo.Text != "" ? txtRefNo.Text : null; bool AddressFlag = this.radNewAddr.Checked ? true : false; string HSNCode = this.txtHSNCode.Text != "" ? this.txtHSNCode.Text : null; string GSTIN = this.txtGSTIN.Text != "" ? this.txtGSTIN.Text : null; string StateCode = this.txtStateCode.Text != "" ? this.txtStateCode.Text : null; string DCNo = this.txtDCNo.Text != "" ? this.txtDCNo.Text : null; InvoicerDataSetTableAdapters.LineItemTableAdapter objData = new InvoicerDataSetTableAdapters.LineItemTableAdapter(); DataTable dtLineItem = null; if (blnEditFlag) { objData.DeleteLineItem(intInvoiceID); } dtLineItem = (DataTable)((DataView)lineItemBindingSource.List).Table; if (!(dtLineItem.HasErrors)) { if (dtLineItem.Rows.Count > 0) { foreach (DataRow item in dtLineItem.Rows) { objData.Insert(intInvoiceID, Convert.ToInt32(item["SNo"]), item["Product"].ToString(), item["HSNCode"].ToString(), Convert.ToDecimal(item["UnitPrice"].ToString()), Convert.ToInt16(item["Quantity"].ToString())); } } else { MessageBox.Show("Please enter Invoice Item."); return(0); } } if (blnEditFlag) { objInvoice.UpdateInvoice(intInvoiceNo, intClientID, InvoiceDate, Decimal.Parse(Discount.ToString()), Decimal.Parse(CGST.ToString()), Decimal.Parse(SGST.ToString()), Decimal.Parse(IGST.ToString()), 0, LineAmount, SubTotal, TotalAmount, TaxAmount, AddressFlag, null, OrderNo, DCNoDate, OrderDate, GSTIN, StateCode, DCNo, intInvoiceID); return(intInvoiceID); } else { return(objInvoice.Insert(intInvoiceNo, intClientID, InvoiceDate, Discount, CGST, SGST, IGST, 0, LineAmount, SubTotal, TotalAmount, TaxAmount, AddressFlag, null, OrderNo, DCNoDate, OrderDate, GSTIN, StateCode, DCNo)); } } catch (Exception excLocal) { MessageBox.Show(excLocal.Message); return(0); } }
public void DisplayData(int intInvoiceID) { DataSet dsInvoicer = null; try { //InvoicerDataSetTableAdapters.ClientTableAdapter objClient = new InvoicerDataSetTableAdapters.ClientTableAdapter(); InvoicerDataSetTableAdapters.InvoiceTableAdapter objInvoice = new InvoicerDataSetTableAdapters.InvoiceTableAdapter(); InvoicerDataSetTableAdapters.LineItemTableAdapter objLineItem = new InvoicerDataSetTableAdapters.LineItemTableAdapter(); dsInvoicer = new DataSet(); DataTable dtInvoice = objInvoice.GetDataByID(intInvoiceID); if (dtInvoice.Rows.Count > 0) { foreach (DataRow drInvoice in dtInvoice.Rows) { //SELECT AddressFlag, CGST, ClientID, DCNoDate, Discount, Freight, GSTIN, IGST, InvoiceDate, //InvoiceID, InvoicePath, LineAmount, OrderDate, OrderNo, SGST, StateCode, //SubTotal, TaxAmount, TotalAmount FROM Invoice WHERE (InvoiceID = ?) cmbClient.SelectedValue = drInvoice["ClientID"].ToString(); txtInvoiceID.Text = drInvoice["InvoiceID"].ToString(); txtInvoiceNo.Text = drInvoice["InvoiceNo"].ToString().PadLeft(3, '0'); dtInvoiceDate.Text = drInvoice["InvoiceDate"].ToString(); dtDCDate.Text = drInvoice["DCNoDate"].ToString(); dtRefDate.Text = drInvoice["OrderDate"].ToString(); txtRefNo.Text = drInvoice["OrderNo"].ToString(); txtCGST.Text = drInvoice["CGST"].ToString(); txtSGST.Text = drInvoice["SGST"].ToString(); txtIGST.Text = drInvoice["IGST"].ToString(); txtDiscount.Text = drInvoice["Discount"].ToString(); txtGSTIN.Text = drInvoice["GSTIN"].ToString(); txtStateCode.Text = drInvoice["StateCode"].ToString(); radOldAddr.Checked = drInvoice["AddressFlag"].ToString() == "True" ? false : true; txtTaxAmount.Text = drInvoice["TaxAmount"].ToString(); txtLineAmount.Text = drInvoice["LineAmount"].ToString(); txtTotalDiscount.Text = drInvoice["SubTotal"].ToString(); txtTotalAmount.Text = drInvoice["TotalAmount"].ToString(); DataTable dtLineItem = objLineItem.GetDataByID(intInvoiceID); lineItemBindingSource.DataSource = dtLineItem.AsDataView(); if (dtLineItem.Rows.Count > 0) { txtHSNCode.Text = dtLineItem.Rows[0]["HSNCode"].ToString(); } else { txtHSNCode.Text = ConfigurationManager.AppSettings["HSNCODE"].ToString(); } dgInvoicer.DataSource = lineItemBindingSource; dgInvoicer.Refresh(); } } else { cmbClient.SelectedValue = 0; //txtInvoiceNo.Text = drInvoice["InvoiceID"].ToString().PadLeft(3, '0'); dtInvoiceDate.Text = DateTime.Now.ToShortDateString(); dtDCDate.Text = DateTime.Now.ToShortDateString(); dtRefDate.Text = DateTime.Now.ToShortDateString(); txtRefNo.Text = ""; txtCGST.Text = "0"; txtSGST.Text = "0"; txtIGST.Text = "0"; txtDiscount.Text = "0"; txtGSTIN.Text = ConfigurationManager.AppSettings["GSTIN"].ToString(); txtStateCode.Text = ConfigurationManager.AppSettings["STATECODE"].ToString(); txtHSNCode.Text = ConfigurationManager.AppSettings["HSNCODE"].ToString(); radOldAddr.Checked = false; txtTaxAmount.Text = "0"; txtLineAmount.Text = "0"; txtTotalDiscount.Text = "0"; txtTotalAmount.Text = "0"; //DataTable dtLineItem = objLineItem.GetDataByID(0); lineItemBindingSource.DataSource = objLineItem.GetDataByID(0).AsDataView(); dgInvoicer.DataSource = lineItemBindingSource; dgInvoicer.Refresh(); //this.invoicerDataSetBindingSource = objLineItem.GetDataByID(0); //BindingSource DT = (BindingSource)lineItemBindingSource.DataSource; //if (DT != null) // ((DataView)DT.List).Clear(); //this.lineItemBindingSource = this.invoicerDataSetBindingSource; //this.lineItemBindingSource.DataMember = "LineItem"; //dgInvoicer.Update(); } } catch (Exception excLocal) { throw excLocal; } }
public static bool GeneratePDFReport(int intInvoiceid, string strClientName) { string strSourceRptPath; string strReportOutputPath; string strFileName = String.Empty; DataSet dsInvoicer = null; ReportDocument rptDoc = null; try { InvoicerDataSetTableAdapters.ClientTableAdapter objClient = new InvoicerDataSetTableAdapters.ClientTableAdapter(); InvoicerDataSetTableAdapters.InvoiceTableAdapter objInvoice = new InvoicerDataSetTableAdapters.InvoiceTableAdapter(); InvoicerDataSetTableAdapters.LineItemTableAdapter objLineItem = new InvoicerDataSetTableAdapters.LineItemTableAdapter(); dsInvoicer = new DataSet(); DataTable dtInvoice = objInvoice.GetDataByID(intInvoiceid); if (dtInvoice.Rows.Count > 0) { strSourceRptPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.ToString()).ToString() + @"\"; strSourceRptPath = strSourceRptPath.Replace(@"file:\", ""); //Create a new Report Document object rptDoc = new ReportDocument(); rptDoc.Load(strSourceRptPath + "rptInvoiceDetails.rpt"); //DbConnectionStringBuilder builder = new DbConnectionStringBuilder(); //Invoicer.Properties.Settings objsettings = new Properties.Settings(); ////builder.ConnectionString = ConfigurationManager.ConnectionStrings["Invoicer.Properties.Settings.InvoicerConnectionString"].ConnectionString; //builder.ConnectionString = objsettings.InvoicerConnectionString.ToString(); //string databasepath = builder["Data Source"] as string; string databasepath = ConfigurationManager.AppSettings["InvoiceDBPath"].ToString(); ////change path of the database rptDoc.DataSourceConnections[0].SetConnection("", databasepath, false); ////'' if password is given then give the password ////'' if not give it will ask at runtime rptDoc.DataSourceConnections[0].SetLogon("admin", ""); //SetReportLogon(rptDoc, "RXP", null); rptDoc.SetParameterValue("InvoiceID", intInvoiceid); //rptDoc.SetParameterValue("ADDRESS", ConfigurationManager.AppSettings["ADDRESS"].ToString()); // Stream objstream = rptDoc.ExportToStream(ExportFormatType.PortableDocFormat); dsInvoicer.Tables.Add(objClient.GetDataByID(Convert.ToInt32(dtInvoice.Rows[0]["ClientID"].ToString()))); dsInvoicer.Tables.Add(dtInvoice); dsInvoicer.Tables.Add(objLineItem.GetDataByID(intInvoiceid)); rptDoc.SetDataSource(dsInvoicer); //strReportOutputPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.ToString()).ToString() + @"\PDFReports\";//ConfigurationManager.AppSettings["ExportPDFPath"].ToString(); strClientName = dsInvoicer.Tables["Client"].Rows[0]["ClientName"].ToString(); strReportOutputPath = System.IO.Path.GetDirectoryName(ConfigurationManager.AppSettings["InvoicePDFPath"].ToString()) + @"\" + strClientName + @"\"; strReportOutputPath = strReportOutputPath.Replace(@"file:\", ""); //strReportOutputPath = strReportOutputPath + @"\"; if (!Directory.Exists(strReportOutputPath)) { Directory.CreateDirectory(strReportOutputPath); } string strInvNo = dtInvoice.Rows[0]["InvoiceNo"].ToString().PadLeft(3, '0'); strFileName = "Invoice_" + strInvNo + "_" + DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss") + ".pdf"; if (UpdatePDFFiles(strReportOutputPath + strFileName, intInvoiceid)) { FileInfo fileInfo = new FileInfo(strReportOutputPath + strFileName); if (fileInfo.Exists) { File.Delete(strReportOutputPath + strFileName); } } //rptDoc.PrintOptions.PaperOrientation = PaperOrientation.Portrait; //rptDoc.PrintOptions.PaperSize = PaperSize.PaperA4; //int intcount = rptDoc.Database.Tables.Count; rptDoc.ExportToDisk(ExportFormatType.PortableDocFormat, strReportOutputPath + strFileName); //rptDoc.PrintToPrinter(1, false, 0, 0); } return(true); } catch (Exception excLocal) { throw excLocal; } finally { dsInvoicer.Dispose(); //Clear Report Document object rptDoc.Close(); //rptDoc.Dispose(); rptDoc = null; } }