public void loadData() { string wanted_path = ""; ReportParameter[] rp = new ReportParameter[4]; ReportDataSource rds = new ReportDataSource(); ReportDataSource rds1 = new ReportDataSource(); PleaseWait pb = new PleaseWait(); BackgroundWorker bwConn = new BackgroundWorker(); bwConn.DoWork += (sender, e) => { MySqlConnection cn = new MySqlConnection(); cn.ConnectionString = DbConnect.conString; cn.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT Name,ContactNo,Date,Address,Age,AdharCard,Remark,CenterType,CenterName,CreatedBy,CreatedAt,Flag FROM PatientsRemark WHERE (CenterType='" + DailyReports.centerType + "' and CenterName='" + DailyReports.centerName + "') and (Flag=1 and Date=@date)"; cmd.Parameters.AddWithValue("@date", DateTime.Parse(DateTime.Now.ToShortDateString()).ToString("yyyy-MM-dd")); cmd.Connection = cn; MySqlDataAdapter da = new MySqlDataAdapter(cmd); DataTable table1 = new DataTable("Patients"); da.Fill(table1); DataSet ds = new DataSet(); ds.Tables.Add(table1); rds.Name = "DataSet1"; rds.Value = table1; MySqlCommand cmd1 = new MySqlCommand(); cmd1.Connection = cn; cmd1.CommandType = CommandType.Text; cmd1.CommandText = "SELECT Name,ContactNo,Date,Address,Age,AdharCard,Remark,CenterType,CenterName,CreatedBy,CreatedAt,Flag FROM PatientsRemark WHERE (CenterType='" + DailyReports.centerType + "' and CenterName='" + DailyReports.centerName + "') and (Flag=0 and Date=@date)"; cmd1.Parameters.AddWithValue("@date", DateTime.Parse(DateTime.Now.ToShortDateString()).ToString("yyyy-MM-dd")); MySqlDataAdapter da1 = new MySqlDataAdapter(cmd1); DataTable table2 = new DataTable("Discharged"); da1.Fill(table2); DataSet ds1 = new DataSet(); ds1.Tables.Add(table2); rds1.Name = "DataSet2"; rds1.Value = table2; var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var subFolderPath = Path.Combine(path, "OCC Reports"); if (!System.IO.Directory.Exists(subFolderPath)) { System.IO.Directory.CreateDirectory(subFolderPath); } var cur_folder = DateTime.Now.ToString("dd-MM-yyyy"); subFolderPath = subFolderPath + "//" + cur_folder; if (!System.IO.Directory.Exists(subFolderPath)) { System.IO.Directory.CreateDirectory(subFolderPath); } wanted_path = subFolderPath; rp[0] = new ReportParameter("Date", DateTime.Now.ToShortDateString()); rp[1] = new ReportParameter("CenterType", DailyReports.centerType); rp[2] = new ReportParameter("CenterName", DailyReports.centerName); rp[3] = new ReportParameter("FilteredBy", "Daily"); }; bwConn.RunWorkerCompleted += (sender, e) => { if (e.Error != null) { MessageBox.Show(e.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } string path = System.IO.Path.GetDirectoryName(Application.ExecutablePath); ReportViewer1.LocalReport.ReportPath = path + "\\Report1.rdlc"; ReportViewer1.LocalReport.SetParameters(rp); ReportViewer1.LocalReport.DataSources.Add(rds); ReportViewer1.LocalReport.DataSources.Add(rds1); ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout); ReportViewer1.LocalReport.Refresh(); pb.Close(); }; bwConn.RunWorkerAsync(); pb.ShowDialog(); }
private void saveDetails() { PleaseWait pb = new PleaseWait(); BackgroundWorker bwConn = new BackgroundWorker(); bwConn.DoWork += (sender, e) => { if (!validation()) { MessageBox.Show("Please fill all fields !!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (status.Equals("ADD NEW")) { DialogResult drs = MessageBox.Show("Are You Sure Do You Want To Add This Patient's Remark ??", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (drs == DialogResult.No) { return; } MySqlConnection cn = new MySqlConnection(); cn.ConnectionString = DbConnect.conString; cn.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = cn; cmd.CommandType = CommandType.Text; string[] address = txtadd.Text.Split(','); int flag = 1; if (txtremark.Text == "Discharged") { flag = 0; string bedname = getBedDetails("SELECT BedName From Patients WHERE Name='" + txtname.Text + "' and ContactNo='" + txtcontact.Text + "'"); string WardCode = getBedDetails("SELECT WardCode From Patients WHERE Name='" + txtname.Text + "' and ContactNo='" + txtcontact.Text + "'"); cmd.CommandText = "UPDATE Beds SET Flag=0 WHERE BedName='" + bedname + "' and WardCode='" + WardCode + "'"; cmd.ExecuteNonQuery(); } cmd.CommandText = "INSERT INTO PatientsRemark (Name,ContactNo,Gender,Address,Age,AdharCard,Date,Remark,CenterType,CenterName,CreatedBy,CreatedAt,Area,District,Flag) VALUES ('" + txtname.Text + "','" + txtcontact.Text + "','" + gender + "','" + txtadd.Text + "'," + txtage.Text + ",'" + txtadhar.Text + "',@date,'" + txtremark.Text + "','" + centerType + "','" + centerName + "','" + created_by + "','" + DateTime.Now.ToString("hh:mm:ss tt") + "','" + address[0] + "','" + address[1] + "'," + flag + ")"; cmd.Parameters.AddWithValue("@date", DateTime.Parse(txtdate.Text).ToString("yyyy-MM-dd")); cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); MessageBox.Show("Patient's Remark Added Successfully !!!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); cn.Close(); } else if (status.Equals("UPDATE")) { MySqlConnection cn = new MySqlConnection(); cn.ConnectionString = DbConnect.conString; cn.Open(); DialogResult drs = MessageBox.Show("Are You Sure Do You Want To Update This Patient's Remark ??", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (drs == DialogResult.No) { return; } MySqlCommand cmd = new MySqlCommand(); cmd.Connection = cn; cmd.CommandType = CommandType.Text; int flag = 1; if (txtremark.Text == "Discharged") { flag = 0; string bedname = getBedDetails("SELECT BedName From Patients WHERE Name='" + txtname.Text + "' and ContactNo='" + txtcontact.Text + "'"); string WardCode = getBedDetails("SELECT WardCode From Patients WHERE Name='" + txtname.Text + "' and ContactNo='" + txtcontact.Text + "'"); cmd.CommandText = "UPDATE Beds SET Flag=0 WHERE BedName='" + bedname + "' and WardCode='" + WardCode + "'"; cmd.ExecuteNonQuery(); } cmd.CommandText = "UPDATE PatientsRemark SET Name='" + txtname.Text + "',ContactNo='" + txtcontact.Text + "',Gender='" + gender + "',Address='" + txtadd.Text + "',Age=" + txtage.Text + ",AdharCard='" + txtadhar.Text + "',Date=@date,Remark='" + txtremark.Text + "',CenterType='" + centerType + "',CenterName='" + centerName + "',CreatedBy='" + created_by + "',CreatedAt='" + DateTime.Now.ToString("hh:mm:ss tt") + "',Flag=" + flag + " WHERE ID=" + lbid.Text; cmd.Parameters.AddWithValue("@date", DateTime.Parse(txtdate.Text).ToString("yyyy-MM-dd")); cmd.ExecuteNonQuery(); MessageBox.Show("Patient's Remark Updated Successfully !!!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); cn.Close(); } }; bwConn.RunWorkerCompleted += (sender, e) => { if (e.Error != null) { MessageBox.Show(e.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } pb.Close(); clearAll(); actionButtonNormalStage(); unlockAll(false); fillgrid(); }; bwConn.RunWorkerAsync(); pb.ShowDialog(); }