///////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
//using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Apartment_Management
{
public partial class Unit_2 : Form
{
public Unit_2()
{
InitializeComponent();
}
private void comboBox_property_name()
{
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\AMS_2007.accdb");
OleDbDataAdapter da = new OleDbDataAdapter("SELECT Property.Property_Name, Property.Property_ID, Property.Property_Phone, Property.Property_Manager FROM Property", con);
con.Open();
DataSet dt = new DataSet();
da.Fill(dt, "Property_Name");
comboBox_Name_2.DataSource = dt.Tables["Property_Name"];
comboBox_Name_2.DisplayMember = "Property_Name";
comboBox_Name_2.ValueMember = "Property_ID";
con.Close();
}
private void display_datagrid()
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["Apartment_Management.Properties.Settings.AMS_2007ConnectionString"].ToString();
con.Open();
MessageBox.Show("Connection Sucess");
OleDbCommand cmd = new OleDbCommand();
if (comboBox_Name_2.Text == "Select All Properties")
cmd.CommandText = "SELECT DISTINCTROW Unit.Property_Name, Unit.Unit_Number, Unit.Bedroom, " +
"Unit.Rental_Cost, Unit.Security_Deposit, Unit.Bathroom, Unit.Square_Feet, " +
"Unit.Status, Tenant.Date_Lease_Expired, Tenant.Late_On_Payment, " +
"Tenant.Days_Delinquent FROM Unit LEFT JOIN " +
"Tenant ON(Unit.Unit_Number = Tenant.Unit_Number) " +
"AND(Unit.Property_Name = Tenant.Property_Name) " +
"ORDER BY Unit.Property_Name, Unit.Unit_Number, Unit.Bedroom, Unit.Rental_Cost";
else
{
MessageBox.Show("else condition");
cmd.CommandText = "SELECT DISTINCTROW Unit.Property_Name, Unit.Unit_Number, Unit.Bedroom, " +
"Unit.Rental_Cost, Unit.Security_Deposit, Unit.Bathroom, Unit.Square_Feet, " +
"Unit.Status, Tenant.Date_Lease_Expired, Tenant.Late_On_Payment, " +
"Tenant.Days_Delinquent FROM Unit LEFT JOIN " +
"Tenant ON(Unit.Unit_Number = Tenant.Unit_Number) " +
"AND(Unit.Property_Name = Tenant.Property_Name) " +
"WHERE Unit.Property_Name = '" + comboBox_Name_2.Text + "'" +
"ORDER BY Unit.Property_Name, Unit.Unit_Number, Unit.Bedroom, Unit.Rental_Cost";
}
cmd.Connection = con;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView2.DataSource = ds.Tables[0];
}
private void Unit_2_Load(Object Sender, EventArgs e)
{
comboBox_property_name();
display_datagrid();
}
private void comboBox_Name_2_SelectedIndexChanged(Object Sender, EventArgs e)
{
display_datagrid();
}
}
}