private void Login_Button_Click(object sender, EventArgs e) { MainClass mc = new MainClass(); mc.OpenConnection(); mc.AppLogin(UserNameTBox.Text, PasswordTBox.Text); try { if (MainClass.Flag == 1) { new SignIn().Show(); mc.CloseConnection(); MainClass.Flag = 0; this.Hide(); } else if (MainClass.Flag == 2) { new LoginChange().Show(); mc.CloseConnection(); MainClass.Flag = 0; this.Hide(); } else if (MainClass.Flag == 0) { mc.CloseConnection(); MessageBox.Show("Please Check Your Login Details !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { mc.CloseConnection(); MessageBox.Show(ex.Message); } }
private void SaveButton_Click(object sender, EventArgs e) { MainClass mc = new MainClass(); mc.OpenConnection(); try { if (UserNameCheckBox.Checked && PasswordCheckBox.Checked) { MainClass.Flag = 1; mc.UpdateLoginDetails(UserNameBox.Text, PasswordBox.Text); } else if (UserNameCheckBox.Checked) { MainClass.Flag = 2; mc.UpdateLoginDetails(UserNameBox.Text, PasswordBox.Text = null); } else if (PasswordCheckBox.Checked) { MainClass.Flag = 3; mc.UpdateLoginDetails(UserNameBox.Text = null, PasswordBox.Text); } if (MainClass.Flag == 4) { MessageBox.Show("UserName And Password Updated Successfully!", "Updated", MessageBoxButtons.OK, MessageBoxIcon.Information); mc.CloseConnection(); new LoginForm().Show(); MainClass.Flag = 0; this.Hide(); } else if (MainClass.Flag == 5) { MessageBox.Show("UserName Updated Successfully!", "Updated", MessageBoxButtons.OK, MessageBoxIcon.Information); mc.CloseConnection(); new LoginForm().Show(); MainClass.Flag = 0; this.Hide(); } else if (MainClass.Flag == 6) { MessageBox.Show("Password Updated Successfully!", "Updated", MessageBoxButtons.OK, MessageBoxIcon.Information); mc.CloseConnection(); new LoginForm().Show(); MainClass.Flag = 0; this.Hide(); } } catch (Exception ex) { mc.CloseConnection(); MessageBox.Show(ex.Message); } }
//Search Button private void SearchButton_Click(object sender, EventArgs e) { { MainClass mc = new MainClass(); mc.OpenConnection(); try { if (JewelleryTypeList.SelectedItem != null && MaterialList.SelectedItem != null && ItemBox.Text != "") { MessageBox.Show("Please Select Only Two Fields At Once!"); } else if (JewelleryTypeList.SelectedItem != null && MaterialList.SelectedItem != null && ItemBox.Text == "") { mc.SqlQuery("Select * From Product." + JewelleryTypeList.SelectedItem + " where Material = '" + MaterialList.SelectedItem + "'"); SqlDataReader sdr = mc.DbCommand.ExecuteReader(); while (sdr.Read()) { MainClass.item.Add(Convert.ToInt32(sdr[0].ToString())); MainClass.quantity.Add(Convert.ToInt32(sdr[1].ToString())); MainClass.type.Add(sdr[2].ToString()); MainClass.material.Add(sdr[3].ToString()); MainClass.weight.Add(Convert.ToDecimal(sdr[4].ToString())); MainClass.colour.Add(sdr[5].ToString()); MainClass.size.Add(Convert.ToDecimal(sdr[6].ToString())); MainClass.price.Add(Convert.ToDecimal(sdr[8].ToString())); MainClass.Img = (byte[])(sdr[7]); MainClass.Images.Add(MainClass.Img); ++MainClass.Flag; } MainClass.checkForPOS = 1; this.Hide(); mc.CloseConnection(); sdr.Close(); } else if (JewelleryTypeList.SelectedItem != null && ItemBox.Text != null) { try { mc.SqlQuery("Select * From Product." + JewelleryTypeList.SelectedItem + " where Item# = " + ItemBox.Text + ""); SqlDataReader sr = mc.DbCommand.ExecuteReader(); sr.Read(); if (sr.HasRows) { MainClass.Item = Convert.ToInt32(sr[0].ToString()); MainClass.Quantity = Convert.ToInt32(sr[1].ToString()); MainClass.Type = sr[2].ToString(); MainClass.Material = sr[3].ToString(); MainClass.Weight = Convert.ToDecimal(sr[4].ToString()); MainClass.Colour = sr[5].ToString(); MainClass.Size = Convert.ToDecimal(sr[6].ToString()); MainClass.Img = (byte[])(sr[7]); MainClass.Price = Convert.ToDecimal(sr[8].ToString()); MainClass.Flag = 1; mc.CloseConnection(); sr.Close(); this.Close(); } else { mc.CloseConnection(); MessageBox.Show("This item does not exit", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception exp) { MessageBox.Show(exp.Message); } } else { MessageBox.Show("Please insert data to search!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); mc.CloseConnection(); } } catch (Exception exp) { mc.CloseConnection(); MessageBox.Show(exp.Message); } } }