Пример #1
0
        public ExecutionResult SaveTemplate(string fileName)
        {
            #region Variable Definition
            ExecutionResult execRes = new ExecutionResult();
            BinarySerialize serializer = new BinarySerialize();
            byte[] buffer = null;
            Hashtable values = new Hashtable();
            #endregion
            //IDbConnection iDbConn = this.GetConnection(this.report.EEPAlias);
            try
            {
                #region Get serialized values
                //ReportID
                if (string.IsNullOrEmpty(this.report.ReportID))
                {
                    values.Add(SysRptDB.ReportID, SysRptDB.SysReportID);
                }
                else
                {
                    values.Add(SysRptDB.ReportID, this.report.ReportID);
                }
                //FileName
                //values.Add(Path.GetFileName(report.FilePath));
                values.Add(SysRptDB.FileName, fileName);

                //ReportName
                values.Add(SysRptDB.ReportName, report.ReportName);

                //Description
                values.Add(SysRptDB.Description, report.Description);

                //FilePath
                values.Add(SysRptDB.FilePath, report.FilePath);

                //OutputMode
                values.Add(SysRptDB.OutputMode, report.OutputMode.ToString());

                //HeaderRepeat
                values.Add(SysRptDB.HeaderRepeat, report.HeaderRepeat.ToString());

                //HeaderFont
                buffer = serializer.Serialize(report.HeaderFont);
                values.Add(SysRptDB.HeaderFont, buffer);

                //HeaderItems
                buffer = serializer.Serialize(report.HeaderItems);
                values.Add(SysRptDB.HeaderItems, buffer);

                //FooterFont
                buffer = serializer.Serialize(report.FooterFont);
                values.Add(SysRptDB.FooterFont, buffer);

                //FooterItems
                buffer = serializer.Serialize(report.FooterItems);
                values.Add(SysRptDB.FooterItems, buffer);

                //FieldFont
                buffer = serializer.Serialize(report.FieldFont);
                values.Add(SysRptDB.FieldFont, buffer);

                //FieldItems
                buffer = serializer.Serialize(report.FieldItems);
                values.Add(SysRptDB.FieldItems, buffer);

                ////Setting
                //buffer = serializer.Serialize(report.Setting);
                //values.Add(SysRptDB.Setting, buffer);

                //Format
                buffer = serializer.Serialize(report.Format);
                values.Add(SysRptDB.Format, buffer);

                //Parameters
                buffer = serializer.Serialize(report.Parameters);
                values.Add(SysRptDB.Parameters, buffer);

                //Images
                buffer = serializer.Serialize(report.Images);
                values.Add(SysRptDB.Images, buffer);

                //Mail Setting
                buffer = serializer.Serialize(report.MailSetting);
                values.Add(SysRptDB.MailSetting, buffer);
                #endregion

                if (this.report.ReportID == null || this.report.ReportID == String.Empty)
                {
                    execRes = this.ExecuteSql(GetSelectTemplateSql(fileName), ExecuteMode.Select);
                }
                else
                {
                    execRes = this.ExecuteSql(GetSelectTemplateSql(this.report.ReportID, fileName), ExecuteMode.Select);
                }

                if (execRes.Status)
                {
                    if (((DataTable)execRes.Anything).Rows.Count == 0)
                    {
                        execRes = this.ExecuteSql(GetInsertSysRptTableSql(values), ExecuteMode.Insert, values);
                    }
                    else
                    {
                        //if (saveMode == SaveMode.Save)
                        //{
                        execRes = this.ExecuteSql(GetUpdateSysRptTableSql(values), ExecuteMode.Update, values);
                        //}
                        //else
                        //{
                        //  execRes.Status = false;
                        //    execRes.Message = MessageInfo.TemplateExist;
                        //}
                    }
                }

                if (execRes.Status)
                {
                    execRes.Message = MessageInfo.SaveSuccess;
                }
            }
            catch (Exception ex)
            {
                execRes.Status = false;
                execRes.Message = ex.Message;
            }
            finally
            {
            }

            return execRes;
        }
