FrmCrystalReprotEN.cs 11.9 KB
using System;
using System.Data;
using Comm;
using System.IO;
using CrystalDecisions.CrystalReports.Engine;
using Dal;

namespace App
{
    public partial class FrmCrystalReprotEN : App.FrmBase
    {
        string _ProductImageRoot;
        string _TestImageRoot;
        string _TestDate;
        string _TestTime;
        string _ProductName;
        string _ProductSize;
        string _Standard;
        string _Temperature;
        string _Operator;
        string _Department;
        string _Company;
        string _Solvent;
        string _TestMode;
        string _TestResult;
        string _MIL;
        string _DEF;
        string _UserDefine;
        string _startTime;
        string _endTime;
        string _UserLimitValue;
        string _IPCValue;
        string _Unit;
        string _MILValue;
        string _DEFValue;
        string _IPC;
        string _ECName1;
        string _ECValue1;
        string _ECName2;
        string _ECValue2;
        string _WashUpperLimit;
        string _MachineModel;
        string _ECResult1;
        string _ECResult2;
        string _SerialNumber;
        string _CalibrationDate;
        string _Notes;
        string _dataFirst;
        string _dataLast;

        public FrmCrystalReprotEN(string productImageRoot,
        string testImageRoot, string testDate, string testTime, string productName,
        string productSize, string standard, string temperature, string Operator,
        string department, string company, string solvent, string testMode,
        string testResult, string mIL, string dEF, string userDefine, string StartTime, string endTime, string ParUserLimit, string ParaIPC, string Unit, string MIL, string DEF, string IPCReport,
            string ecValue1, string ecValue2, string ecName1, string ecName2, string WashUpperLimit, string MachineModel
            , string ecResult1, string ecResult2, string SerialNumber, string CalibrationDate, string Notes,
            string dataFirst, string dataLast)
        {
            InitializeComponent();
            _ProductImageRoot = productImageRoot;
            _TestImageRoot = testImageRoot;
            _TestDate = testDate;
            _TestTime = testTime;
            _ProductName = productName;
            _ProductSize = productSize;
            _Standard = standard;
            _Temperature = temperature;
            _Operator = Operator;
            _Department = department;
            _Company = company;
            _Solvent = solvent;
            _TestMode = testMode;
            _TestResult = testResult;
            _MIL = mIL;
            _DEF = dEF;
            _UserDefine = userDefine;
            _startTime = StartTime;
            _endTime = endTime;
            _UserLimitValue = ParUserLimit;
            _IPCValue = ParaIPC;
            _Unit = Unit;
            _MILValue = MIL;
            _DEFValue = DEF;
            _IPC = IPCReport;
            _ECName1 = ecName1;
            _ECValue1 = ecValue1;
            _ECName2 = ecName2;
            _ECValue2 = ecValue2;
            _WashUpperLimit = WashUpperLimit;
            _MachineModel = MachineModel;
            _ECResult1 = ecResult1;
            _ECResult2 = ecResult2;
            _SerialNumber = SerialNumber;
            _CalibrationDate = CalibrationDate;
            _Notes = Notes;

            //Asa, 2020/7/16
            _dataFirst = dataFirst;
            _dataLast = dataLast;
        }
        private void CreateReport()
        {
            CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1;
            crystalReportViewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
            crystalReportViewer1.ActiveViewIndex = 0;
            crystalReportViewer1.ShowLogo = false;
            crystalReportViewer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            crystalReportViewer1.DisplayGroupTree = false;
            crystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill;
            crystalReportViewer1.Location = new System.Drawing.Point(0, 0);
            crystalReportViewer1.Name = "crystalReportViewer1";
            crystalReportViewer1.ShowGroupTreeButton = false;
            crystalReportViewer1.Size = new System.Drawing.Size(767, 477);
            crystalReportViewer1.TabIndex = 0;
            ReportDocument rep = new ReportDocument();
            rep.Load(Fuction.m_CurrentDirectory + @"\CrystalReport\CrystalReportEN.rpt");


            DataTable data = new DataTable("DataTable1");
            data.Columns.Add(Const.CR_PRODUCTIMAGE, System.Type.GetType("System.Byte[]"));
            data.Columns.Add(Const.CR_TESTIMAGE, System.Type.GetType("System.Byte[]"));
            data.Columns.Add(Const.CR_TESTDATE, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_TESTTIME, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_PRODCTNAME, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_PRODUCTSIZE, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_STANDARD, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_TEMPRATURE, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_OPERATOR, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_DEPARTMENT, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_COMPANY, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_SOLVENT, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_TESTMODE, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_TESTRESULT, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_MIL, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_DEF, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_USERDEFINE, System.Type.GetType("System.String"));

            data.Columns.Add(Const.CR_USERLIMITVALUE, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_IPCVALUE, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_UNIT, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_MILVALUE, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_DEFVALUE, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_IPC, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_ECNAME1, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_ECVALUE1, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_ECNAME2, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_ECVALUE2, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_MACHINEMODEL, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_WASHUPPERLIMIT, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_ECRESULT1, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_ECRESULT2, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_SERIALNUMBER, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_CALIBRATIONDDATE, System.Type.GetType("System.String"));
            data.Columns.Add(Const.CR_NOTES, System.Type.GetType("System.String"));

            //Asa, 2020/7/16
            data.Columns.Add("DataFirst", System.Type.GetType("System.String"));
            data.Columns.Add("DataLast", System.Type.GetType("System.String"));


            DataRow row = data.NewRow();
            // define the filestream object to read the image 
            FileStream fs = null;
            // define te binary reader to read the bytes of image 
            BinaryReader br = null;
            byte[] imgbyte = new byte[0];
            if (File.Exists(@_ProductImageRoot))
            {
                // open image in file stream 
                fs = new FileStream(@_ProductImageRoot, FileMode.Open);
                // initialise the binary reader from file streamobject 
                br = new BinaryReader(fs);
                // define the byte array of filelength 

                imgbyte = new byte[fs.Length + 1];
                // read the bytes from the binary reader 
                imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)));
            }
            //else
            //{
            //    // if phot does not exist show the nophoto.jpg file 
            //    fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "NoPhoto.jpg", FileMode.Open);
            //}

            row[Const.CR_PRODUCTIMAGE] = imgbyte;
            imgbyte = new byte[0];
            fs = null;
            br = null;
            if (File.Exists(@_TestImageRoot))
            {
                // open image in file stream 
                fs = new FileStream(@_TestImageRoot, FileMode.Open);
                // initialise the binary reader from file streamobject 
                br = new BinaryReader(fs);
                // define the byte array of filelength 
                imgbyte = new byte[fs.Length + 1];
                // read the bytes from the binary reader 
                imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)));
            }
            //else
            //{
            //    // if phot does not exist show the nophoto.jpg file 
            //    fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "NoPhoto.jpg", FileMode.Open);
            //}

            row[Const.CR_TESTIMAGE] = imgbyte;

            row[Const.CR_TESTDATE] = _TestDate;
            row[Const.CR_TESTTIME] = _TestTime;
            row[Const.CR_PRODCTNAME] = _ProductName;
            row[Const.CR_PRODUCTSIZE] = _ProductSize;
            row[Const.CR_STANDARD] = _Standard;
            row[Const.CR_TEMPRATURE] = _Temperature;
            row[Const.CR_OPERATOR] = _Operator;
            row[Const.CR_DEPARTMENT] = _Department;
            row[Const.CR_COMPANY] = _Company;
            row[Const.CR_SOLVENT] = _Solvent;
            row[Const.CR_TESTMODE] = _TestMode;
            row[Const.CR_TESTRESULT] = _TestResult;
            row[Const.CR_MIL] = _MIL;
            row[Const.CR_DEF] = _DEF;
            row[Const.CR_USERDEFINE] = _UserDefine;

            row[Const.CR_USERLIMITVALUE] = _UserLimitValue;
            row[Const.CR_IPCVALUE] = _IPCValue;
            row[Const.CR_UNIT] = _Unit;
            row[Const.CR_MILVALUE] = _MILValue;
            row[Const.CR_DEFVALUE] = _DEFValue;
            row[Const.CR_IPC] = _IPC;
            row[Const.CR_ECNAME1] = _ECName1;
            row[Const.CR_ECVALUE1] = _ECValue1;
            row[Const.CR_ECNAME2] = _ECName2;
            row[Const.CR_ECVALUE2] = _ECValue2;
            row[Const.CR_MACHINEMODEL] = _MachineModel;
            row[Const.CR_WASHUPPERLIMIT] = _WashUpperLimit;
            row[Const.CR_ECRESULT1] = _ECResult1;
            row[Const.CR_ECRESULT2] = _ECResult2;
            row[Const.CR_SERIALNUMBER] = _SerialNumber;
            row[Const.CR_CALIBRATIONDDATE] = _CalibrationDate;
            row[Const.CR_NOTES] = _Notes;


            //Asa, 2020/7/16
            row["DataFirst"] = _dataFirst;
            row["DataLast"] = _dataLast;


            data.Rows.Add(row);
            if (br != null)
            {
                // add row into the datatable 
                br.Close();
                // close the binary reader 
                fs.Close();
            }
            // close the file stream 
            // object of crystal report 
            rep.SetDataSource(data);
            // set the datasource of crystalreport object 
            crystalReportViewer1.ReportSource = rep;
            //set the report source 
            crystalReportViewer1.Refresh();
            this.Controls.Add(crystalReportViewer1);
        }

        private void FrmCrystalReprotEN_Load(object sender, EventArgs e)
        {
            this.Text = "";
            this.ControlBox = true;
            CreateReport();
        }
    }
}