Beispiel #1
0
        public void btnsave_Click(object sender, EventArgs e)
        {
            try
            {
                int ricept;
                int Payment;
                ricept  = Convert.ToInt32(txtReciept.Text);
                Payment = Convert.ToInt32(txtPayment.Text);
                if (ricept != Payment)
                {
                    MessageBox.Show("Payment Amount and Reciept Amount Does not Match...Entry Cannot Saved..");
                }
                else
                {
                    c.getconnstr();
                    c.returnconn(c.myconn);
                    txtvchtype.Text = "JV";
                    if (add_edit == true)
                    {
                        SqlConnection con   = c.myconn;
                        DateTime      dt    = dtp.Value;
                        Int32         VchNo = c.getvchno(txtvchtype.Text, ref dt, con);
                        vouchNo           = c.getvouchernumber(txtvchtype.Text, ref dt, con); //txtvchtype.Text +  dtp.Value.Date.ToString("ddMMyyyy") + VchNo;
                        txtvoucherno.Text = vouchNo;
                        SqlTransaction trn;
                        trn = c.myconn.BeginTransaction();
                        try
                        {
                            string mysql;
                            mysql = "insert into tbl_Voucher(yearno,VchNo,VouchNo,VchType,VchDate,Remark,status)values('" + school.CurrentSessionCode + "','" + VchNo + "','" + vouchNo + "','" + txtvchtype.Text + "','" + dtp.Value.Date + "','" + txtRemark.Text + "','AE')";
                            c.connectsql(mysql, c.myconn, trn);
                            for (int i = 0; i < dataGridView1.Rows.Count; i++)
                            {
                                decimal pay = Convert.ToInt32(dataGridView1.Rows[i].Cells["Payment"].Value);
                                decimal rec = Convert.ToInt32(dataGridView1.Rows[i].Cells["Reciept"].Value);
                                if (pay == 0)
                                {
                                    mysql = "insert into tbl_VoucherDetail (yearno,vchno,VouchNo,VchType,AccCode,VchDate,Amount) values ('" + school.CurrentSessionCode + "','" + VchNo + "','" + vouchNo + "','" + txtvchtype.Text + "','" + dataGridView1.Rows[i].Cells["ACCOUNT"].Value.ToString() + "','" + dtp.Value.Date + "','" + rec + "')";
                                }
                                else
                                {
                                    mysql = "insert into tbl_VoucherDetail (yearno,vchno,VouchNo,VchType,AccCode,VchDate,Amount) values ('" + school.CurrentSessionCode + "','" + VchNo + "','" + vouchNo + "','" + txtvchtype.Text + "','" + dataGridView1.Rows[i].Cells["ACCOUNT"].Value.ToString() + "','" + dtp.Value.Date + "','" + -1 * pay + "')";
                                }
                                c.connectsql(mysql, c.myconn, trn);
                            }
                            trn.Commit();
                            MessageBox.Show("Record Saved...");
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                            trn.Rollback();
                        }
                    }
                    if (add_edit == false)
                    {
                        c.getconnstr();
                        c.returnconn(c.myconn);
                        SqlDataReader dr = null;
                        con = c.myconn;
                        dr  = c.fillreader(ref dr, "select VchNo from tbl_Voucher where vchtype='JV'  and VouchNo='" + txtvoucherno.Text + "'", con);
                        if (dr.HasRows == true)
                        {
                            dr.Read();
                            VchNo = Convert.ToInt16(dr[0]);
                            if (dr[1] == "AE")
                            {
                                MessageBox.Show("Voucher Not Made from Account Entry...");
                                dr.Close();
                                goto mline;
                            }
                        }
                        dr.Close();
                        SqlTransaction trn;
                        trn = c.myconn.BeginTransaction();
                        try
                        {
                            string mysql;
                            mysql = "delete from tbl_Voucher where vchtype='JV'  and VouchNo='" + txtvoucherno.Text + "'";
                            c.connectsql(mysql, c.myconn, trn);
                            mysql = "delete from tbl_VoucherDetail where  vchtype='JV' and VouchNo='" + txtvoucherno.Text + "'";
                            c.connectsql(mysql, c.myconn, trn);
                            for (int i = 0; i < dataGridView1.Rows.Count; i++)
                            {
                                decimal pay = Convert.ToInt32(dataGridView1.Rows[i].Cells["Payment"].Value);
                                decimal rec = Convert.ToInt32(dataGridView1.Rows[i].Cells["Reciept"].Value);
                                if (pay == 0)
                                {
                                    mysql = "insert into tbl_VoucherDetail (yearno,vchno,VouchNo,VchType,AccCode,VchDate,Amount) values ('" + school.CurrentSessionCode + "','" + VchNo + "','" + vouchNo + "','" + txtvchtype.Text + "','" + dataGridView1.Rows[i].Cells["ACCOUNT"].Value.ToString() + "','" + dtp.Value.Date + "'," + rec + "')";
                                }
                                else
                                {
                                    mysql = "insert into tbl_VoucherDetail (yearno,vchno,VouchNo,VchType,AccCode,VchDate,Amount) values ('" + school.CurrentSessionCode + "','" + VchNo + "','" + vouchNo + "','" + txtvchtype.Text + "','" + dataGridView1.Rows[i].Cells["ACCOUNT"].Value.ToString() + "','" + dtp.Value.Date + "'," + -1 * pay + "')";
                                }
                                c.connectsql(mysql, c.myconn, trn);
                            }
                            trn.Commit();
                            MessageBox.Show("Record Update...");
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                            trn.Rollback();
                        }
                        trn.Dispose();
                    }
mline:
                    c.GetMdiParent(this).EnableAllEditMenuButtons();

                    DesignForm.fromDesign1(this);
                }
            }

            catch { }
        }
