Exemplo n.º 1
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            try
            {
                if (tb_Total_Bill.Text != "")
                {
                    obj.openconnection();
                    obj.globalVal_Custid(0, int.Parse(tb_Customer_ID.Text));
                    obj.cmd = new SqlCommand(" insert into Customer_Master values (" + tb_Customer_ID.Text + " , '" + tb_Customer_Name.Text + "' , '" + dtp_Bill_Date.Text + "' , " + tb_Customer_Mob_No.Text + ",'" + tb_Cust_GSTIN.Text + "' , " + tb_Bill.Text + " , " + tb_Discount.Text + " , " + tb_Total_Bill.Text + " )", obj.con);

                    if (obj.cmd.ExecuteNonQuery() > 0)
                    {
                        goto nxtquery;
                    }
                    else
                    {
                        MessageBox.Show("Record are Not saved Successfully");
                    }
                    nxtquery :;
                    obj.cmd.Dispose();

                    int i = 0;
                    foreach (DataGridViewRow row in dgv_new_bill.Rows)
                    {
                        if (i == (dgv_new_bill.Rows.Count - 1))
                        {
                            goto nxt;
                        }
                        //  int Mob_id = 0;
                        obj.cmd = new SqlCommand(" Insert into Customer_Purchase_Detail values(" + dgv_new_bill.Rows[i].Cells[0].Value + ",'" + dgv_new_bill.Rows[i].Cells[1].Value + "','" + dgv_new_bill.Rows[i].Cells[2].Value + "','" + dgv_new_bill.Rows[i].Cells[3].Value + "'," + dgv_new_bill.Rows[i].Cells[4].Value + "," + dgv_new_bill.Rows[i].Cells[5].Value + "," + dgv_new_bill.Rows[i].Cells[6].Value + " ," + dgv_new_bill.Rows[i].Cells[7].Value + "," + dgv_new_bill.Rows[i].Cells[8].Value + "," + dgv_new_bill.Rows[i].Cells[9].Value + "," + dgv_new_bill.Rows[i].Cells[10].Value + " )", obj.con);
                        obj.cmd.ExecuteNonQuery();
                        obj.cmd.Dispose();

                        i = i + 1;
                    }
                    nxt :;

                    if (i > 0)
                    {
                        //obj.globalVal_Custid(0,int.Parse(tb_Customer_ID.Text));

                        MessageBox.Show("Record Added Successfully...");

                        frm_Bill_History_by_Cust_Name obj1 = new frm_Bill_History_by_Cust_Name();
                        obj1.Show();
                    }
                    else
                    {
                        MessageBox.Show("Server Error..");
                    }

                    tb_Customer_Name.Text   = "";
                    tb_Customer_Mob_No.Text = "";
                    tb_Bill.Text            = "";
                    tb_Discount.Text        = "0";
                    tb_Price.Text           = "";
                    tb_Quantity.Text        = "";
                    tb_Total_Bill.Text      = "";
                    tb_Customer_Mob_No.Text = "";
                    cb_Brand_Name.Text      = "";
                    cb_Model_Name.Text      = "";
                    tb_Total_Price.Text     = "";
                    dgv_new_bill.DataSource = "";

                    int f = 0;
                    f = obj.Auto_Increment("select count(Customer_ID) from Customer_Master", 1);
                    tb_Customer_ID.Text = Convert.ToString(f);
                }
                else
                {
                    MessageBox.Show("Please fill all fields");
                }
            }
            catch (Exception ex)
            {
                //  Block of code to handle errors
                MessageBox.Show(ex.Message);
            }
        }
        private void frm_Bill_History_by_Cust_Name_Load(object sender, EventArgs e)
        {
            try
            {
                int iFormLoad = obj.globalVal_FormLoad(1);
                if (iFormLoad == -1)
                {
                    goto nxt;
                }
                int temp;
                temp           = obj.globalVal_Custid(1, 0);
                tb_search.Text = Convert.ToString(temp);


                if (tb_search.Text != "") //when user come through new invice
                {
                    lbl.Visible         = false;
                    tb_Category.Visible = false;
                    btn_Search.Visible  = false;
                    con.Open();

                    DataTable dt  = new DataTable();
                    DataTable dt1 = new DataTable();

                    cmd.Connection = con;

                    cmd = new SqlCommand("select * from Customer_Master where Customer_ID = " + tb_search.Text + " ", con);
                    SqlDataAdapter adp = new SqlDataAdapter(cmd);
                    adp.Fill(dt);

                    // obj.cmd.Dispose();



                    cmd = new SqlCommand("select * from Customer_Purchase_Detail where Customer_ID = " + tb_search.Text + " ", con);
                    adp = new SqlDataAdapter(cmd);
                    adp.Fill(dt1);


                    Report.rpt_1 rpt = new Report.rpt_1();
                    rpt.Database.Tables["Customer_Master"].SetDataSource(dt);
                    rpt.Database.Tables["Customer_Purchase_Detail"].SetDataSource(dt1);
                    crv_bill_history_Cust.ReportSource = null;
                    crv_bill_history_Cust.ReportSource = rpt;

                    obj.cmd.Dispose();
                }
                else
                {
                    MessageBox.Show("Please fill the All Fields...");
                }

                nxt :;
                // this.crv_bill_history_Cust.RefreshReport();
            }
            catch (Exception ex)
            {
                //  Block of code to handle errors
                MessageBox.Show(ex.Message);
            }
        }