コード例 #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string       id = dgvResult.Rows[dgvResult.CurrentCell.RowIndex].Cells[0].Value.ToString();
            DialogResult dr = new DialogResult();

            dr = MessageBox.Show("Do you really want to delete a record, ID = " + id + " ?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if ((int)dr == 6)
            {
                if (frmRemax.formToManage == "house")
                {
                    if (frmLogin.admin != null)
                    {
                        frmLogin.admin.Houses = Remax.TabHouses();
                        frmLogin.admin.DeleteHouse(id);
                        HouseDB.UpdateHousesDB(frmLogin.admin.Houses);
                    }

                    if (frmLogin.agent != null)
                    {
                        house = HouseDB.getHouse(id);
                        if (house.IdAgent != frmLogin.agent.Id)
                        {
                            MessageBox.Show("The house added by another agent.You can not delete.");
                        }
                        else
                        {
                            frmLogin.agent.Houses = Remax.TabHouses();
                            frmLogin.agent.DeleteHouse(id);
                            HouseDB.UpdateHousesDB(frmLogin.agent.Houses);
                        }
                    }
                }
                else if (frmRemax.formToManage == "client")
                {
                    if (frmLogin.admin != null)
                    {
                        frmLogin.admin.Clients = Remax.TabClients();
                        frmLogin.admin.DeleteClient(id);
                        ClientDB.UpdateClientsDB(frmLogin.admin.Clients);
                    }
                    else
                    {
                        frmLogin.agent.Clients = Remax.TabClients();
                        frmLogin.agent.DeleteClient(id);
                        ClientDB.UpdateClientsDB(frmLogin.agent.Clients);
                    }
                }
                else if (frmRemax.formToManage == "employee")
                {
                    frmLogin.admin.Employees = Remax.TabEmployees();
                    frmLogin.admin.Languages = Remax.TabLanguages();
                    frmLogin.admin.DeleteEmployee(id);
                    EmployeeDB.UpdateEmployeesDB(frmLogin.admin.Employees, frmLogin.admin.Languages);
                }
            }
        }
コード例 #2
0
        private void btnHSave_Click(object sender, EventArgs e)
        {
            House house = new House();

            house.BuildingType    = cboHBuilding.SelectedValue.ToString();
            house.NumberParking   = cboHParking.SelectedValue.ToString();
            house.NumberBedrooms  = cboHBedrooms.SelectedValue.ToString();
            house.PropertyType    = cboHProperty.SelectedValue.ToString();
            house.Price           = float.Parse(txtHPrice.Text);
            house.IdAgent         = (frmLogin.agent != null) ? frmLogin.agent.Id : cboHAgent.SelectedValue.ToString();
            house.IdSeller        = cboHClient.SelectedValue.ToString();
            house.Pool            = (checkBoxPool.Checked) ? true : false;
            house.Waterfront      = (checkBoxWater.Checked) ? true : false;
            house.Elevator        = (checkBoxElevator.Checked) ? true : false;
            house.AdapterMobility = (checkBoxMobility.Checked) ? true : false;
            house.NetArea         = int.Parse(txtHNetArea.Text);
            house.YearBuilt       = int.Parse(txtYear.Text);
            house.Description     = txtHDesc.Text;
            house.Name            = txtHName.Text;
            house.Address         = txtHAddress.Text;

            if (frmManage.mode == "add" && frmLogin.admin != null)
            {
                frmLogin.admin.Houses = Remax.TabHouses();
                frmLogin.admin.AddHouse(house);
                HouseDB.UpdateHousesDB(frmLogin.admin.Houses);
            }

            if (frmManage.mode == "add" && frmLogin.agent != null)
            {
                frmLogin.agent.Houses = Remax.TabHouses();
                frmLogin.agent.AddHouse(house);
                HouseDB.UpdateHousesDB(frmLogin.agent.Houses);
            }

            if (frmManage.mode == "edit" && frmLogin.admin != null)
            {
                house.Id = frmManage.house.Id;
                frmLogin.admin.Houses = Remax.TabHouses();
                frmLogin.admin.EditHouse(house);
                HouseDB.UpdateHousesDB(frmLogin.admin.Houses);
            }

            if (frmManage.mode == "edit" && frmLogin.agent != null)
            {
                house.Id = frmManage.house.Id;
                frmLogin.agent.Houses = Remax.TabHouses();
                frmLogin.agent.EditHouse(house);
                HouseDB.UpdateHousesDB(frmLogin.agent.Houses);
            }


            this.Close();
        }