Esempio n. 1
0
        public virtual CrystalDecisions.CrystalReports.Engine.ReportDocument CreateReport()
        {
            CrystalReport1 rpt = new CrystalReport1();

            rpt.Site = this.Site;
            return(rpt);
        }
Esempio n. 2
0
        private void btnSell_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvInvoice.Rows.Count > 0)
                {
                    if (newTot != 0.00M)
                    {
                        //COPY tbl_Bill_Items DATA TO tbl_InvoiceItems
                        SqlCommand cmd = new SqlCommand("INSERT INTO tbl_InvoiceItems SELECT * FROM tbl_Bill_Items", con);
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();

                        //NEW INVOICE
                        ObjInvoice.NewInvoce(
                            lblInvoiceNo.Text,
                            DateTime.Today,
                            lblSeller.Text,
                            totalPrice,
                            int.Parse(frmPay.discountVal),
                            decimal.Parse(frmPay.paymentVal),
                            balance,
                            totQty,
                            newTot
                            );

                        //NEW INVOICE TEMP
                        ObjInvoice.NewInvoceBill(
                            lblInvoiceNo.Text,
                            DateTime.Today,
                            lblSeller.Text,
                            totalPrice,
                            int.Parse(frmPay.discountVal),
                            decimal.Parse(frmPay.paymentVal),
                            balance,
                            totQty,
                            newTot
                            );

                        MessageBox.Show("Invoice Successful!", "SUCCESSFUL", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        //SELL ITEMS REMOVE IN THE STOCK
                        SqlDataAdapter iget = new SqlDataAdapter("SELECT * FROM tbl_Bill_Items", con);
                        con.Open();
                        DataTable idt = new DataTable();
                        iget.Fill(idt);
                        con.Close();
                        for (int i = 0; i < idt.Rows.Count; i++)
                        {
                            int nowAllQty = 0;

                            string item_no      = idt.Rows[i]["ItemNo"].ToString();
                            int    noOfQuantity = int.Parse(idt.Rows[i]["Qty"].ToString());
                            //con.Open();

                            string     csql = "SELECT * FROM tbl_Stock WHERE ItemNo='" + item_no + "'";
                            SqlCommand cmdi = new SqlCommand(csql, con);
                            con.Open();
                            SqlDataReader dr1 = cmdi.ExecuteReader();
                            if (dr1.Read() == true)
                            {
                                int stock_noOfQty = int.Parse(dr1["Qty"].ToString());
                                // decimal old_OneQtySellPrice = decimal.Parse(dr1[""].ToString());
                                con.Close();

                                //NOW STOCK ITEMS
                                nowAllQty = stock_noOfQty - noOfQuantity;

                                //STOCK UPDATE
                                ObjInvoice.update_Quntity(item_no, nowAllQty);
                            }
                            else
                            {
                                con.Close();
                            }
                        }//FOR LOOP END

                        //CrystalReportBill OBjcryBill = new CrystalReportBill();
                        //OBjcryBill.PrintToPrinter(1, false, 0, 0);
                        CrystalReport1 OBjcryBill1 = new CrystalReport1();
                        OBjcryBill1.SetDatabaseLogon("genesip", "genesip");//Fix databse logon fail error
                        OBjcryBill1.PrintToPrinter(1, false, 0, 0);

                        //OBjcryBill1.DataSourceConnections.Clear();
                        //OBjcryBill1.Refresh();

                        //CLEAR ALL BILL ITEMS
                        SqlCommand cmdBillItems = new SqlCommand("TRUNCATE TABLE " + "tbl_Bill_Items", con);
                        con.Open();
                        cmdBillItems.ExecuteNonQuery();
                        con.Close();

                        //CLEAR ALL BILL ITEMS
                        SqlCommand cmdBillInvo = new SqlCommand("TRUNCATE TABLE " + "tbl_Bill_Invoice", con);
                        con.Open();
                        cmdBillInvo.ExecuteNonQuery();
                        con.Close();

                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Please pay your bill!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Please add some items in the invoice!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
        }