예제 #1
0
        private void cboTipCode_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboTipCode.Text == "")
            {
                MessageBox.Show("Ensure that all fields are filled!", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cboTipCode.Focus();
            }
            else
            {
                conn connect = new conn();
                if (connect.OpenConnection() == true)
                {
                    query = "SELECT * FROM tip WHERE Tip_Code LIKE '" + cboTipCode.Text + "' ORDER BY Tip_Code ASC";
                    MySqlCommand    cmd        = new MySqlCommand(query, connect.connection);
                    MySqlDataReader dataReader = cmd.ExecuteReader();
                    //Read the data and store them in the list

                    if (dataReader.Read())
                    {
                        this.cboTipType.Text      = dataReader["Tip_Type"].ToString();
                        this.dtpTime.Text         = dataReader["Time_Interval"].ToString();
                        this.rtxtDescription.Text = dataReader["Description"].ToString();

                        tipCode = dataReader["Tip_Code"].ToString();       //for editing
                    }
                    connect.CloseConnection();
                }
            }
        }
예제 #2
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     //for deletion
     if (cboFarmerId.Visible == false)
     {
         MessageBox.Show("Select Details to Edit");
         cboFarmerId.Visible = true;
     }
     else if (MessageBox.Show("Are you sure you want to exit?", "MESS Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         query = "DELETE FROM farmer WHERE Farmer_Id='" + cboFarmerId.TabIndex + "'";
         try
         {
             conn connect = new conn();
             if (connect.OpenConnection() == true)
             {
                 MySqlCommand cmd = new MySqlCommand(query, connect.connection);
                 cmd.ExecuteNonQuery();
                 connect.CloseConnection();
                 MessageBox.Show("Record Successfully deleted!", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 Reset();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("" + ex);
         }
     }
 }
예제 #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtTipCode.Text == "" && cboTipCode.Visible == false)
            {
                MessageBox.Show("Ensure all fields are filled", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtTipCode.Focus();
            }
            else if (cboTipCode.Text == "" && cboTipCode.Visible == true)
            {
                MessageBox.Show("Ensure all fields are filled", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cboTipCode.Focus();
            }
            else if (cboTipType.Text == "")
            {
                MessageBox.Show("Ensure all fields are filled", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cboTipType.Focus();
            }
            else if (dtpTime.Text == "")
            {
                MessageBox.Show("Ensure all fields are filled", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                dtpTime.Focus();
            }
            else if (rtxtDescription.Text == "")
            {
                MessageBox.Show("Ensure all fields are filled", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                rtxtDescription.Focus();
            }

            else
            {
                if (cboTipCode.Visible == true)
                {
                    query = "UPDATE Tip SET Tip_Code='" + cboTipCode.Text + "', Tip_Type='" + cboTipType.Text + "', Time_Interval= '" + dtpTime.Text + "', Description= '" + rtxtDescription.Text + "' WHERE Tip_Code= '" + tipCode + "'";
                }

                else
                {
                    query = "INSERT INTO tip(Tip_Code, Tip_Type, Time_Interval, Description) VALUES('" + txtTipCode.Text + "', '" + cboTipType.Text + "', '" + dtpTime.Text + "',, '" + rtxtDescription.Text + "')";
                }
                try
                {
                    conn connect = new conn();
                    if (connect.OpenConnection() == true)
                    {
                        //create command and assign the query and connection from the constructor
                        MySqlCommand cmd = new MySqlCommand(query, connect.connection);
                        //MySqlDataReader dataReader
                        cmd.ExecuteReader();
                        connect.CloseConnection();
                        MessageBox.Show("Record Successfully saved!", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Reset();
                    }
                }


                catch (Exception ex)
                {
                    MessageBox.Show("" + ex);
                }
            }
        }
예제 #4
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (txtFarmerId.Text == "" && cboFarmerId.Visible == false)
            {
                MessageBox.Show("Ensure all fields are filled", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtFarmerId.Focus();
            }
            if (cboFarmerId.Text == "" && cboFarmerId.Visible == true)
            {
                MessageBox.Show("Ensure all fields are filled", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cboFarmerId.Focus();
            }
            else if (txtFirstName.Text == "")
            {
                MessageBox.Show("Ensure all fields are filled", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtFirstName.Focus();
            }
            else if (txtMiddleName.Text == "")
            {
                MessageBox.Show("Ensure all fields are filled", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtMiddleName.Focus();
            }
            else if (txtLastName.Text == "")
            {
                MessageBox.Show("Ensure all fields are filled", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtLastName.Focus();
            }

            else if (txtPostalCode.Text == "")
            {
                MessageBox.Show("Ensure all fields are filled", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPostalCode.Focus();
            }
            else if (txtEmailAddress.Text == "")
            {
                MessageBox.Show("Ensure all fields are filled", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtEmailAddress.Focus();
            }
            else if (txtPhoneNo.Text == "")
            {
                MessageBox.Show("Ensure all fields are filled", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPhoneNo.Focus();
            }
            else if (cboStatus.Text == "")
            {
                MessageBox.Show("Ensure all fields are filled", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cboStatus.Focus();
            }
            else if (txtTipCode.Text == "")
            {
                MessageBox.Show("Ensure all fields are filled", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtTipCode.Focus();
            }
            else if (txtOfficerId.Text == "")
            {
                MessageBox.Show("Ensure all fields are filled", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtOfficerId.Focus();
            }



            else
            {
                if (cboFarmerId.Visible == true)
                {
                    query = "UPDATE farmer SET Farmer_Id='" + cboFarmerId.Text + "', F_Name='" + txtFirstName.Text + "', M_Name= '" + txtMiddleName.Text + "', L_Name= '" + txtLastName.Text + "', Postal_Code='" + txtPostalCode.Text + "', Email_Address='" + txtEmailAddress.Text + "', Phone_No='" + txtPhoneNo.Text + "', Status='" + cboStatus.Text + "', Tip_Code='" + txtTipCode.Text + "', Officer_Id='" + txtOfficerId.Text + "' WHERE Farmer_Id= '" + famCode + "'";
                }

                else
                {
                    query = "INSERT INTO farmer(Farmer_Id, F_Name, M_Name, L_Name,Postal_Code, Email_Address, Phone_No, Status,Tip_Code,Officer_Id) VALUES('" + txtFarmerId.Text + "', '" + txtFirstName.Text + "', '" + txtMiddleName.Text + "',, '" + txtLastName.Text + "' '" + txtPostalCode.Text + "', '" + txtEmailAddress.Text + "', '" + txtPhoneNo.Text + "', '" + cboStatus.Text + "', '" + txtTipCode.Text + "', '" + txtOfficerId.Text + "')";
                }
                try
                {
                    conn connect = new conn();
                    if (connect.OpenConnection() == true)
                    {
                        //create command and assign the query and connection from the constructor
                        MySqlCommand cmd = new MySqlCommand(query, connect.connection);
                        //MySqlDataReader dataReader
                        cmd.ExecuteReader();
                        connect.CloseConnection();
                        MessageBox.Show("Record Successfully saved!", "MESS Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Reset();
                    }
                }


                catch (Exception ex)
                {
                    MessageBox.Show("" + ex);
                }
            }
        }