- Messages
- 165
- Reaction score
- 0
- Points
- 26
hello po mga sir, gumawa po ako ng error handler na kapag may existing user may lalabas na error, pero lumalabas yung error message at yung DialogResult parehas, ang gusto ko po sanang mangyari, ichecheck nya muna yung values if existing then lalabas yung error message, if hindi naman existing lalabas yung save message pano po ba magagawa yun?
eto po yung code ko sa save:
tapos eto po yung code ko sa usercheck() method
Pano po aayusin to mga master? thank you po
eto po yung code ko sa save:
Code:
usercheck();
DialogResult dr = MetroMessageBox.Show(this, "Are you sure you want to Save without your desire Sales Count or Sales Amount?", "Wait!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (txtCount.Text == "0" || txtAmount.Text == "0")
{
if (dr == DialogResult.Yes)
{
Data.con.Open();
string SaveStr = "Insert into dbinfo.tbluser (UserID, UserName, UserPassword, UserLevel, TargetCount, TargetAmount) Values (@UserID, @UserName, @UserPassword, @UserLevel, @TargetCount, @TargetAmount)";
MySqlCommand SaveCmd = new MySqlCommand(SaveStr, Data.con);
SaveCmd.Parameters.AddWithValue("@UserID", txtID.Text);
SaveCmd.Parameters.AddWithValue("@UserName", txtName.Text);
SaveCmd.Parameters.AddWithValue("@UserPassword", txtPassword.Text);
SaveCmd.Parameters.AddWithValue("@UserLevel", cbLevel.Text);
SaveCmd.Parameters.AddWithValue("@TargetCount", txtCount.Text);
SaveCmd.Parameters.AddWithValue("@TargetAmount", txtAmount.Text);
SaveCmd.ExecuteNonQuery();
Data.con.Close();
LoadData();
MetroMessageBox.Show(this, "User Entry Saved!", "Saved!", MessageBoxButtons.OK, MessageBoxIcon.Information);
clear();
}
else if (dr == DialogResult.No)
{
clear();
}
}
tapos eto po yung code ko sa usercheck() method
Code:
string constring = "server=localhost;port=3306;username=root;password=root";
string Query = "Select * from dbinfo.tbluser where UserName=@UserName";
MySqlConnection con = new MySqlConnection(constring);
MySqlCommand Check = new MySqlCommand(Query, con);
Check.Parameters.AddWithValue("@UserName", this.txtName.Text);
con.Open();
MySqlDataReader dr = Check.ExecuteReader();
while (dr.Read())
{
if (dr.HasRows)
{
MetroMessageBox.Show(this, "The User Name " + dr[1].ToString() + " Already exist!","Existing User", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtName.Clear();
break;
}
else
{
txtCheck.Visible = false;
}
}
Pano po aayusin to mga master? thank you po