示例#1
0
        //save button code
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                int id1 = Convert.ToInt32(textBox8.Text);
                if (id1 == 0)
                {
                    if (checkBox1.Checked == true)
                    {
                        val = "1";
                    }
                    else
                    {
                        val = "0";
                    }

                    connection.Open();
                    string       command1 = "insert into main_sales_return(n_no, n_date, c_name,type,in_no,total,notes,stock_add) values('" + textBox1.Text + "','" + dateTimePicker1.Text + "','" + comboBox1.Text + "','" + comboBox2.Text + "','" + comboBox3.Text + "','" + textBox7.Text + "','" + textBox4.Text + "','" + val + "') ";
                    OleDbCommand cmdd1    = new OleDbCommand(command1, connection);
                    cmdd1.ExecuteNonQuery();
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        string       command = "insert into sales_return(n_no, n_date, c_name, city, type,in_no,in_date,invoice_amount,item_code,item_name,item_price,r_qty,unit,disc,disc_amt,r_amt,net_amount,notes) values('" + textBox1.Text + "','" + dateTimePicker1.Text + "','" + comboBox1.Text + "','" + textBox2.Text + "','" + comboBox2.Text + "','" + comboBox3.Text + "','" + dateTimePicker2.Text + "','" + textBox3.Text + "',@item_code,@item_name,@item_price,@r_qty,@unit,@disc,@disc_amt,@r_amt,'" + textBox7.Text + "','" + textBox4.Text + "') ";
                        OleDbCommand cmdd    = new OleDbCommand(command, connection);
                        cmdd.Parameters.AddWithValue("@item_code", row.Cells[0].Value);
                        cmdd.Parameters.AddWithValue("@item_name", row.Cells[1].Value);
                        cmdd.Parameters.AddWithValue("@item_price", row.Cells[2].Value);
                        cmdd.Parameters.AddWithValue("@r_qty", row.Cells[3].Value);
                        cmdd.Parameters.AddWithValue("@unit", row.Cells[4].Value);
                        cmdd.Parameters.AddWithValue("@disc", row.Cells[5].Value);
                        cmdd.Parameters.AddWithValue("@disc_amt", row.Cells[6].Value);
                        cmdd.Parameters.AddWithValue("@r_amt", row.Cells[7].Value);

                        cmdd.ExecuteNonQuery();
                        if (checkBox1.Checked == true)
                        {
                            invoice.code = row.Cells[0].Value.ToString();
                            stock_check st = new stock_check();
                            st.getstock();
                            invoice.code = row.Cells[0].Value.ToString();
                            invoice.qty  = Convert.ToString(stock_check.stock + Convert.ToDouble(row.Cells[3].Value.ToString()));
                            insert_update_invoice up = new insert_update_invoice();
                            up.update_stock();
                        }
                    }
                    //update order id and ref no by 1

                    int idd = 1;
                    return_no = get_id.sales_return_no + 1;

                    try
                    {
                        OleDbCommand command2 = new OleDbCommand(@"UPDATE get_id
                                                    SET sales_return_no = @p_order_no
                                                        WHERE ID = " + idd + "", connection);

                        command2.Parameters.AddWithValue("@p_order_no", return_no);

                        command2.ExecuteNonQuery();
                        connection.Close();
                    }
                    catch (Exception a)
                    {
                        MessageBox.Show("" + a);
                    }
                    resetform();
                    gridview();
                    grid();
                    getid();
                }
                else
                {
                    MessageBox.Show("Cannot Access");
                }
            }
            catch (Exception o)
            {
                MessageBox.Show("" + o);
            }
            finally
            {
                connection.Close();
            }
        }
