private void cmbStability_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { TypeOfAssettextBox.Focus(); e.Handled = true; } }
private void TypeOfAssettextBox_Leave(object sender, EventArgs e) { if (!string.IsNullOrEmpty(TypeOfAssettextBox.Text)) { string vendorname = TypeOfAssettextBox.Text.Trim(); Regex mRegxExpression; int Minlen = 3; mRegxExpression = new Regex(@"^[A-Za-z]+[\s][A-Za-z]+[.][A-Za-z]+$"); if ((!mRegxExpression.IsMatch(vendorname)) && (!(TypeOfAssettextBox.Text.Length >= Minlen))) { MessageBox.Show("Please type your valid Asset type.", "MojoCRM", MessageBoxButtons.OK, MessageBoxIcon.Error); TypeOfAssettextBox.Clear(); TypeOfAssettextBox.Focus(); } } }
private void Savebutton_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(cmbStability.Text)) { MessageBox.Show("Please Select Stability", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (TypeOfAssettextBox.Text == "") { MessageBox.Show("Please Enter Type Of Asset!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); TypeOfAssettextBox.Focus(); return; } else { try { con = new SqlConnection(cs.DBConn); con.Open(); string ct = "select T_Name from tblTypeOfAsset where T_Name='" + TypeOfAssettextBox.Text + "'"; cmd = new SqlCommand(ct); cmd.Connection = con; rdr = cmd.ExecuteReader(); if (rdr.Read()) { MessageBox.Show("This Asset Type Already Exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); TypeOfAssettextBox.Text = ""; TypeOfAssettextBox.Focus(); if ((rdr != null)) { rdr.Close(); } return; } con = new SqlConnection(cs.DBConn); con.Open(); cmd = con.CreateCommand(); cmd.CommandText = "SELECT S_Id from tblStability WHERE S_Name= '" + cmbStability.Text + "'"; rdr = cmd.ExecuteReader(); if (rdr.Read()) { s_id = rdr.GetInt32(0); } if ((rdr != null)) { rdr.Close(); } if (con.State == ConnectionState.Open) { con.Close(); } con = new SqlConnection(cs.DBConn); con.Open(); string query = "insert into tblTypeOfAsset(T_Name,S_Id, UserId, DateAndTime) values(@d1,@d2,@d3,@d4)" + "SELECT CONVERT(int,SCOPE_IDENTITY())";; cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@d1", TypeOfAssettextBox.Text); cmd.Parameters.AddWithValue("@d2", s_id); cmd.Parameters.AddWithValue("@d3", user_id); cmd.Parameters.AddWithValue("@d4", DateTime.UtcNow.ToLocalTime()); cmd.ExecuteNonQuery(); MessageBox.Show("Saved Successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbStability.SelectedIndex = -1; TypeOfAssettextBox.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void cmbStability_SelectedIndexChanged(object sender, EventArgs e) { TypeOfAssettextBox.Focus(); }