Beispiel #2
0
        public void btnsave_Click(object sender, EventArgs e)
        {
            if (valcmbbank.Text == "" && valcmbaccountgroup.Text == "" && txtPaidAmt.Text == "" && txtNarration.Text == "")
            {
                MessageBox.Show("Null Value Not Allowed ");
            }
            else
            {
                int Bank1;
                int Bank2;
                Bank1 = Convert.ToInt32(valcmbaccountgroup.SelectedValue);
                Bank2 = Convert.ToInt32(valcmbbank.SelectedValue);
                if (Bank1 == Bank2)
                {
                    MessageBox.Show("Both Accounts are same....");
                    goto mline;
                }
                c.returnconn(c.myconn);
                txtvchtype.Text = "BP";
                if (add_edit == true)
                {
                    SqlConnection con   = c.myconn;
                    DateTime      dt    = dtp.Value;
                    Int32         VchNo = c.getvchno(txtvchtype.Text, ref dt, con);
                    vouchNo           = c.getvouchernumber(txtvchtype.Text, ref dt, con); //txtvchtype.Text +  dtp.Value.Date.ToString("ddMMyyyy") + VchNo;
                    txtvoucherno.Text = vouchNo;
                    SqlTransaction trn;
                    trn = c.myconn.BeginTransaction();
                    try
                    {
                        string mysql;
                        mysql = "insert into tbl_Voucher(YearNo,VchNo,VouchNo,VchType,VchDate,Remark,Status)values('" + school.CurrentSessionCode + "','" + VchNo + "','" + vouchNo + "','" + txtvchtype.Text + "','" + dtp.Value.Date + "','" + txtNarration.Text + "','AE')";
                        c.connectsql(mysql, c.myconn, trn);
                        mysql = "insert into tbl_VoucherDetail (YearNo,vchno,VouchNo,VchType,AccCode,VchDate,Amount,CashBankNo,ChequeNo,ChequeDate) values ('" + school.CurrentSessionCode + "','" + VchNo + "','" + vouchNo + "','" + txtvchtype.Text + "','" + valcmbbank.SelectedValue + "','" + dtp.Value.Date + "'," + -1 * Convert.ToDecimal(txtPaidAmt.Text) + ",0,'" + txtChkNo.Text + "','" + txtChkDate.Value + "')";
                        c.connectsql(mysql, c.myconn, trn);
                        mysql = "insert into tbl_VoucherDetail (YearNo,vchno,VouchNo,VchType,AccCode,VchDate,Amount,CashBankNo,ChequeNo,ChequeDate) values ('" + school.CurrentSessionCode + "','" + VchNo + "','" + vouchNo + "','" + txtvchtype.Text + "','" + valcmbaccountgroup.SelectedValue + "','" + dtp.Value.Date + "','" + txtPaidAmt.Text + "','" + valcmbbank.SelectedValue + "','" + txtChkNo.Text + "','" + txtChkDate.Value + "')";
                        c.connectsql(mysql, c.myconn, trn);
                        trn.Commit();
                        MessageBox.Show("Record Saved...");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        trn.Rollback();
                    }
                    trn.Dispose();
                }
                if (add_edit == false)
                {
                    c.getconnstr();
                    c.returnconn(c.myconn);
                    SqlDataReader dr = null;
                    con = c.myconn;
                    dr  = c.fillreader(ref dr, "select VchNo,Status from tbl_Voucher where vchtype='BP'  and VouchNo='" + txtvoucherno.Text + "'", con);
                    if (dr.HasRows == true)
                    {
                        dr.Read();
                        VchNo = Convert.ToInt16(dr[0]);
                        if (dr[1] == "AE")
                        {
                            MessageBox.Show("Voucher Not Made from Account Entry...");
                            dr.Close();
                            goto mline;
                        }
                    }
                    dr.Close();
                    c.returnconn(c.myconn);
                    SqlTransaction trn;
                    trn = c.myconn.BeginTransaction();
                    try
                    {
                        string mysql;
                        mysql = "delete from tbl_Voucher where vchtype='BP'  and VouchNo='" + txtvoucherno.Text + "'";
                        c.connectsql(mysql, c.myconn, trn);
                        mysql = "delete from tbl_VoucherDetail where  vchtype='BP' and VouchNo='" + txtvoucherno.Text + "'";
                        c.connectsql(mysql, c.myconn, trn);
                        mysql = "insert into tbl_Voucher(YearNo,VchNo,VouchNo,VchType,VchDate,Remark,Status)values('" + school.CurrentSessionCode + "','" + VchNo + "','" + txtvoucherno.Text + "','" + txtvchtype.Text + "','" + dtp.Value.Date + "','" + txtNarration.Text + "','AE')";
                        c.connectsql(mysql, c.myconn, trn);
                        mysql = "insert into tbl_VoucherDetail (YearNo,vchno,VouchNo,VchType,AccCode,VchDate,Amount,CashBankNo,ChequeNo,ChequeDate) values ('" + school.CurrentSessionCode + "','" + VchNo + "','" + vouchNo + "','" + txtvchtype.Text + "','" + valcmbbank.SelectedValue + "','" + dtp.Value.Date + "'," + -1 * Convert.ToDecimal(txtPaidAmt.Text) + ",0,'" + txtChkNo.Text + "','" + txtChkDate.Value + "')";
                        c.connectsql(mysql, c.myconn, trn);
                        mysql = "insert into tbl_VoucherDetail (YearNo,vchno,VouchNo,VchType,AccCode,VchDate,Amount,CashBankNo,ChequeNo,ChequeDate) values ('" + school.CurrentSessionCode + "','" + VchNo + "','" + vouchNo + "','" + txtvchtype.Text + "','" + valcmbaccountgroup.SelectedValue + "','" + dtp.Value.Date + "','" + txtPaidAmt.Text + "','" + valcmbbank.SelectedValue + "','" + txtChkNo.Text + "','" + txtChkDate.Value + "')";
                        c.connectsql(mysql, c.myconn, trn);
                        trn.Commit();
                        MessageBox.Show("Record Update...");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        trn.Rollback();
                    }
                    trn.Dispose();
                }
mline:
                c.GetMdiParent(this).EnableAllEditMenuButtons();

                DesignForm.fromDesign1(this);
            }
        }