Пример #2
0
        public ExecutionResult ExecuteSql(string sql, ExecuteMode executeMode, Hashtable htValues)
        {
            ExecutionResult execRes = new ExecutionResult();
            bool designMode = string.IsNullOrEmpty(CliUtils.fLoginDB);
            if (designMode)
            {
                return ExecuteSqlDesign(sql, executeMode, htValues);
            }
            string database = designMode ? report.EEPAlias : CliUtils.fLoginDB;
            CliUtils.fLoginDB = database;
            ClientType clientType = CliUtils.GetDataBaseType(database);

            DBParameter dbParameter = new DBParameter(clientType);
            try
            {
                ArrayList parameters = new ArrayList();
                if (htValues != null)
                {
                    foreach (DictionaryEntry de in htValues)
                    {
                        IDbDataParameter dbParam = dbParameter.CreateParameter();
                        dbParam.ParameterName = dbParameter.ParamTag + de.Key;
                        dbParam.Value = de.Value;
                        if (de.Value != null)
                        {
                            if (de.Value.GetType().Name == "Byte[]")
                            {
                                if (dbParam is OleDbParameter)
                                    (dbParam as OleDbParameter).OleDbType = OleDbType.LongVarBinary;
                                else
                                    dbParam.DbType = DbType.Binary;
                            }
                            else
                            {
                                if (dbParam is OleDbParameter)
                                    (dbParam as OleDbParameter).OleDbType = OleDbType.VarChar;
                                else
                                    dbParam.DbType = DbType.String;
                            }
                        }
                        else
                        {
                            if (dbParam is OleDbParameter)
                                (dbParam as OleDbParameter).OleDbType = OleDbType.VarChar;
                            else
                                dbParam.DbType = DbType.String;
                            dbParam.Value = "";
                        }
                        parameters.Add(dbParam);
                    }
                }

                DataSet ds = CliUtils.ExecuteSql("GLModule", "cmdRefValUse", sql, database, executeMode == ExecuteMode.Select, CliUtils.fCurrentProject, null, parameters);

                if (executeMode == ExecuteMode.Select)
                {
                    execRes.Anything = ds.Tables[0];
                }

                //if (executeMode == ExecuteMode.Select)
                //{
                //    iDbDataAdapter = DBUtils.CreateDbDataAdapter(iDbCommand);
                //    if (iDbCommand.Connection is OleDbConnection)
                //    {
                //        DataTable dt = new DataTable();
                //        (iDbDataAdapter as OleDbDataAdapter).Fill(dt);
                //        ds.Tables.Add(dt);
                //    }
                //    else
                //        iDbDataAdapter.Fill(ds);
                //    //iDbDataAdapter.Fill(ds);
                //    execRes.Anything = ds.Tables[0];
                //}
                //else
                //{
                //    iDbCommand.ExecuteNonQuery();
                //}
                execRes.Status = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (designMode)
                {
                    CliUtils.fLoginDB = string.Empty;
                }
            }

            return execRes;
        }
Пример #3
0
        public ExecutionResult ExecuteSqlDesign(string sql, ExecuteMode executeMode, Hashtable htValues)
        {
            IDbConnection iDbConn = GetConnection(report.EEPAlias);
            #region Variable Definition
            ExecutionResult execRes = new ExecutionResult();
            //IDbConnection iDbConn = null;
            IDbCommand iDbCommand = null;
            IDbDataAdapter iDbDataAdapter = null;
            DataSet ds = new DataSet();
            IDbDataParameter dbParam = null;
            #endregion

            DBParameter dbParameter = new DBParameter(DBUtils.GetDatabaseType(iDbConn));
            try
            {

                if (iDbConn.State == ConnectionState.Closed)
                {
                    iDbConn.Open();
                }
                iDbCommand = iDbConn.CreateCommand();
                iDbCommand.CommandText = sql;
                if (htValues != null)
                {
                    foreach (DictionaryEntry de in htValues)
                    {
                        dbParam = iDbCommand.CreateParameter();
                        dbParam.ParameterName = dbParameter.ParamTag + de.Key;
                        dbParam.Value = de.Value;
                        if (de.Value != null)
                        {
                            if (de.Value.GetType().Name == "Byte[]")
                            {
                                if (iDbCommand.Connection is OleDbConnection)
                                    (dbParam as OleDbParameter).OleDbType = OleDbType.LongVarBinary;
                                else
                                    dbParam.DbType = DbType.Binary;
                            }
                            else
                            {
                                if (iDbCommand.Connection is OleDbConnection)
                                    (dbParam as OleDbParameter).OleDbType = OleDbType.VarChar;
                                else
                                    dbParam.DbType = DbType.String;
                            }
                        }
                        else
                        {
                            if (iDbCommand.Connection is OleDbConnection)
                                (dbParam as OleDbParameter).OleDbType = OleDbType.VarChar;
                            else
                                dbParam.DbType = DbType.String;
                            dbParam.Value = "";
                        }
                        iDbCommand.Parameters.Add(dbParam);
                    }
                }

                if (executeMode == ExecuteMode.Select)
                {
                    iDbDataAdapter = DBUtils.CreateDbDataAdapter(iDbCommand);
                    DataTable dt = new DataTable();
                    if (iDbCommand.Connection is OleDbConnection)
                    {
                        (iDbDataAdapter as OleDbDataAdapter).Fill(dt);
                        ds.Tables.Add(dt);
                    }
                    else
                        iDbDataAdapter.Fill(ds);
                    //iDbDataAdapter.Fill(ds);
                    execRes.Anything = ds.Tables[0];
                }
                else
                {
                    iDbCommand.ExecuteNonQuery();
                }

                execRes.Status = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                iDbConn.Close();
                //iDbConn.Dispose();

            }

            return execRes;
        }
