Ejemplo n.º 1
0
 private void ButtonPreview_Click(object sender, EventArgs e)
 {
     ReportViewer1.SetDisplayMode(ButtonPreview.Checked ? DisplayMode.Normal : DisplayMode.PrintLayout);
 }
Ejemplo n.º 2
0
 private void Frm_Imp_Log_Load(object sender, EventArgs e)
 {
     ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
     ReportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth;
     ReportViewer1.RefreshReport();
 }
Ejemplo n.º 3
0
        private void loadData()
        {
            string wanted_path = "";

            ReportParameter[] rp     = new ReportParameter[4];
            ReportDataSource  rds    = 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 = query;
                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;
                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", centerType);
                rp[2]       = new ReportParameter("centerName", centerName);
                rp[3]       = new ReportParameter("FilteredBy", filterBy);
                ReportViewer1.LocalReport.DataSources.Clear();
            };
            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 + "//Report2.rdlc";
                ReportViewer1.LocalReport.SetParameters(rp);
                ReportViewer1.LocalReport.DataSources.Add(rds);
                ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
                ReportViewer1.LocalReport.Refresh();
                Warning[] warnings;
                string[]  streamids;
                string    mimeType;
                string    encoding;
                string    filenameExtension;

                byte[] bytes = ReportViewer1.LocalReport.Render(
                    "PDF", null, out mimeType, out encoding, out filenameExtension,
                    out streamids, out warnings);
                string filename = @wanted_path + "//" + DateTime.Now.ToString("hh-mm-ss") + ".pdf";
                using (FileStream fs = new FileStream(filename, FileMode.Create))
                {
                    fs.Write(bytes, 0, bytes.Length);
                }
                System.Diagnostics.Process.Start(filename);
                pb.Close();
            };
            bwConn.RunWorkerAsync();
            pb.ShowDialog();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="startIndex"></param>
        /// <returns></returns>
        private void Print()
        {
            try
            {
                var item = PrintData.Data[Index];

                m_currentPageIndex = 0;
                m_streams          = null;

                PageSettings ps = Config.GetPageSettings();
                ReportViewer1.SetPageSettings(ps);
                ReportViewer1.LocalReport.ReportPath = Config.TemplateLocation(PrintData.PrintTemplate.FileName);

                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource(PrintData.PrintTemplate.DataSetName, item.ToDataTable()));
                var printParams = PrintData.PrintTemplate.PrintParams;
                if (printParams.Count > 0)
                {
                    int j = 0;
                    foreach (var parameter in ReportViewer1.LocalReport.GetParameters())
                    {
                        var    db_param = PrintData.PrintTemplate.PrintParams.Find(p => p.PrintParamName == parameter.Name);
                        string fileName = $"{PrintData.PrintTemplate.PrintTemplateID}_{db_param.Value}{Index}{j++}";

                        switch (db_param.ParamType)
                        {
                        case ParamType.BarCode:
                            //创建条形码文件
                            fileName += "1D";
                            string value = CanCreateCode(db_param, item, out bool isCreate);

                            if (isCreate == false)
                            {
                                Message = $"值({value})不能生成条形码";
                                return;
                            }

                            PrintReport.CreateBarCode(value, fileName, Config.TempleAddress);
                            break;

                        case ParamType.QRCode:
                            //创建二维码
                            fileName += "2D";
                            value     = CanCreateCode(db_param, item, out isCreate);

                            if (isCreate == false)
                            {
                                Message = $"值({value})不能生成条形码";
                            }
                            PrintReport.CreateQRCode(value, fileName, Config.TempleAddress);
                            break;

                        case ParamType.Other:

                            ReportViewer1.LocalReport.SetParameters(new ReportParameter
                                                                        (parameter.Name, Convert.ToString(item[db_param.Value])));
                            continue;

                        case ParamType.SQL:
                            value = "0";
                            if (item.ContainsKey(db_param.Value))
                            {
                                value = Convert.ToString(item[db_param.Value]);
                            }
                            ReportViewer1.LocalReport.SetParameters(new ReportParameter
                                                                        (parameter.Name, value));
                            continue;
                        }
                        var file = Path.Combine(Config.TempleAddress, fileName + ".bmp");
                        ReportViewer1.LocalReport.SetParameters(new ReportParameter(parameter.Name, "file://" + file));
                    }

                    ReportViewer1.SetDisplayMode(DisplayMode.PrintLayout);

                    ReportViewer1.ZoomMode    = ZoomMode.Percent;
                    ReportViewer1.ZoomPercent = 100;
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
            }
        }
Ejemplo n.º 5
0
        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();
        }