Exemple #1
0
        private void bPreview_Click(object sender, EventArgs e)
        {
            //System.Data.SqlClient.SqlDataReader SqlReader = null;
            DataTable DT = new DataTable();
            DataRow dr = DT.NewRow();

            string  d1,d2 ;
            DateTime dt1 = DateTime.Parse(dateTimePicker1.Text);
            int Year1 = dt1.Year;
            int Month1 = dt1.Month;
            int day1 = dt1.Day;

            DateTime dt2 = DateTime.Parse(dateTimePicker2.Text);
            int Year2 = dt2.Year;
            int Month2 = dt2.Month;
            int day2 = dt2.Day;

            if (Year1 > 2500)
            {
                d1 = (Year1 - 543).ToString() + "-" + Month1.ToString("00") + "-" + day1.ToString("00");
                d2 = (Year2 - 543).ToString() + "-" + Month2.ToString("00") + "-" + day2.ToString("00");

            }
            else {
                d1 = Year1.ToString() + "-" + Month1.ToString("00") + "-" + day1.ToString("00");
                d2 = Year2.ToString() + "-" + Month2.ToString("00") + "-" + day2.ToString("00");
            }

            string sql = "select h.staff_code as id ,p.first_name +' '+p.last_name name, sum(h.pdf_page) page, ";
            sql += " convert(varchar(10),h.create_on,103) date  ";
            sql += " from scan_history h inner join personal p ";
            sql += " on h.staff_code =p.staff_code  ";
            sql += " where convert(varchar(10),h.create_on,120) between '" + d1 + "' and '" + d2 + "' ";
            sql += " group by h.staff_code, p.first_name, p.last_name, convert(varchar(10),h.create_on,103)";
            sql += " order by h.staff_code";

            Func.Master.ScanHistoryFunc fnc = new Func.Master.ScanHistoryFunc();
            DT = fnc.GetDataBySql(sql);

            if (DT.Rows.Count > 0)
            {
                TableLogOnInfo logonInfo = new TableLogOnInfo();
                logonInfo.ConnectionInfo.DatabaseName = Config.DbGetDbName;
                logonInfo.ConnectionInfo.ServerName = Config.DbGetDataSource;
                logonInfo.ConnectionInfo.UserID = Config.DbGetUserID;
                logonInfo.ConnectionInfo.Password = Config.DbGetPwd;

                SummaryReport rpt = new SummaryReport();
                frmPrintPreview frm = new frmPrintPreview();
                rpt.SetDataSource(DT);
                rpt.Database.Tables[0].ApplyLogOnInfo(logonInfo);
                frm.crystalReportViewer1.ReportSource = rpt;
                frm.StartPosition = FormStartPosition.CenterScreen;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
        }
Exemple #2
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            if (Directory.Exists(txtFolder.Text) == true)
            {
                //DateTime dt1 = DateTime.Parse(dateTimePicker1.Text);
                //DateTime dt2 = DateTime.Parse(dateTimePicker2.Text);

                Config.CreateReportFolder(txtFolder.Text);
                FileFunc fnc = new FileFunc();
                DataTable DT = fnc.GetPDFFileList(txtFolder.Text);

                if (DT.Rows.Count > 0)
                {
                    TableLogOnInfo logonInfo = new TableLogOnInfo();
                    logonInfo.ConnectionInfo.DatabaseName = Config.DbGetDbName;
                    logonInfo.ConnectionInfo.ServerName = Config.DbGetDataSource;
                    logonInfo.ConnectionInfo.UserID = Config.DbGetUserID;
                    logonInfo.ConnectionInfo.Password = Config.DbGetPwd;

                    SummaryReport rpt = new SummaryReport();
                    frmPrintPreview frm = new frmPrintPreview();

                    rpt.SetDataSource(DT);
                    rpt.Database.Tables[0].ApplyLogOnInfo(logonInfo);
                    frm.crystalReportViewer1.ReportSource = rpt;
                    frm.StartPosition = FormStartPosition.CenterScreen;
                    frm.WindowState = FormWindowState.Maximized;
                    frm.Show();
                }
                else
                {
                    MessageBox.Show("ไม่พบข้อมูล");
                }
            }
            else {
                MessageBox.Show("ไม่พบโฟล์เดอร์ที่ระบุ");
            }
        }