Пример #4
0
        private void btPreview_Click(object sender, EventArgs e)
        {
            IReportExport excelReport = null;
            ExecutionResult execResult;
            execResult = new ExecutionResult();

            this.Cursor = Cursors.WaitCursor;

            this.SaveReportConfig();

            if (this.TempReport.Format.ExportFormat == ReportFormat.ExportType.Excel)
            {
                excelReport = new ExcelReportExporter(this.TempReport, ExportMode.Preview, false);
            }
            else
            {
                excelReport = new PdfReportExporter(this.TempReport, ExportMode.Preview, false);
            }

            execResult = excelReport.CheckValidate();

            if (execResult.Status)
            {
                excelReport.View();
            }
            else
            {
                MessageBox.Show(execResult.Message, "Preview Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.Cursor = Cursors.Default;
        }
Пример #5
0
        private void btExport_Click(object sender, EventArgs e)
        {
            IReportExport reportExport = null;
            ExecutionResult execResult = new ExecutionResult();

            this.SaveReportConfig();

            if (this.TempReport.Format.ExportFormat == ReportFormat.ExportType.Excel)
            {
                reportExport = new ExcelReportExporter(this.TempReport, ExportMode.Export, false);
            }
            else
            {
                reportExport = new PdfReportExporter(this.TempReport, ExportMode.Export, false);
            }

            execResult = reportExport.CheckValidate();

            if (execResult.Status)
            {
                fmProgress fp = new fmProgress("Easily Report (" + this.TempReport.Format.ExportFormat.ToString() + " Format)", reportExport, this.TempReport);
                fp.Visible = false;
                fp.ShowDialog();
            }
            else
            {
                MessageBox.Show(execResult.Message, TitleMsgInfo.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #6
0
        /// <summary>
        /// Export Pdf
        /// </summary>
        private void ExportPdf()
        {
            #region Variable Definition
            ExecutionResult execResult = new ExecutionResult();
            SizeInfo pdfSize = new SizeInfo(this.Report, this.Report.Format.PageSize);
            int maxGroupCount = 0;
            List<List<int>> allStartIndex = new List<List<int>>();
            #endregion
            try
            {
                this.progressInfo = 0;
                this.progressCount = 0;

                pdf = new PdfController(Report, exportMode, ExportByHeight, DesignMode, PageWidth);

                #region Ӌ�㿂퓔�
                for (int i = 0; i < Report.FieldItems.Count; i++)
                {
                    DataSourceItem fieldItem = Report.FieldItems[i];
                    List<int> startIndex = new List<int>();

                    startIndex.Clear();

                    if (fieldItem.Fields.Count > 0)
                    {
                        List<string> groupColumns = new List<string>();
                        DataTable table = GroupBy(i, groupColumns);//��Table��������

                        if (table.Rows.Count > 0)
                        {
                            startIndex.Add(0);
                        }

                        if (fieldItem.GroupGap == DataSourceItem.GroupGapType.Page)
                        {
                            for (int j = 0; j < table.Rows.Count; j++)
                            {
                                if (j > 0 && GroupBreak(table.Rows[j], table.Rows[j - 1], groupColumns))
                                {
                                    startIndex.Add(j);
                                }
                            }
                        }
                        else
                        {
                            int maxCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(table.Rows.Count) / Convert.ToDouble(Report.Format.PageRecords)));
                            for (int j = 0; j < maxCount - 1; j++)
                            {
                                startIndex.Add((j + 1) * Report.Format.PageRecords);
                            }
                        }

                        if (startIndex.Count > maxGroupCount)
                        {
                            maxGroupCount = startIndex.Count;
                        }
                    }

                    allStartIndex.Add(startIndex);

                    processInfoCollection.Add(0);
                }

                if (maxGroupCount != 0)
                {
                    pdfSize.TotalPageCount = maxGroupCount;
                }
                #endregion

                if (exportMode == ExportMode.Export)
                {
                    Report.SetPageCount(pdfSize.TotalPageCount);
                }
                else
                {
                    Report.SetPageCount(1);
                }

                this.TagInfo = ProcessTagInfo.Exporting;

                for (int i = 0; i < pdfSize.TotalPageCount; i++)
                {
                    Report.SetCurrentPageIndex(i + 1);

                    CreateItem(Report.HeaderItems, Report.HeaderFont);

                    if (ExportByHeight)
                    {
                        AllFieldList.Add(ExportField(allStartIndex));
                    }
                    else
                    {
                        ExportField(allStartIndex);
                    }

                    CreateItem(Report.FooterItems, Report.FooterFont);

                    if (i != Report.PageCount - 1 && !ExportByHeight)
                    {
                        pdf.NewPage();
                    }
                }

                if (ExportByHeight)
                {
                    FitsPage();
                }

                if (exportMode == ExportMode.Export)
                {
                    this.TagInfo = ProcessTagInfo.ProcessFinished;
                    this.ProgressInfo = this.ProgressCount;
                }
            }
            catch (Exception ex)
            {
                ThrowException(ex);
            }
            finally
            {
                if (pdf != null)
                {
                    if (Report.PageCount == 0)
                    {
                        pdf.SetEmpty();
                    }
                    pdf.Dispose();
                }
            }
        }
Пример #7
0
        public ExecutionResult CheckValidate()
        {
            #region Variable Definition
            ExecutionResult execResult = new ExecutionResult();
            bool newLine = false;
            int excelGroupCount = 0;
            int normalGroupCount = 0;
            #endregion

            execResult.Status = true;

            foreach (DataSourceItem fieldItem in Report.FieldItems)
            {
                if (fieldItem.DataSource == null)
                {
                    execResult.Status = false;
                    execResult.Message = MessageInfo.DataSourceNull;
                    return execResult;
                }
                else if (fieldItem.Fields.Count == 0)
                {
                    execResult.Status = false;
                    execResult.Message = MessageInfo.FieldItemsNull;
                    return execResult;
                }
                foreach (FieldItem field in fieldItem.Fields)
                {
                    switch (field.Group)
                    {
                        case FieldItem.GroupType.Normal: normalGroupCount++; break;
                        case FieldItem.GroupType.Excel: excelGroupCount++; break;
                    }
                    if (field.NewLine)
                    {
                        newLine = true;
                    }
                }
                if (excelGroupCount > 0 && normalGroupCount > 0)
                {
                    execResult.Status = false;
                    execResult.Message = MessageInfo.MultiGroupModeError;
                    return execResult;
                }

                else if (excelGroupCount > 1)
                {
                    execResult.Status = false;
                    execResult.Message = MessageInfo.MultiExcelGroupColumnError;
                    return execResult;
                }
                else if (excelGroupCount == 1 && (newLine || Report.FieldItems.Count > 1))
                {
                    execResult.Status = false;
                    execResult.Message = MessageInfo.ExcelGroupNewLineError;
                    return execResult;
                }
                else if (fieldItem.GroupTotal && excelGroupCount == 0 && normalGroupCount == 0)
                {
                    execResult.Status = false;
                    execResult.Message = MessageInfo.GroupColumnsNotSetError;
                    return execResult;
                }
            }

            return execResult;
        }