Example #1
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 1)
            {
                ByCenter ob = new ByCenter();
                ob.ShowDialog();
                string   query   = ob.getQuery();
                string[] centers = query.Split(':');
                if (centers[0] == "--CENTER TYPE--" || centers[1] == "--CENTER NAME--")
                {
                    MessageBox.Show("Wrong parameter to search !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                MySqlConnection cn = new MySqlConnection();
                cn.ConnectionString = DbConnect.conString;
                cn.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = cn;
                cmd.CommandText = "Select Name,ContactNo,AdharCard,Date,Remark,CenterType,CenterName From Patients WHERE (CenterType='" + Search.centerType + "' and CenterName='" + Search.centerName + "') and (CenterType='" + centers[0] + "' and CenterName='" + centers[1] + "')";
                MySqlDataAdapter da     = new MySqlDataAdapter(cmd);
                DataTable        table1 = new DataTable("Patients");
                da.Fill(table1);
                cmd.CommandText = "Select AdharCard,Address,Date,Remark,CenterType,CenterName From PatientsRemark WHERE (CenterType='" + Search.centerType + "' and CenterName='" + Search.centerName + "')";
                DataTable table2 = new DataTable("Remarks");
                da.Fill(table2);
                DataSet ds = new DataSet();
                ds.Tables.Add(table1);
                ds.Tables.Add(table2);
                DataRelation Datatablerelation = new DataRelation("Remark Details", ds.Tables[0].Columns[2], ds.Tables[1].Columns[0], false);
                ds.Relations.Add(Datatablerelation);
                dataGrid1.DataSource = ds.Tables[0];
                cn.Close();
            }
            if (comboBox1.SelectedIndex == 2)
            {
                ByName ob = new ByName();
                ob.ShowDialog();
                string name = ob.getQuery();
                if (name == "")
                {
                    MessageBox.Show("Wrong parameter to search !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                MySqlConnection cn = new MySqlConnection();
                cn.ConnectionString = DbConnect.conString;
                cn.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = cn;
                cmd.CommandText = "Select Name,ContactNo,AdharCard,Date,Remark,CenterType,CenterName From Patients WHERE (CenterType='" + Search.centerType + "' and CenterName='" + Search.centerName + "') and (Name LIKE '%" + name + "%')";
                MySqlDataAdapter da     = new MySqlDataAdapter(cmd);
                DataTable        table1 = new DataTable("Patients");
                da.Fill(table1);
                cmd.CommandText = "Select AdharCard,Address,Date,Remark,CenterType,CenterName From PatientsRemark WHERE CreatedBy='" + created_by + "'";
                DataTable table2 = new DataTable("Remarks");
                da.Fill(table2);
                DataSet ds = new DataSet();
                ds.Tables.Add(table1);
                ds.Tables.Add(table2);
                DataRelation Datatablerelation = new DataRelation("Remark Details", ds.Tables[0].Columns[2], ds.Tables[1].Columns[0], false);
                ds.Relations.Add(Datatablerelation);
                dataGrid1.DataSource = ds.Tables[0];
                cn.Close();
            }
            if (comboBox1.SelectedIndex == 3)
            {
                ByGender ob = new ByGender();
                ob.ShowDialog();
                string gender = ob.getQuery();
                if (gender == "")
                {
                    MessageBox.Show("Please select gender to search !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                MySqlConnection cn = new MySqlConnection();
                cn.ConnectionString = DbConnect.conString;
                cn.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = cn;
                cmd.CommandText = "Select Name,ContactNo,AdharCard,Date,Remark,CenterType,CenterName From Patients WHERE (CenterType='" + Search.centerType + "' and CenterName='" + Search.centerName + "') and (Gender='" + gender + "')";
                MySqlDataAdapter da     = new MySqlDataAdapter(cmd);
                DataTable        table1 = new DataTable("Patients");
                da.Fill(table1);
                cmd.CommandText = "Select AdharCard,Address,Date,Remark,CenterType,CenterName From PatientsRemark WHERE CreatedBy='" + created_by + "'";
                DataTable table2 = new DataTable("Remarks");
                da.Fill(table2);
                DataSet ds = new DataSet();
                ds.Tables.Add(table1);
                ds.Tables.Add(table2);
                DataRelation Datatablerelation = new DataRelation("Remark Details", ds.Tables[0].Columns[2], ds.Tables[1].Columns[0], false);
                ds.Relations.Add(Datatablerelation);
                dataGrid1.DataSource = ds.Tables[0];
                cn.Close();
            }
            if (comboBox1.SelectedIndex == 4)
            {
                ByDate ob = new ByDate();
                ob.ShowDialog();
                string          query = ob.getQuery();
                string[]        dates = query.Split(':');
                MySqlConnection cn    = new MySqlConnection();
                cn.ConnectionString = DbConnect.conString;
                cn.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = cn;
                cmd.CommandText = "Select Name,ContactNo,AdharCard,Date,Remark,CenterType,CenterName From Patients WHERE (CenterType='" + Search.centerType + "' and CenterName='" + Search.centerName + "') and (Date BETWEEN @date1 and @date2)";
                cmd.Parameters.AddWithValue("@date1", DateTime.Parse(dates[0]).ToString("yyyy-MM-dd"));
                cmd.Parameters.AddWithValue("@date2", DateTime.Parse(dates[1]).ToString("yyyy-MM-dd"));
                MySqlDataAdapter da     = new MySqlDataAdapter(cmd);
                DataTable        table1 = new DataTable("Patients");
                da.Fill(table1);
                cmd.CommandText = "Select AdharCard,Address,Date,Remark,CenterType,CenterName From PatientsRemark WHERE CreatedBy='" + created_by + "'";

                DataTable table2 = new DataTable("Remarks");
                da.Fill(table2);
                DataSet ds = new DataSet();
                ds.Tables.Add(table1);
                ds.Tables.Add(table2);
                DataRelation Datatablerelation = new DataRelation("Remark Details", ds.Tables[0].Columns[2], ds.Tables[1].Columns[0], false);
                ds.Relations.Add(Datatablerelation);
                dataGrid1.DataSource = ds.Tables[0];
                cn.Close();
            }
            if (comboBox1.SelectedIndex == 5)
            {
                //age
                ByAge ob = new ByAge();
                ob.ShowDialog();
                string query = ob.getQuery();
                if (query == "" || query == ":")
                {
                    MessageBox.Show("Wrong parameters to search !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                string[] ages = query.Split(':');
                if (!ages[0].All(char.IsDigit) || !ages[1].All(char.IsDigit))
                {
                    MessageBox.Show("Wrong parameters to search !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                MySqlConnection cn = new MySqlConnection();
                cn.ConnectionString = DbConnect.conString;
                cn.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = cn;
                cmd.CommandText = "Select Name,ContactNo,AdharCard,Age,Date,Remark,CenterType,CenterName From Patients WHERE (CenterType='" + Search.centerType + "' and CenterName='" + Search.centerName + "') and (Age >=" + ages[0] + " and Age <=" + ages[1] + ")";
                MySqlDataAdapter da     = new MySqlDataAdapter(cmd);
                DataTable        table1 = new DataTable("Patients");
                da.Fill(table1);
                cmd.CommandText = "Select AdharCard,Address,Age,Date,Remark,CenterType,CenterName From PatientsRemark WHERE CreatedBy='" + created_by + "'";
                DataTable table2 = new DataTable("Remarks");
                da.Fill(table2);
                DataSet ds = new DataSet();
                ds.Tables.Add(table1);
                ds.Tables.Add(table2);
                DataRelation Datatablerelation = new DataRelation("Remark Details", ds.Tables[0].Columns[2], ds.Tables[1].Columns[0], false);
                ds.Relations.Add(Datatablerelation);
                dataGrid1.DataSource = ds.Tables[0];
                cn.Close();
            }
        }
Example #2
0
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (comboBox1.SelectedIndex == 1)
     {
         //By Center
         ByCenter ob = new ByCenter();
         ob.ShowDialog();
         string   query   = ob.getQuery();
         string[] centers = query.Split(':');
         if (centers[0] == "--CENTER TYPE--" || centers[1] == "--CENTER NAME--")
         {
             MessageBox.Show("Wrong parameter to search !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         filterBy = "By Center";
         fillgrid("SELECT Name,ContactNo,Date,Address,Age,AdharCard,Remark,CenterType,CenterName,CreatedBy,CreatedAt FROM PatientsRemark WHERE (CenterType='" + centers[0] + "' and CenterName='" + centers[1] + "')");
     }
     if (comboBox1.SelectedIndex == 2)
     {
         //By Name
         ByName ob = new ByName();
         ob.ShowDialog();
         string query = ob.getQuery();
         if (query == "")
         {
             MessageBox.Show("Wrong parameter to search !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         filterBy = "By Name";
         fillgrid("SELECT Name,ContactNo,Date,Address,Age,AdharCard,Remark,CenterType,CenterName,CreatedBy,CreatedAt FROM PatientsRemark WHERE (CenterType='" + AdvanceSearch.centerType + "' and CenterName='" + AdvanceSearch.centerName + "') and (Name LIKE '%" + query + "%')");
     }
     if (comboBox1.SelectedIndex == 3)
     {
         //By Gender
         ByGender ob = new ByGender();
         ob.ShowDialog();
         string gender = ob.getQuery();
         if (gender == "")
         {
             MessageBox.Show("Please select gender to search !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         filterBy = "By Gender";
         fillgrid("SELECT Name,ContactNo,Date,Address,Age,AdharCard,Remark,CenterType,CenterName,CreatedBy,CreatedAt FROM PatientsRemark WHERE (CenterType='" + AdvanceSearch.centerType + "' and CenterName='" + AdvanceSearch.centerName + "') and (Gender='" + gender + "')");
     }
     if (comboBox1.SelectedIndex == 4)
     {
         //By Date
         filterBy = "By Date";
         byDate();
     }
     if (comboBox1.SelectedIndex == 5)
     {
         ByAge ob = new ByAge();
         ob.ShowDialog();
         string query = ob.getQuery();
         if (query == "" || query == ":")
         {
             MessageBox.Show("Wrong parameters to search !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         filterBy = "By Age";
         string[] ages = query.Split(':');
         if (!ages[0].All(char.IsDigit) || !ages[1].All(char.IsDigit))
         {
             MessageBox.Show("Wrong parameters to search !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         fillgrid("SELECT Name,ContactNo,Date,Address,Age,AdharCard,Remark,CenterType,CenterName,CreatedBy,CreatedAt FROM PatientsRemark WHERE (CenterType='" + AdvanceSearch.centerType + "' and CenterName='" + AdvanceSearch.centerName + "') and (Age >=" + ages[0] + " and Age <=" + ages[1] + ")");
     }
     if (comboBox1.SelectedIndex == 6)
     {
         ByAdd ob = new ByAdd();
         ob.ShowDialog();
         string query = ob.getAddress();
         if (query == "" || query == ":")
         {
             MessageBox.Show("Wrong parameters to search !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         filterBy = "By Location";
         string[] address = query.Split(',');
         fillgrid("SELECT Name,ContactNo,Date,Address,Age,AdharCard,Remark,CenterType,CenterName,CreatedBy,Area,District,CreatedAt FROM PatientsRemark WHERE (CenterType='" + AdvanceSearch.centerType + "' and CenterName='" + AdvanceSearch.centerName + "') and (Area ='" + address[0] + "' and District ='" + address[1] + "')");
     }
 }