Пример #1
0
        private void buttonAddR_Click(object sender, EventArgs e)
        {
            string         keyWord = textBoxname.Text;
            SqlConnection  conn    = new SqlConnection(myconnstr);
            SqlDataAdapter sda     = new SqlDataAdapter("Select * from tbl_room where roomName LIKE '%" + keyWord + "%'", conn);
            DataTable      DTs     = new DataTable();

            sda.Fill(DTs);

            Regex regex = new Regex(@"^[0-9]+$");

            if (comboBoxBuildingName.Text == "")
            {
                MessageBox.Show("Please Select Building name !");
            }
            else if (comboBoxFloorNo.Text == "")
            {
                MessageBox.Show("Please Select Floor No !");
            }
            else if (textBoxname.Text == "")
            {
                MessageBox.Show("Room name is required !");
            }
            else if (DTs.Rows.Count != 0)
            {
                MessageBox.Show("Room name is already used, Please use another name !");
            }
            else if (textBoxcapacity.Text == "")
            {
                MessageBox.Show("Capacity are required !");
            }
            else if (!regex.IsMatch(textBoxcapacity.Text))
            {
                MessageBox.Show("Capacity fields must only numeric value!");
            }

            else if (comboBoxType.Text == "")
            {
                MessageBox.Show("Room Type is required !");
            }

            else
            {
                r.BuildingName = comboBoxBuildingName.Text;
                r.RoomName     = textBoxname.Text;
                r.FloorNo      = int.Parse(comboBoxFloorNo.Text);
                r.Capacity     = int.Parse(textBoxcapacity.Text);
                r.Types        = comboBoxType.Text;

                //Insert data into data base using Insert method
                bool success = r.Insert(r);
                if (success == true)
                {
                    MessageBox.Show("New Room Successfully Added");
                    clear();
                }
                else
                {
                    MessageBox.Show("Failed to add Room, Try again!!");
                }
                //Load data on datagrid
                DataTable dt = r.Select();
                dataGridViewRoom.DataSource = dt;
            }
        }