示例#2
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count > 0)
            {
                if (textBox3.Text == "0")
                {
                    try
                    {
                        //insert into in_main
                        if (connection.State == ConnectionState.Open)
                        {
                            connection.Close();
                        }
                        connection.Open();
                        string com = "insert into main_return(n_no,n_date,ref_no, ref_date,type,name,rec_no)" +
                                     " values('" + textBox1.Text + "','" + dateTimePicker1.Text + "','" + textBox2.Text + "'," +
                                     "'" + dateTimePicker3.Text + "','" + comboBox1.Text + "','" + comboBox2.Text + "'," +
                                     "'" + comboBox2.Text + "') ";
                        OleDbCommand comm = new OleDbCommand(com, connection);
                        comm.ExecuteNonQuery();

                        foreach (DataGridViewRow row in dataGridView1.Rows)
                        {
                            string command = "insert into stock_return(n_no,n_date,ref_no, ref_date,type,name,deli_note," +
                                             "d_date,item_code,item_name,r_qty,unit,notes) " +
                                             "values('" + textBox1.Text + "','" + dateTimePicker1.Text + "','" + textBox2.Text + "'," +
                                             "'" + dateTimePicker3.Text + "','" + comboBox1.Text + "'," +
                                             "'" + comboBox2.Text + "','" + comboBox3.Text + "','" + dateTimePicker2.Text +
                                             "',@item_code,@item_name,@qty,@unit,'" + textBox4.Text + "') ";
                            OleDbCommand cmdd = new OleDbCommand(command, connection);
                            cmdd.Parameters.AddWithValue("@item_code", row.Cells[0].Value);
                            cmdd.Parameters.AddWithValue("@item_name", row.Cells[1].Value);
                            cmdd.Parameters.AddWithValue("@qty", row.Cells[2].Value);
                            cmdd.Parameters.AddWithValue("@unit", row.Cells[3].Value);
                            cmdd.ExecuteNonQuery();

                            invoice.code = row.Cells[0].Value.ToString();
                            stock_check st = new stock_check();
                            st.getstock();
                            invoice.code = row.Cells[0].Value.ToString();
                            invoice.qty  = Convert.ToString(stock_check.stock - Convert.ToDouble(row.Cells[2].Value.ToString()));
                            insert_update_invoice up = new insert_update_invoice();
                            up.update_stock();
                        }
                    }
                    catch (Exception r)
                    {
                        MessageBox.Show("" + r);
                    }
                    finally
                    {
                        if (connection.State == ConnectionState.Open)
                        {
                            connection.Close();
                        }
                        reset();
                        gridview();
                        grid();

                        //update order id and ref no by 1
                        int note_no      = 0;
                        int reference_no = 0;
                        int idd          = 1;
                        note_no      = get_id.stockreturn_note_no + 1;
                        reference_no = get_id.stockreturn_ref_no + 1;
                        try
                        {
                            OleDbCommand command = new OleDbCommand(@"UPDATE get_id
                                                    SET stockreturn_no = @p_order_no,
                                                        stockreturnref = @p_orderref_no
                                                    WHERE ID = " + idd + "", connection);

                            command.Parameters.AddWithValue("@p_order_no", note_no);
                            command.Parameters.AddWithValue("@p_orderref_no", reference_no);
                            if (connection.State == ConnectionState.Open)
                            {
                                connection.Close();
                            }
                            connection.Open();
                            command.ExecuteNonQuery();
                            if (connection.State == ConnectionState.Open)
                            {
                                connection.Close();
                            }
                        }
                        catch (Exception a)
                        {
                            MessageBox.Show("" + a);
                        }
                        textBox1.Text = Convert.ToString(note_no);
                        textBox2.Text = Convert.ToString(reference_no);
                    }
                }
                else
                {
                    MessageBox.Show("Cannot Access");
                }
            }
        }
