Пример #1
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            try
            {
                con = new OleDbConnection(lblpath.Text);
                con.Open();
                string cb = "insert into PlotSell(CUSTOMERID,CUSTOMERNAME,PLOTNO,SURVEYNO,PLOTSIZE,RATE,TOTALAMOUNT,BOOKINGAMOUNT,AGREEMENTAMOUNT,TOTALPAIDAMOUNT,BALANCEAMOUNT,EXTRADETAIL,PLOTSELLDATE) VALUES (" + lblcustid.Text + ",'" + cmbCustomer.Text + "','" + txtplotno.Text + "','" + txtsurveyno.Text + "'," + txtplotsize.Text + "," + txtrate.Text + "," + txttotalamount.Text + "," + txtbookingamout.Text + "," + txtagreementamount.Text + "," + txttotalpaidamount.Text + "," + txtbalanceamount.Text + ",'" + txtextradetail.Text + "','" + dtpDate.Text + "')";
                cmd            = new OleDbCommand(cb);
                cmd.Connection = con;
                cmd.ExecuteReader();
                con.Close();
                MessageBox.Show("Successfully saved", "PLOT SELL DETAIL", MessageBoxButtons.OK, MessageBoxIcon.Information);

                con = new OleDbConnection(lblpath.Text);
                con.Open();
                string cb1 = "insert into Ledger(PLOTSELLID,VOUCHERDATE,VOUCHERTYPE,VOUCHERNO,DEBIT,BAL) VALUES (" + lblplotsell.Text + ",'" + dtpDate.Text + "','" + "TOTAL PLOT SELL AMOUNT" + "'," + lblplotsell.Text + "," + txttotalamount.Text + "," + txttotalamount.Text + ")";

                cmd            = new OleDbCommand(cb1);
                cmd.Connection = con;
                cmd.ExecuteReader();
                con.Close();

                string a = Convert.ToString(Convert.ToInt64(txttotalamount.Text) - Convert.ToInt64(txtbookingamout.Text));
                con = new OleDbConnection(lblpath.Text);
                con.Open();
                string cb2 = "insert into Ledger(PLOTSELLID,VOUCHERDATE,VOUCHERTYPE,VOUCHERNO,CREDIT,BAL) VALUES (" + lblplotsell.Text + ",'" + dtpDate.Text + "','" + "Booking AMOUNT" + "'," + lblplotsell.Text + "," + txtbookingamout.Text + "," + a.ToString() + ")";

                cmd            = new OleDbCommand(cb2);
                cmd.Connection = con;
                cmd.ExecuteReader();
                con.Close();

                a   = Convert.ToString(Convert.ToInt64(a) - Convert.ToInt64(txtagreementamount.Text));
                con = new OleDbConnection(lblpath.Text);
                con.Open();
                string cb3 = "insert into Ledger(PLOTSELLID,VOUCHERDATE,VOUCHERTYPE,VOUCHERNO,CREDIT,BAL) VALUES (" + lblplotsell.Text + ",'" + dtpDate.Text + "','" + "AGREEMENT AMOUNT" + "'," + lblplotsell.Text + "," + txtagreementamount.Text + "," + a.ToString() + ")";

                cmd            = new OleDbCommand(cb3);
                cmd.Connection = con;
                cmd.ExecuteReader();
                con.Close();

                DialogResult result1 = MessageBox.Show("Do you want to print this plot sell detail?", "Account Management",
                                                       MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result1 == DialogResult.Yes)
                {
                    try
                    {
                        rptInvoice rpt = new rptInvoice();
                        //The report you created.
                        cmd = new OleDbCommand();
                        OleDbDataAdapter myDA = new OleDbDataAdapter();
                        DataSet          myDS = new DataSet();
                        //The DataSet you created.
                        con            = new OleDbConnection(lblpath.Text);
                        cmd.Connection = con;
                        //   cmd.CommandText = "SELECT PlotSell.CUSTOMERID,PlotSell.CUSTOMERNAME,PlotSell.PLOTNO,PlotSell.SURVEYNO,PlotSell.PLOTSIZE,PlotSell.RATE,PlotSell.TOTALAMOUNT,PlotSell.BOOKINGAMOUNT,PlotSell.AGREEMENTAMOUNT,PlotSell.TOTALPAIDAMOUNT,PlotSell.BALANCEAMOUNT,PlotSell.EXTRADETAIL,PlotSell.PLOTSELLDATE,PlotSell.PLOTSELLID,Installment.INSTALLMENTNO,Installment.INSTALLMENTDATE,Installment.INSTALLMENT FROM  PlotSell INNER JOIN  Installment ON  PlotSell.PLOTSELLID = Installment.PLOTSELLID  WHERE  PlotSell.PLOTSELLID =" + lblplotsell.Text + "";

                        cmd.CommandText    = "SELECT PlotSell.CUSTOMERID,PlotSell.CUSTOMERNAME,PlotSell.PLOTNO,PlotSell.SURVEYNO,PlotSell.PLOTSIZE,PlotSell.RATE,PlotSell.TOTALAMOUNT,PlotSell.BOOKINGAMOUNT,PlotSell.AGREEMENTAMOUNT,PlotSell.TOTALPAIDAMOUNT,PlotSell.BALANCEAMOUNT,PlotSell.EXTRADETAIL,PlotSell.PLOTSELLDATE,PlotSell.PLOTSELLID FROM  PlotSell   WHERE  PlotSell.PLOTSELLID =" + lblplotsell.Text + "";
                        cmd.CommandType    = CommandType.Text;
                        myDA.SelectCommand = cmd;
                        myDA.Fill(myDS, "PlotSell");


                        cmd.CommandText    = "SELECT Company.COMPANYNAME,Company.ADDRESS,Company.PHONENO,Company.EMAIL,Company.WEB,Company.TINNO,Company.CSTNO,Company.EXTRA1,Company.EXTRA2 FROM Company ";
                        cmd.CommandType    = CommandType.Text;
                        myDA.SelectCommand = cmd;
                        myDA.Fill(myDS, "Company");

                        cmd.CommandText    = "SELECT Installment.INSTALLMENTNO,Installment.INSTALLMENTDATE,Installment.INSTALLMENT FROM Installment WHERE  Installment.PLOTSELLID =" + lblplotsell.Text + " ";
                        cmd.CommandType    = CommandType.Text;
                        myDA.SelectCommand = cmd;
                        myDA.Fill(myDS, "Installment");
                        con.Close();
                        rpt.SetDataSource(myDS);
                        frmReport frm = new frmReport();
                        frm.crystalReportViewer1.ReportSource = rpt;
                        frm.Visible = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                btn_save.Enabled = false;
                Reset();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }