コード例 #1
0
        public void ReprintSalesInvoice(int salesInvoiceNumber)
        {
            //get Finished Sales Inbvoice details if exist
            DataTable siFinishedDT = new DataTable();

            if (!proc.SalesInvoiceExist(salesInvoiceNumber, ref siFinishedDT))
            {
                MessageBox.Show("Unable to find provided Sales Invoice Number. (proc.SalesInvoiceExist)\r\n" + proc.errorMessage);
                return;
            }

            //Supply Global SalesInvoiceFinished Object variables based on fetched data
            foreach (DataRow row in siFinishedDT.Rows)
            {
                gSalesInvoiceFinished.ClientCode           = row.Field <string>("ClientCode");
                gSalesInvoiceFinished.SalesInvoiceNumber   = row.Field <double>("SalesInvoiceNumber");
                gSalesInvoiceFinished.SalesInvoiceDateTime = row.Field <DateTime>("SalesInvoiceDateTime");
                gSalesInvoiceFinished.GeneratedBy          = row.Field <string>("GeneratedBy");
                gSalesInvoiceFinished.CheckedBy            = row.Field <string>("CheckedBy");
                gSalesInvoiceFinished.ApprovedBy           = row.Field <string>("ApprovedBy");
                gSalesInvoiceFinished.TotalAmount          = row.Field <double>("TotalAmount");
                gSalesInvoiceFinished.VatAmount            = row.Field <double>("VatAmount");
                gSalesInvoiceFinished.NetOfVatAmount       = row.Field <double>("NetOfVatAmount");

                //PNB
                if (gClient.ShortName == "PNB")
                {
                }
            }

            //Get Sales Invoice List Details to be supplied to Global Report Datatable
            DataTable siListDT = new DataTable();

            if (!proc.GetOldSalesInvoiceList(salesInvoiceNumber, ref siListDT))
            {
                MessageBox.Show("Unable to connect to server. (proc.SalesInvoiceExist)\r\n" + proc.errorMessage);
                return;
            }


            //Create new instance of the document.
            ReportDocument crystalDocument = new ReportDocument();


            //Load path of the report
            if (!p.LoadReportPath("SalesInvoice", ref crystalDocument))
            {
                MessageBox.Show("SalesInvoice.rpt File not found");
                return;
            }

            //Supply report Data Source
            crystalDocument.SetDataSource(siListDT);

            //Supply values on report parameters.
            p.FillCRReportParameters("SalesInvoice", ref crystalDocument);

            //Tag newly created report to global Crystal Document
            gCrystalDocument = crystalDocument;

            //Load report Viewer
            frmReportViewer crForm = new frmReportViewer();

            crForm.Show();
        }
コード例 #2
0
        private void btnPrintSalesInvoice_Click(object sender, EventArgs e)
        {
            if (!p.ValidateInputFieldsSI(txtSalesInvoiceNumber.Text.ToString(), cbCheckedBy.Text.ToString(), cbApprovedBy.Text.ToString()))
            {
                MessageBox.Show("Please supply values in blank field(s)");
            }
            else if (dgvListToProcess.Rows.Count == 0)
            {
                MessageBox.Show("Please select record from Batch List.");
            }
            else
            {
                DialogResult result = MessageBox.Show("This will process Sales Invoice on selected DR's. \r\n Select 'YES' to proceed.", "Confirmation", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    ProcessServices_Nelson proc = new ProcessServices_Nelson();

                    if (!proc.UpdateTempTableSI(salesInvoiceList))
                    {
                        MessageBox.Show("Sales Invoice Temp Table Update Error (UpdateTempTable). \r\n" + proc.errorMessage);
                        return;
                    }

                    //Fill gSalesInvoiceFinished Model Class
                    //gSalesInvoiceList = salesInvoiceList;
                    gSalesInvoiceFinished.ClientCode           = gClient.ClientCode.ToString();
                    gSalesInvoiceFinished.SalesInvoiceDateTime = dtpInvoiceDate.Value;
                    gSalesInvoiceFinished.GeneratedBy          = gUser.UserName.ToString();
                    gSalesInvoiceFinished.CheckedBy            = cbCheckedBy.Text.ToString();
                    gSalesInvoiceFinished.ApprovedBy           = cbApprovedBy.Text.ToString();
                    gSalesInvoiceFinished.SalesInvoiceNumber   = double.Parse(txtSalesInvoiceNumber.Text.ToString());
                    gSalesInvoiceFinished.TotalAmount          = double.Parse(salesInvoiceList.Sum(x => x.lineTotalAmount).ToString());
                    gSalesInvoiceFinished.VatAmount            = p.GetVatAmount(gSalesInvoiceFinished.TotalAmount);
                    gSalesInvoiceFinished.NetOfVatAmount       = p.GetNetOfVatAmount(gSalesInvoiceFinished.TotalAmount);

                    ///Sort Sales Invoice By Batch before saving and Printing
                    var sortedList = salesInvoiceList.OrderBy(x => x.Batch).ToList();

                    ///Update Database
                    if (!proc.UpdateSalesInvoiceHistory(sortedList))
                    {
                        MessageBox.Show("Error updating sales invoice record to server. (proc.UpdateSalesInvoiceHistory) \r\n" + proc.errorMessage);
                        return;
                    }

                    //Update Quantity On hand for PNB
                    if (gClient.ShortName == "PNB")
                    {
                        foreach (var item in sortedList)
                        {
                            if (!proc.UpdateItemQuantityOnhand(item.Quantity, item.checkName, item.PurchaseOrderNumber))
                            {
                                MessageBox.Show("Error on (Procedure ChequeQuantityIsSufficient) \r\n \r\n" + proc.errorMessage);
                                return;
                            }
                        }
                    }

                    //Create new instance of the document/ Prepare report using Crystal Reports
                    ReportDocument crystalDocument = new ReportDocument();

                    //Check RPT File
                    if (!p.LoadReportPath("SalesInvoice", ref crystalDocument))
                    {
                        MessageBox.Show("SalesInvoice.rpt File not found");
                        return;
                    }

                    //Supply Data source to document
                    crystalDocument.SetDataSource(sortedList);

                    //Install Fastmember from nuGet for Fast (List to Datatable) Conversion
                    //DataTable dt = new DataTable();
                    //using (var reader = ObjectReader.Create(sortedList))
                    //{
                    //    dt.Load(reader);
                    //}
                    /////Supply datatable from the list converted
                    //gReportDT = dt;


                    //Supply details on report parameters
                    p.FillCRReportParameters("SalesInvoice", ref crystalDocument);


                    //Supply these details into Global ReportDocument to be able for the report viewer to initialize the rerport
                    gCrystalDocument = crystalDocument;

                    frmReportViewer crForm = new frmReportViewer();
                    crForm.Show();
                    RefreshView();
                }
            }
        }