示例#3
0
        //----------------save code------------------------
        private void button3_Click(object sender, EventArgs e)
        {
            //---------------- insert query------------------------
            try
            {
                int id = Convert.ToInt32(textBox3.Text);

                if (id == 0)
                {
                    string status = "";
                    string due    = "";
                    if (Convert.ToDouble(textBox19.Text) == Convert.ToDouble(textBox20.Text))
                    {
                        status = "Paid";
                        due    = "0";
                    }
                    else
                    {
                        status = "Due";
                        due    = Convert.ToString(Convert.ToDouble(textBox19.Text) - Convert.ToDouble(textBox20.Text));
                    }
                    //insert into in_main
                    connection.Open();
                    string       com  = "insert into in_main(in_no,in_date,or_no, or_date,c_code,c_name,amount,status,due_amount,type) values('" + textBox2.Text + "','" + dateTimePicker1.Text + "','" + comboBox1.Text + "','" + dateTimePicker2.Text + "','" + textBox4.Text + "','" + comboBox2.Text + "','" + textBox19.Text + "',@status,@due,@type) ";
                    OleDbCommand comm = new OleDbCommand(com, connection);
                    comm.Parameters.AddWithValue("@status", status);
                    comm.Parameters.AddWithValue("@due", due);
                    comm.Parameters.AddWithValue("@type", "tax");
                    comm.ExecuteNonQuery();
                    connection.Close();

                    foreach (DataGridViewRow row in dataGridView2.Rows)
                    {
                        connection.Open();
                        string       command = "insert into invoice(in_no,in_date,order_no, order_date,c_name,b_add,b_city,b_zip,b_state,b_country,s_add,s_city,s_zip,s_state,s_country,sales_person,contact_name,item_code,item_name,qty,unit,price,disc,disc_amount,total,disamount,cgst,cgst_amt,sgst,sgst_amt,notes,net_amount,receive_amount,type) values('" + textBox2.Text + "','" + dateTimePicker1.Text + "','" + comboBox1.Text + "','" + dateTimePicker2.Text + "','" + comboBox2.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "','" + textBox12.Text + "','" + textBox11.Text + "','" + textBox10.Text + "','" + textBox14.Text + "','" + textBox13.Text + "','" + comboBox3.Text + "','" + textBox15.Text + "',@item_code,@item_name,@qty,@unit,@price,@disc,@disc_amount,@total,@dismount,@cgst,@cgst_amt,@sgst,@sgst_amt,'" + textBox16.Text + "','" + textBox19.Text + "','" + textBox20.Text + "',@type) ";
                        OleDbCommand cmdd    = new OleDbCommand(command, connection);
                        cmdd.Parameters.AddWithValue("@item_code", row.Cells[0].Value);
                        cmdd.Parameters.AddWithValue("@item_name", row.Cells[1].Value);
                        cmdd.Parameters.AddWithValue("@qty", row.Cells[2].Value);
                        cmdd.Parameters.AddWithValue("@unit", row.Cells[3].Value);
                        cmdd.Parameters.AddWithValue("@price", row.Cells[4].Value);
                        cmdd.Parameters.AddWithValue("@disc", row.Cells[5].Value);
                        cmdd.Parameters.AddWithValue("@disc_amount", row.Cells[6].Value);
                        cmdd.Parameters.AddWithValue("@total", row.Cells[7].Value);
                        cmdd.Parameters.AddWithValue("@disamount", row.Cells[8].Value);
                        cmdd.Parameters.AddWithValue("@cgst", row.Cells[9].Value);
                        cmdd.Parameters.AddWithValue("@cgst_amt", row.Cells[10].Value);
                        cmdd.Parameters.AddWithValue("@sgst", row.Cells[11].Value);
                        cmdd.Parameters.AddWithValue("@sgst_amt", row.Cells[12].Value);
                        cmdd.Parameters.AddWithValue("@type", "tax");
                        cmdd.ExecuteNonQuery();

                        invoice.code = row.Cells[0].Value.ToString();
                        stock_check st = new stock_check();
                        st.getstock();
                        invoice.code = row.Cells[0].Value.ToString();
                        invoice.qty  = Convert.ToString(stock_check.stock - Convert.ToDouble(row.Cells[2].Value.ToString()));
                        insert_update_invoice up = new insert_update_invoice();
                        up.update_stock();


                        int idd = 1;
                        taxinvoice_id = get_id.taxinvoice_id + 1;

                        try
                        {
                            OleDbCommand command2 = new OleDbCommand(@"UPDATE get_id
                                                    SET invoice_id = @p_order_no                                                     
                                                    WHERE ID = " + idd + "", connection);

                            command2.Parameters.AddWithValue("@p_order_no", taxinvoice_id);

                            command2.ExecuteNonQuery();
                            connection.Close();
                        }
                        catch (Exception a)
                        {
                            MessageBox.Show("" + a);
                        }
                        gridview();
                        grid();
                        clear();
                        getid();
                    }
                }
                else
                {
                    MessageBox.Show("Can't update Invoice");
                }
            }
            catch (Exception u)
            {
                MessageBox.Show("" + u);
            }
            finally
            {
                connection.Close();
            }
        }