예제 #1
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (ID > -1)
                {
                    dbconnection.Open();

                    getGateValue();
                    getTaategValue();
                    getSafayValue();
                    string       query = "update car_income set Car_ID ='" + comCarNumber.SelectedValue + "' ,Address='" + txtAddress.Text + "',NoCarton='" + txtNoCarton.Text + "',NoSets=" + txtNoSets.Text + ",NoDocks=" + txtNoDocks.Text + ",NoColumns=" + txtNoColumns.Text + ",NoCompinations=" + txtNoComp.Text + ",NoPanio=" + txtNoPanio.Text + ",Nolon=" + txtNolone.Text + ",Gate =" + gate + ",Taateg =" + Taateg + ",Safay=" + SafayCar_Number + " where Car_Income_ID=" + ID + "";
                    MySqlCommand com   = new MySqlCommand(query, dbconnection);
                    com.ExecuteNonQuery();
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        if (ID > 0)
                        {
                            query = "update  Car_Permission set Permission_Number=" + row.Cells[0].Value + " where Car_Income_ID=" + ID + "";
                            com   = new MySqlCommand(query, dbconnection);
                            com.ExecuteNonQuery();
                        }
                    }

                    totalSafay += getSafayValue();
                    totalGate  += getGateValue();


                    query = "update Total_Revenue_Of_CarIncom set TotalSafay=" + totalSafay + ",TotalGate=" + totalGate + " where Car_ID=" + comCarNumber.SelectedValue;
                    com   = new MySqlCommand(query, dbconnection);
                    com.ExecuteNonQuery();

                    MessageBox.Show("Done");
                    carIncomes.displayData();
                }
                else
                {
                    MessageBox.Show("select row please");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                dbconnection.Open();
                if (txtAddress.Text != "" && txtNolone.Text != "")
                {
                    string       query = "insert into car_Income (Car_ID,Address,NoCarton,NoSets,NoDocks,NoColumns,NoCompinations,NoPanio,Nolon,Gate,Taateg,Safay,Date,Note) values (@Car_ID,@Address,@NoCarton,@NoSets,@NoDocks,@NoColumns,@NoCompinations,@NoPanio,@Nolon,@Gate,@Taateg,@Safay,@Date,@Note)";
                    MySqlCommand com   = new MySqlCommand(query, dbconnection);

                    com.Parameters.Add("@Date", MySqlDbType.Date);
                    com.Parameters["@Date"].Value = dateTimePicker1.Value.Date;
                    com.Parameters.Add("@Car_ID", MySqlDbType.Int16);
                    com.Parameters["@Car_ID"].Value = comCarNumber.SelectedValue;
                    com.Parameters.Add("@Address", MySqlDbType.VarChar);
                    com.Parameters["@Address"].Value = txtAddress.Text;
                    com.Parameters.Add("@NoCarton", MySqlDbType.Double);
                    com.Parameters["@NoCarton"].Value = txtNoCarton.Text;
                    com.Parameters.Add("@NoSets", MySqlDbType.Double);
                    com.Parameters["@NoSets"].Value = txtNoSets.Text;
                    com.Parameters.Add("@NoDocks", MySqlDbType.Double);
                    com.Parameters["@NoDocks"].Value = txtNoDocks.Text;
                    com.Parameters.Add("@NoColumns", MySqlDbType.Double);
                    com.Parameters["@NoColumns"].Value = txtNoColumns.Text;
                    com.Parameters.Add("@NoCompinations", MySqlDbType.Double);
                    com.Parameters["@NoCompinations"].Value = txtNoComp.Text;
                    com.Parameters.Add("@NoPanio", MySqlDbType.Double);
                    com.Parameters["@NoPanio"].Value = txtNoPanio.Text;
                    com.Parameters.Add("@Nolon", MySqlDbType.Double);
                    com.Parameters["@Nolon"].Value = txtNolone.Text;
                    com.Parameters.Add("@Gate", MySqlDbType.Double);
                    com.Parameters["@Gate"].Value = getGateValue();
                    com.Parameters.Add("@Taateg", MySqlDbType.Double);
                    com.Parameters["@Taateg"].Value = getTaategValue();
                    com.Parameters.Add("@Safay", MySqlDbType.Double);
                    com.Parameters["@Safay"].Value = getSafayValue();
                    if (txtNote.Text != "")
                    {
                        com.Parameters.Add("@Note", MySqlDbType.VarChar);
                        com.Parameters["@Note"].Value = txtNote.Text;
                    }
                    else
                    {
                        com.Parameters.Add("@Note", MySqlDbType.VarChar);
                        com.Parameters["@Note"].Value = null;
                    }
                    com.ExecuteNonQuery();

                    double totalSafay = 0, totalGate = 0;
                    query = "select TotalSafay,TotalGate from Total_Revenue_Of_CarIncom where Car_ID= " + comCarNumber.SelectedValue + "";
                    com   = new MySqlCommand(query, dbconnection);
                    MySqlDataReader dr   = com.ExecuteReader();
                    bool            flag = false;
                    while (dr.Read())
                    {
                        totalSafay = Convert.ToDouble(dr["TotalSafay"].ToString());
                        if (dr["TotalGate"].ToString() != "")
                        {
                            totalGate = Convert.ToDouble(dr["TotalGate"].ToString());
                        }
                        flag = true;
                    }
                    totalSafay += getSafayValue();
                    totalGate  += getGateValue();
                    dr.Close();
                    if (flag)
                    {
                        query = "update Total_Revenue_Of_CarIncom set TotalSafay=" + totalSafay + ",TotalGate=" + totalGate + " where Car_ID= " + comCarNumber.SelectedValue;
                        com   = new MySqlCommand(query, dbconnection);
                        com.ExecuteNonQuery();
                    }
                    else
                    {
                        query = "insert into  Total_Revenue_Of_CarIncom  (TotalSafay,TotalGate, Car_ID) values(@TotalSafay,@TotalGate,@Car_ID)";
                        com   = new MySqlCommand(query, dbconnection);
                        com.Parameters.Add("@TotalSafay", MySqlDbType.Double);
                        com.Parameters["@TotalSafay"].Value = totalSafay;
                        com.Parameters.Add("@TotalGate", MySqlDbType.Double);
                        com.Parameters["@TotalGate"].Value = totalGate;
                        com.Parameters.Add("@Car_ID", MySqlDbType.Int16);
                        com.Parameters["@Car_ID"].Value = comCarNumber.SelectedValue;
                        com.ExecuteNonQuery();
                    }


                    query = "select Car_Income_ID from Car_Income order by Car_Income_ID Desc limit 1";
                    com   = new MySqlCommand(query, dbconnection);
                    int id = 0;
                    if (com.ExecuteScalar() != null)
                    {
                        id = Convert.ToInt16(com.ExecuteScalar());
                    }
                    else
                    {
                        MessageBox.Show("error :(");
                        dbconnection.Close();
                        return;
                    }
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        if (id > 0)
                        {
                            query = "insert into Car_Permission (Car_Income_ID,Permission_Number) values (@Car_Income_ID,@Permission_Number)";
                            com   = new MySqlCommand(query, dbconnection);

                            com.Parameters.Add("@Car_Income_ID", MySqlDbType.Int16);
                            com.Parameters["@Car_Income_ID"].Value = id;
                            com.Parameters.Add("@Permission_Number", MySqlDbType.VarChar);
                            com.Parameters["@Permission_Number"].Value = row.Cells[0].Value;
                            com.ExecuteNonQuery();
                        }
                    }

                    MessageBox.Show("ADD Success");
                    carIncomes.displayData();
                    clear();
                }
                else
                {
                    MessageBox.Show("insert data to all fields");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            dbconnection.Close();
        }