private void frmHouse_Load(object sender, EventArgs e) { txtHName.Focus(); if (frmLogin.admin != null) { DataTable dt = Remax.ViewClients(); DataView dv = dt.DefaultView; dv.RowFilter = " Role='Seller' "; cboHClient.DataSource = dv; } else { DataTable dt = Remax.ViewClients(); DataView dv = dt.DefaultView; dv.RowFilter = "Agent = '" + frmLogin.agent.Name + "' AND Role='Seller'"; cboHClient.DataSource = dv; } cboHClient.DisplayMember = "Name"; cboHClient.ValueMember = "Id"; if (frmLogin.admin != null) { cboHAgent.DataSource = Remax.ViewEmployees(); cboHAgent.DisplayMember = "Name"; cboHAgent.ValueMember = "Id"; } else { cboHAgent.Visible = false; lblHAgent.Visible = false; } cboHBuilding.DataSource = Remax.TabBuilding(); cboHBuilding.ValueMember = "refBuildingType"; cboHBuilding.DisplayMember = "BuildingType"; cboHProperty.DataSource = Remax.TabProperty(); cboHProperty.ValueMember = "refPropertyType"; cboHProperty.DisplayMember = "propertyType"; cboHParking.DataSource = Remax.TabParking(); cboHParking.DisplayMember = "NumParking"; cboHParking.ValueMember = "refNumParking"; cboHBedrooms.DataSource = Remax.TabBedrooms(); cboHBedrooms.DisplayMember = "NumBedrooms"; cboHBedrooms.ValueMember = "refNumBedrooms"; if (frmManage.mode == "edit") { house = frmManage.house; txtHName.Text = house.Name; txtHPrice.Text = house.Price.ToString(); txtHNetArea.Text = house.NetArea.ToString(); txtYear.Text = house.YearBuilt.ToString(); checkBoxElevator.Checked = house.Elevator; checkBoxMobility.Checked = house.AdapterMobility; checkBoxPool.Checked = house.Pool; checkBoxWater.Checked = house.Waterfront; foreach (DataRow row in Remax.ViewEmployees()) { if (row["Id"].ToString() == house.IdAgent) { cboHAgent.Text = row["Name"].ToString(); } } foreach (DataRow row in Remax.ViewClients()) { if (row["Id"].ToString() == house.IdSeller) { cboHClient.Text = row["Name"].ToString(); } } foreach (DataRow row in Remax.TabBuilding()) { if (row["refBuildingType"].ToString() == house.BuildingType) { cboHBuilding.Text = row["BuildingType"].ToString(); } } foreach (DataRow row in Remax.TabProperty()) { if (row["refPropertyType"].ToString() == house.BuildingType) { cboHProperty.Text = row["PropertyType"].ToString(); } } foreach (DataRow row in Remax.TabParking()) { if (row["refNumParking"].ToString() == house.BuildingType) { cboHParking.Text = row["NumParking"].ToString(); } } foreach (DataRow row in Remax.TabBedrooms()) { if (row["refNumBedrooms"].ToString() == house.BuildingType) { cboHBedrooms.Text = row["NumBedrooms"].ToString(); } } txtHDesc.Text = house.Description; txtHAddress.Text = house.Address; } }
private void btnSearch_Click(object sender, EventArgs e) { if (checkBoxID.Checked) { if (txtSearch.Text == "") { MessageBox.Show("Enter a criteria"); } else { string criteria = txtSearch.Text; if (frmRemax.formToManage == "house") { if (frmLogin.admin != null) { DataView dv = HouseDB.getViewHouses("admin"); dv.RowFilter = "CONVERT(Id, System.String) LIKE '%" + criteria + "%'"; dgvResult.DataSource = dv; } else { DataView dv = HouseDB.getViewHouses("user or agent"); dv.RowFilter = "CONVERT(Id, System.String) LIKE '%" + criteria + "%'"; dgvResult.DataSource = dv; } } if (frmRemax.formToManage == "client") { if (frmLogin.agent == null) { DataView dv = ClientDB.getViewClients(""); dv.RowFilter = "CONVERT(Id, System.String) LIKE '%" + criteria + "%'"; dgvResult.DataSource = dv; } else { DataView dv = ClientDB.getViewClients(frmLogin.agent.Name); dv.RowFilter = " CONVERT(Id, System.String) LIKE '%" + criteria + "%'"; dgvResult.DataSource = dv; } } if (frmRemax.formToManage == "employee") { DataView dv = EmployeeDB.getViewEmployees(""); dv.RowFilter = "CONVERT(Id, System.String) LIKE '%" + criteria + "%'"; dgvResult.DataSource = dv; } if (frmRemax.formToManage == "agent") { DataView dv = EmployeeDB.getViewEmployees("agent"); dv.RowFilter = "CONVERT(Id, System.String) LIKE '%" + criteria + "%'"; dgvResult.DataSource = dv; } } } if (checkBoxName.Checked) { if (txtSearch.Text == "") { MessageBox.Show("Enter a criteria"); } else { string criteria = txtSearch.Text; if (frmRemax.formToManage == "house") { if (frmLogin.employee == null) { DataTable dt = Remax.ViewHouses("user"); DataView dv = dt.DefaultView; dv.RowFilter = "Name LIKE '%" + criteria + "%'"; dgvResult.DataSource = dv; } else { DataTable dt = Remax.ViewHouses(); DataView dv = dt.DefaultView; dv.RowFilter = "Name LIKE '%" + criteria + "%'"; dgvResult.DataSource = dv; } } if (frmRemax.formToManage == "client") { if (frmLogin.agent != null) { DataView dv = Remax.ViewClients(frmLogin.agent.Name); dv.RowFilter = "Name LIKE '%" + criteria + "%'"; dgvResult.DataSource = dv; } else { DataTable dt = Remax.ViewClients(); DataView dv = dt.DefaultView; dv.RowFilter = "Name LIKE '%" + criteria + "%'"; dgvResult.DataSource = dv; } } if (frmRemax.formToManage == "employee") { DataTable dt = Remax.ViewEmployees(); DataView dv = dt.DefaultView; dv.RowFilter = "Name LIKE '%" + criteria + "%'"; dgvResult.DataSource = dv; } if (frmRemax.formToManage == "agent") { DataTable dt = Remax.TabAgents(); DataView dv = dt.DefaultView; dv.RowFilter = "Name LIKE '%" + criteria + "%'"; dgvResult.DataSource = dv; } } } if (!checkBoxName.Checked && !checkBoxID.Checked) { MessageBox.Show("Check type of search."); } }