Пример #1
0
        private void btn_AddNewHouse_Click(object sender, EventArgs e)
        {
            mycon.Open();
            if (clsGLobalVariables.method == "add")
            {
                SqlCommand mycmdHouses = new SqlCommand("INSERT INTO Houses (Bathroom, Bedrooms, Total_rooms, Living_Area, Parking, Built_Date, Price, Address," +
                                                        "Reviews,refEmployee,ClientName,Listing,HouseType)" +
                                                        " VALUES('" + cb_Bathrooms.SelectedItem.ToString() + "','" + cb_Bedrooms.SelectedItem.ToString() + "','" + cb_TotalRooms.SelectedItem.ToString() + "','" + txt_LivingArea.Text + "'," +
                                                        "'" + cb_Parking.SelectedItem.ToString() + "','" + BuildDate.Value.ToString("dd-MMM-yyyy") +
                                                        "','" + txt_Price.Text + "','" + txt_Address.Text + "','" + txtReviews.Text + "','" + cbAgentName.SelectedItem.ToString() + "','" + cb_ClientName.SelectedItem.ToString() +
                                                        "','" + cb_ListingFor.SelectedItem.ToString() + "','" + cb_HouseType.SelectedItem.ToString() + "')", mycon);
                SqlDataAdapter daAddHouses = new SqlDataAdapter(mycmdHouses);
                var            dsHousesAdd = new DataSet();
                daAddHouses.Fill(dsHousesAdd);

                MessageBox.Show("House is Added Successfully!", "Data Added", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            if (clsGLobalVariables.method == "edit")
            {
                try
                {
                    string cmd = "UPDATE Houses SET Bathroom ='" + cb_Bathrooms.SelectedItem.ToString() + "', Total_rooms ='" + cb_TotalRooms.SelectedItem.ToString() +
                                 "', Living_Area ='" + txt_LivingArea.Text + "', Parking ='" + cb_Parking.SelectedItem.ToString() +
                                 "', Address ='" + txt_Address.Text + "', Built_Date = '" + BuildDate.Value.ToString("dd-MMM-yyyy") +
                                 "', Price ='" + txt_Price.Text + "', Reviews = '" + txtReviews.Text +
                                 "', ClientName ='" + cb_ClientName.SelectedItem.ToString() + "', Listing = '" + cb_ListingFor.Text.ToString() + "', HouseType = '" + cb_HouseType.Text.ToString() +
                                 "', Bedrooms ='" + cb_Bedrooms.SelectedItem.ToString() + "', refEmployee ='" + cbAgentName.SelectedItem.ToString() + "' WHERE HouseID = " + Convert.ToInt32(clsGLobalVariables.Id);

                    SqlCommand     mycmdeditHouses = new SqlCommand(cmd, mycon);
                    SqlDataAdapter daeditHouses    = new SqlDataAdapter(mycmdeditHouses);
                    var            dsHousesEdit    = new DataSet();
                    daeditHouses.Fill(dsHousesEdit);

                    MessageBox.Show("House Detail has been Updated!", "Updated", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                mycon.Close();

                this.Close();
                frmHouses houses = new frmHouses();
                houses.Show();
            }
        }
        private void btn_DeleteHouse_Click(object sender, EventArgs e)
        {
            clsGLobalVariables.Id = dataHouses.SelectedRows[0].Cells[0].Value.ToString();

            mycon.Open();
            SqlCommand     mycmddeleteHouses = new SqlCommand("DELETE FROM Houses WHERE HouseID =" + Convert.ToInt32(clsGLobalVariables.Id.ToString()), mycon);
            SqlDataAdapter daHousesdelete    = new SqlDataAdapter(mycmddeleteHouses);
            var            dsHousesdelete    = new DataSet();

            daHousesdelete.Fill(dsHousesdelete);
            mycon.Close();
            this.Close();
            MessageBox.Show("The Houses has been deleted!", "Delete", MessageBoxButtons.OK, MessageBoxIcon.Information);
            frmHouses house = new frmHouses();

            house.Show();
        }
Пример #3
0
        private void viewHousesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmHouses frmHouses = new frmHouses();

            frmHouses.Show();
        }