private void tbName_Leave(object sender, EventArgs e) { if (tbName.Text.Trim() == string.Empty) { return; } using (var con = new SqlConnection(ConStr)) { string query = "SELECT ProductID FROM tblStock WHERE Name=@name"; using (var cmd = new SqlCommand(query, con)) { con.Open(); cmd.Parameters.AddWithValue("@name", SqlDbType.NVarChar).Value = tbName.Text.Trim(); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); if (ds.Tables[0].Rows.Count == 0) { tbId.Clear(); id = CreateDBID.CreateID("tblStock", "ProductID"); tbId.Text = id.ToString(); } else { MessageBox.Show("Product Already Exist in stock. Please Review Name or UPDATE QUANTITY of previously available product\nProduct ID is: " + ds.Tables[0].Rows[0][0].ToString(), "Product Already Exist", MessageBoxButtons.OK, MessageBoxIcon.Warning); tbName.Clear(); tbName.Focus(); tbId.Clear(); return; } } } }
private void button1_Click(object sender, EventArgs e) { MessageBox.Show(tbCell.Text.Trim() + "="); if (tbName.Text.Trim() == string.Empty || tbPass.Text.Trim() == string.Empty || tbPass2.Text.Trim() == string.Empty) { MessageBox.Show("Some required fields are not provided. please try again.\nRequired fields: Name, Password & Retype Password.", "Missing fields", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (tbPass.Text.Trim() != tbPass2.Text.Trim()) { MessageBox.Show("Password Miss-match. Check both passwords again", "Password not match", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string encryptedPassword = Encryption.Encrypt(tbPass.Text.Trim(), true); try { MessageBox.Show(tbCell.Text.Trim() + "="); clsCreateSP.insertDetails(id, int.Parse(cbRole.SelectedValue.ToString()), tbName.Text.Trim(), encryptedPassword, tbAddress.Text.Trim(), tbCity.Text.Trim(), tbCell.Text.Trim(), tbNarration.Text.Trim(), DateTimee.Value, int.Parse(cbStatus.SelectedValue.ToString())); MessageBox.Show("New Account Created successfully.", "Account Created", MessageBoxButtons.OK, MessageBoxIcon.Information); id = int.Parse(CreateDBID.CreateID("tblUser", "UserID").ToString()); populateGrid(); tbName.Clear(); MessageBox.Show(tbCell.Text.Trim() + "="); } catch (Exception ex) { MessageBox.Show("Error occurred while creating new user account\nDetails: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } }
private void frmCreateSP_Load(object sender, EventArgs e) { id = int.Parse(CreateDBID.CreateID("tblUser", "UserID").ToString()); cbRole.DataSource = clsCreateSP.fetchRole().Tables[0].DefaultView; cbRole.DisplayMember = "Name"; cbRole.ValueMember = "RoleID"; cbStatus.DataSource = clsCreateSP.fetchRole().Tables[2].DefaultView; cbStatus.DisplayMember = "Name"; cbStatus.ValueMember = "UserStatusID"; populateGrid(); }
private void generateId() { id = CreateDBID.CreateID("tblExpense", "ExpenseID"); }