Beispiel #3
0
        public void btnsave_Click(object sender, EventArgs e)
        {
            int           BHM_DES  = 0;
            SqlCommand    command1 = new SqlCommand("select BHM_COD from tbl_LedgerAcc where BHM_COD=1", c.myconn);
            SqlDataReader reader1  = command1.ExecuteReader();
            int           i        = 0;

            if (reader1.HasRows)
            {
                reader1.Read();
                BHM_DES = Convert.ToInt16(reader1["BHM_COD"]);
                if (BHM_DES != 1)
                {
                    MessageBox.Show("Cannot Select Cash Account..");
                    reader1.Close();
                    goto mline;
                }
            }
            c.returnconn(c.myconn);
            txtvchtype.Text = "CR";
            if (add_edit == true)
            {
                SqlConnection con   = c.myconn;
                DateTime      dt    = dtp.Value;
                Int32         VchNo = c.getvchno(txtvchtype.Text, ref dt, con);
                vouchNo           = c.getvouchernumber(txtvchtype.Text, ref dt, con); //txtvchtype.Text +  dtp.Value.Date.ToString("ddMMyyyy") + VchNo;
                txtvoucherno.Text = vouchNo;
                SqlTransaction trn;
                trn = c.myconn.BeginTransaction();
                try
                {
                    string mysql;
                    mysql = "insert into tbl_Voucher(YearNo,VchNo,VouchNo,VchType,VchDate,Remark)values('" + school.CurrentSessionCode + "','" + VchNo + "','" + vouchNo + "','" + txtvchtype.Text + "','" + dtp.Value.Date + "','" + txtRemark.Text + "')";
                    c.connectsql(mysql, c.myconn, trn);
                    mysql = "insert into tbl_VoucherDetail (YearNo,vchno,VouchNo,VchType,AccCode,VchDate,Amount,cashbankno) values ('" + school.CurrentSessionCode + "','" + VchNo + "','" + vouchNo + "','" + txtvchtype.Text + "','" + BHM_DES + "','" + dtp.Value.Date + "'," + txtReceiptAmt.Text + ",0)";
                    c.connectsql(mysql, c.myconn, trn);
                    mysql = "insert into tbl_VoucherDetail (YearNo,vchno,VouchNo,VchType,AccCode,VchDate,Amount,cashbankno) values ('" + school.CurrentSessionCode + "','" + VchNo + "','" + vouchNo + "','" + txtvchtype.Text + "','" + valcmbaccountgroup.SelectedValue + "','" + dtp.Value.Date + "'," + -1 * Convert.ToDecimal(txtReceiptAmt.Text) + ",'" + BHM_DES + "')";
                    c.connectsql(mysql, c.myconn, trn);
                    trn.Commit();
                    MessageBox.Show("Record Saved...");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    trn.Rollback();
                }
                trn.Dispose();
            }
            if (add_edit == false)
            {
                c.getconnstr();
                c.returnconn(c.myconn);
                SqlDataReader dr = null;
                con = c.myconn;
                dr  = c.fillreader(ref dr, "select VchNo from tbl_Voucher where vchtype='CR'  and VouchNo='" + txtvoucherno.Text + "'", con);
                if (dr.HasRows == true)
                {
                    dr.Read();
                    VchNo = Convert.ToInt16(dr[0]);
                }
                dr.Close();
                SqlTransaction trn;
                trn = c.myconn.BeginTransaction();
                try
                {
                    string mysql;
                    mysql = "delete from tbl_Voucher where vchtype='CR'  and VouchNo='" + txtvoucherno.Text + "'";
                    c.connectsql(mysql, c.myconn, trn);
                    mysql = "delete from tbl_VoucherDetail where  vchtype='CR' and VouchNo='" + txtvoucherno.Text + "'";
                    c.connectsql(mysql, c.myconn, trn);
                    mysql = "insert into tbl_Voucher(YearNo,VchNo,VouchNo,VchType,VchDate,Remark)values('" + school.CurrentSessionCode + "','" + VchNo + "','" + vouchNo + "','" + txtvchtype.Text + "','" + dtp.Value.Date + "','" + txtRemark.Text + "')";
                    c.connectsql(mysql, c.myconn, trn);
                    mysql = "insert into tbl_VoucherDetail (YearNo,vchno,VouchNo,VchType,AccCode,VchDate,Amount,cashbankno) values ('" + school.CurrentSessionCode + "','" + VchNo + "','" + vouchNo + "','" + txtvchtype.Text + "','" + BHM_DES + "','" + dtp.Value.Date + "'," + txtReceiptAmt.Text + "," + BHM_DES + ")";
                    c.connectsql(mysql, c.myconn, trn);
                    mysql = "insert into tbl_VoucherDetail (YearNo,vchno,VouchNo,VchType,AccCode,VchDate,Amount,cashbankno) values ('" + school.CurrentSessionCode + "','" + VchNo + "','" + vouchNo + "','" + txtvchtype.Text + "','" + valcmbaccountgroup.SelectedValue + "','" + dtp.Value.Date + "'," + -1 * Convert.ToDecimal(txtReceiptAmt.Text) + ",0)";
                    c.connectsql(mysql, c.myconn, trn);
                    trn.Commit();
                    MessageBox.Show("Record Update...");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    trn.Rollback();
                }
                trn.Dispose();
            }
mline:
            c.GetMdiParent(this).EnableAllEditMenuButtons();

            DesignForm.fromDesign1(this);
        }