Exemplo n.º 1
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (ID > -1)
                {
                    dbconnection.Open();

                    string       query = "update car_travel set Car_ID ='" + comCarNumber.SelectedValue + "' ,Travel_Destination='" + txtTravelDes.Text + "',Custody='" + txtCustody.Text + "',Settlement_Custody=" + txtSettlement_Custody.Text + ",Rest_Custody=" + txtRest.Text + ",Note='" + txtNote.Text + "' where ID=" + ID + "";
                    MySqlCommand com   = new MySqlCommand(query, dbconnection);
                    com.ExecuteNonQuery();

                    double totalSafay = 0;
                    query = "select TotalSafay from Total_Revenue_Of_CarIncom where Car_ID=" + comCarNumber.SelectedValue + "";
                    com   = new MySqlCommand(query, dbconnection);
                    MySqlDataReader dr = com.ExecuteReader();
                    while (dr.Read())
                    {
                        totalSafay = Convert.ToDouble(dr["TotalSafay"].ToString());
                    }
                    totalSafay -= Convert.ToDouble(txtRest.Text);
                    dr.Close();

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

                    MessageBox.Show("Done");
                    carEl3hata.displayData();
                    XtraTabPage xtraTabPage = getTabPage("تعديل العهدة");
                    xtraTabPage.ImageOptions.Image = null;
                }
                else
                {
                    MessageBox.Show("select row please");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (comCarNumber.Text != "" && txtCustody.Text != "" && txtPreRest.Text != "" && txtRest.Text != "" && txtSettlement_Custody.Text != "" && txtTravelDes.Text != "")
                {
                    dbconnection.Open();
                    string       query = "insert into car_travel (Date,Car_ID,Travel_Destination,Custody,Settlement_Custody,Rest_Custody,Previous_Custody,Note) values (@Date,@Car_ID,@Travel_Destination,@Custody,@Settlement_Custody,@Rest_Custody,@Previous_Custody,@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.VarChar);
                    com.Parameters["@Car_ID"].Value = comCarNumber.SelectedValue;
                    com.Parameters.Add("@Travel_Destination", MySqlDbType.VarChar);
                    com.Parameters["@Travel_Destination"].Value = txtTravelDes.Text;
                    com.Parameters.Add("@Custody", MySqlDbType.VarChar);
                    com.Parameters["@Custody"].Value = txtCustody.Text;
                    com.Parameters.Add("@Settlement_Custody", MySqlDbType.VarChar);
                    com.Parameters["@Settlement_Custody"].Value = txtSettlement_Custody.Text;
                    com.Parameters.Add("@Rest_Custody", MySqlDbType.VarChar);
                    com.Parameters["@Rest_Custody"].Value = txtRest.Text;
                    com.Parameters.Add("@Previous_Custody", MySqlDbType.VarChar);
                    com.Parameters["@Previous_Custody"].Value = txtPreRest.Text;

                    if (txtNote.Text != "")
                    {
                        com.Parameters.Add("@Note", MySqlDbType.Double);
                        com.Parameters["@Note"].Value = txtNote.Text;
                    }
                    else
                    {
                        com.Parameters.Add("@Note", MySqlDbType.Double);
                        com.Parameters["@Note"].Value = null;
                    }
                    com.ExecuteNonQuery();

                    double totalSafay = Convert.ToDouble(txtRest.Text);
                    query = "select TotalSafay 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());
                        flag       = true;
                    }

                    dr.Close();
                    if (flag)
                    {
                        totalSafay -= Convert.ToDouble(txtRest.Text);
                        query       = "update Total_Revenue_Of_CarIncom set TotalSafay=" + totalSafay + " 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 = 0;
                        com.Parameters.Add("@Car_ID", MySqlDbType.VarChar);
                        com.Parameters["@Car_ID"].Value = comCarNumber.Text;
                        com.ExecuteNonQuery();
                    }
                    MessageBox.Show("Done");
                    update();
                    txtTravelDes.Text = "";
                    txtNote.Text      = "";
                    carEl3hata.displayData();
                }
                else
                {
                    MessageBox.Show("insert required fields");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            dbconnection.Close();
        }