bool valid() { if (Sname.Text.Trim() == string.Empty) { Sname.Focus(); Sname.BorderStyle = BorderStyle.Solid; Sname.BorderColor = Color.Red; Sname.ToolTip = "Enter Name"; return(false); } if (Semail.Text.Trim() == string.Empty) { Semail.Focus(); Semail.BorderStyle = BorderStyle.Solid; Semail.BorderColor = Color.Red; Semail.ToolTip = "Enter Email"; return(false); } if (Sdept.Text.Trim() == string.Empty) { Sdept.Focus(); Sdept.BorderStyle = BorderStyle.Solid; Sdept.BorderColor = Color.Red; Sdept.ToolTip = "Enter Department"; return(false); } if (Sclg.Text.Trim() == string.Empty) { Sclg.Focus(); Sclg.BorderStyle = BorderStyle.Solid; Sclg.BorderColor = Color.Red; Sclg.ToolTip = "Enter College"; return(false); } if (Spass.Text.Trim() == string.Empty) { Spass.Focus(); Spass.BorderStyle = BorderStyle.Solid; Spass.BorderColor = Color.Red; Spass.ToolTip = "Enter Password"; return(false); } if (Scpass.Text.Trim() != Spass.Text) { Scpass.Focus(); Scpass.BorderStyle = BorderStyle.Solid; Scpass.BorderColor = Color.Red; Scpass.ToolTip = "Password Not Matched"; return(false); } return(true); }
private void button2_Click_1(object sender, EventArgs e) { if (Rname.Text == "") { MessageBox.Show("PLESS FILL THE RESSOURS NAME FILED"); Rname.Focus(); } else if (Sname.Text == "") { MessageBox.Show("PLESS FILL THE STONE NAME FILED"); Sname.Focus(); } else if (Ssize.Text == "") { MessageBox.Show("PLESS FILL THE STONE SIZE FILED"); Ssize.Focus(); } else if (stoneTotalPieces.Text == "") { MessageBox.Show("PLESS FILL THE STONE WEIGHT FILED"); stoneTotalPieces.Focus(); } else if (stoneTotalWeight.Text == "") { MessageBox.Show("PLESS FILL THE TOTAL STONES WEIGHT FILED"); stoneTotalWeight.Focus(); } else if (stone_weight_per_one.Text == "") { MessageBox.Show("PLESS FILL THE STONE PRISE FILED"); stone_weight_per_one.Focus(); } if (Rname.Text != "" && Sname.Text != "" && Ssize.Text != "" && stoneTotalPieces.Text != "" && stoneTotalWeight.Text != "" && stone_weight_per_one.Text != "") { try { SqlConnection conn = new SqlConnection(@" Data Source=HP-PC;Initial Catalog=Stones;User ID=sa;Password=123aA123;Integrated Security=True"); conn.Open(); string insert_query = "insert into enter (date,resource_name,stone_name,stone_size,stone_weight,stone_total_pieces,stone_total_weight,stone_prise) values (@date,@resource_name,@stone_name,@stone_size,@stone_weight,@stone_total_pieces,@stone_total_weight,@stone_prise)"; SqlCommand cmd = new SqlCommand(insert_query, conn); cmd.Parameters.AddWithValue("@date", this.date.Text); cmd.Parameters.AddWithValue("@resource_name", Rname.Text); cmd.Parameters.AddWithValue("@stone_name", Sname.Text); cmd.Parameters.AddWithValue("@stone_size", Ssize.Text); cmd.Parameters.AddWithValue("@stone_weight", stone_weight_per_one.Text); cmd.Parameters.AddWithValue("@stone_total_pieces", stoneTotalPieces.Text); cmd.Parameters.AddWithValue("@stone_total_weight", stoneTotalWeight.Text); cmd.Parameters.AddWithValue("@stone_prise", Sprise.Text); cmd.ExecuteNonQuery(); // MessageBox.Show("STONE RECORD ENTERED"); insert_quantity(); // FOR DISPLAY IN THE DATAGRIDE VIEW SqlDataAdapter da = new SqlDataAdapter("select * from enter", conn); SqlCommandBuilder cm = new SqlCommandBuilder(da); DataSet ds = new DataSet(); da.Fill(ds, "enter"); if (ds.Tables["enter"].Rows.Count > 0) { displayInsert.DataSource = ds.Tables["enter"]; } else { MessageBox.Show("No Deitels"); } conn.Close(); Rname.Clear(); Sname.Clear(); Ssize.Clear(); stone_weight_per_one.Clear(); stoneTotalPieces.Clear(); stoneTotalWeight.Clear(); Sprise.Clear(); } catch (Exception ex) { MessageBox.Show("ERORR:" + ex.ToString()); } } }