private void CheckDataSourceField(string dataSourceName, string fieldName)
        {
            StiDataSource ds = report.Dictionary.DataSources[dataSourceName];

            if (ds == null)
            {
                ds = new StiSqlSource();
                (ds as StiSqlSource).NameInSource = string.Format("Connection1.{0}", dataSourceName);
                ds.Name  = dataSourceName;
                ds.Alias = dataSourceName;
                (ds as StiSqlSource).SqlCommand = string.Format("select * from {0}", dataSourceName);

                report.Dictionary.DataSources.Add(ds);
            }
            StiDataColumn dc = ds.Columns[fieldName];

            if (dc == null)
            {
                dc = new StiDataColumn(fieldName, fieldName, fieldName, typeof(string));
                ds.Columns.Add(dc);
            }
        }
Exemple #2
0
        private void butReport_Click(object sender, EventArgs e)
        {
            if (this.lisEmployeesColumns.Count == 0)
            {
                MessageBox.Show("هیج ستونی انتخاب نشده است.");
                return;
            }

            EmployeesReport erEmployeesReport = new EmployeesReport();

            erEmployeesReport.cnConnection = this.cnConnection;
            erEmployeesReport.usUser       = this.usUser;
            erEmployeesReport.setSettings  = this.setSettings;

            //Report
            StiReport srEmployees = new StiReport();

            srEmployees.Pages[0].PaperSize = System.Drawing.Printing.PaperKind.A4;
            //MessageBox.Show(srEmployees.Pages[0].PaperSize.ToString());
            //srEmployees.
            string strSColumnsName = "";

            for (int i = 0; i < this.lisEmployeesColumns.Count; i++)
            {
                if (i != 0)
                {
                    strSColumnsName += ", ";
                }

                strSColumnsName += this.lisEmployeesColumns[i].strName;
            }
            //DataBase
            StiSqlDatabase dbDataBase1 = new StiSqlDatabase();

            dbDataBase1.Alias            = "dbDataBase1";
            dbDataBase1.Name             = "dbDataBase1";
            dbDataBase1.ConnectionString = this.cnConnection.strConnectionStringPty;
            srEmployees.Dictionary.Databases.Add(dbDataBase1);
            //DataSource
            StiSqlSource dsDataSource = new StiSqlSource();

            dsDataSource.NameInSource = "dbDataBase1";
            dsDataSource.Alias        = "dsDataSource";
            dsDataSource.Name         = "dsDataSource";
            dsDataSource.SqlCommand   = Employee.GetSqlCommand(this.emSearch, strSColumnsName);
            for (int i = 0; i < this.lisEmployeesColumns.Count; i++)
            {
                dsDataSource.Columns.Add(this.lisEmployeesColumns[i].strName, this.lisEmployeesColumns[i].typType);
            }
            srEmployees.DataSources.Add(dsDataSource);
            //HeaderBand
            StiHeaderBand headerBand1 = new StiHeaderBand();

            headerBand1.Height = 0.5;
            headerBand1.Name   = "HeaderBand1";
            srEmployees.Pages[0].Components.Add(headerBand1);
            StiText headerText = new StiText(new RectangleD(5, 0.2, 9.6, 1));

            headerText.Text         = "کارکنان شرکت " + FamSetting.GetCoInformation(this.cnConnection).strName;
            headerText.HorAlignment = StiTextHorAlignment.Center;
            headerText.Name         = "headerText1";
            headerText.Font         = new Font("B Titr", 17);
            headerText.Brush        = new StiSolidBrush(Color.Transparent);
            headerBand1.Components.Add(headerText);
            //ColumnHeaderBand
            StiColumnHeaderBand columnHeaderBand1 = new StiColumnHeaderBand();

            columnHeaderBand1.Height = 0.5;
            columnHeaderBand1.Name   = "columnHeaderBand1";
            srEmployees.Pages[0].Components.Add(columnHeaderBand1);
            StiText[] stColumnHeaders = new StiText[this.lisEmployeesColumns.Count];
            double    douX            = 19;

            for (int i = 0; i < this.lisEmployeesColumns.Count; i++)
            {
                stColumnHeaders[i]               = new StiText(new RectangleD(douX - this.lisEmployeesColumns[i].douWidth, 1, this.lisEmployeesColumns[i].douWidth, 0.8));
                stColumnHeaders[i].Text          = this.lisEmployeesColumns[i].strCaption;
                stColumnHeaders[i].Name          = "ch" + this.lisEmployeesColumns[i].strName;
                stColumnHeaders[i].Border        = new StiBorder(StiBorderSides.All, Color.Black, 1, StiPenStyle.Solid);
                stColumnHeaders[i].Font          = new Font("B Titr", 12);
                stColumnHeaders[i].Brush         = new StiSolidBrush(Color.Gray);
                stColumnHeaders[i].HorAlignment  = StiTextHorAlignment.Center;
                stColumnHeaders[i].VertAlignment = StiVertAlignment.Center;
                columnHeaderBand1.Components.Add(stColumnHeaders[i]);
                douX -= this.lisEmployeesColumns[i].douWidth;
            }
            //DataBand
            StiDataBand dataBand1 = new StiDataBand();

            dataBand1.DataSourceName = "dsDataSource";
            dataBand1.Height         = 0.5;
            dataBand1.Name           = "dataBand1";
            srEmployees.Pages[0].Components.Add(dataBand1);
            StiText[] stDataText = new StiText[this.lisEmployeesColumns.Count];
            douX = 19;
            for (int i = 0; i < this.lisEmployeesColumns.Count; i++)
            {
                stDataText[i]               = new StiText(new RectangleD(douX - this.lisEmployeesColumns[i].douWidth, 0, this.lisEmployeesColumns[i].douWidth, 0.6));
                stDataText[i].Text          = "{dsDataSource." + this.lisEmployeesColumns[i].strName + "}";
                stDataText[i].Name          = "db" + this.lisEmployeesColumns[i].strName;
                stDataText[i].Font          = new Font("B Nazanin", 10);
                stDataText[i].Brush         = new StiSolidBrush(Color.Transparent);
                stDataText[i].HorAlignment  = StiTextHorAlignment.Center;
                stDataText[i].VertAlignment = StiVertAlignment.Center;
                stDataText[i].Border        = new StiBorder(StiBorderSides.All, Color.Black, 1, StiPenStyle.Solid);
                dataBand1.Components.Add(stDataText[i]);
                douX -= this.lisEmployeesColumns[i].douWidth;
            }
            //Render
            srEmployees.Dictionary.Synchronize();
            srEmployees.Compile();
            srEmployees.Render(false);
            //srEmployees.Save(@"c:\rpt\report3.mrt");

            erEmployeesReport.stvEmployees.Report = srEmployees;
            erEmployeesReport.ShowDialog();
        }
        private void button3_Click(object sender, EventArgs e)
        {
            bool   IsNameUnique      = true;
            string connectionString1 = textBox1.Text.Trim();
            string connectionString2 = textBox2.Text.Trim();

            if ((connectionString1.Length > 0) || (connectionString2.Length > 0))
            {
                if (this.Report == null)
                {
                    this.Report = new StiReport();
                }
                this.Report.Dictionary.Clear();
                this.report.DataStore.Clear();
            }
            if (connectionString1.Length > 0)
            {
                StiDatabase mySqlDatabase = null;
                foreach (StiDatabase database in this.report.Dictionary.Databases)
                {
                    if (database.Name == "MyStiSqlDatabase")
                    {
                        mySqlDatabase = database;
                    }
                }
                if (mySqlDatabase == null)
                {
                    mySqlDatabase = new StiSqlDatabase("MyStiSqlDatabase", connectionString1);
                    this.Report.Dictionary.Databases.Add(mySqlDatabase);
                }
                if (mySqlDatabase.GetType() == typeof(StiSqlDatabase))
                {
                    foreach (string myItem in checkedListBox1.CheckedItems)
                    {
                        IsNameUnique = true;
                        foreach (StiDataSource source in this.Report.DataSources)
                        {
                            if (source.Name == myItem)
                            {
                                IsNameUnique = false;
                            }
                        }
                        if (IsNameUnique)
                        {
                            StiSqlSource sqlSource = new StiSqlSource("MyStiSqlDatabase", myItem, myItem, "SELECT * FROM dbo.\"" + myItem + "\"");
                            this.Report.Dictionary.DataSources.Add(sqlSource);
                            this.Report.Dictionary.Synchronize();
                            sqlSource.SynchronizeColumns();
                        }
                    }
                }
            }
            if (connectionString2.Length > 0)
            {
                StiDatabase myOleDbDatabase = null;
                foreach (StiDatabase database in this.report.Dictionary.Databases)
                {
                    if (database.Name == "MyStiOleDbDatabase")
                    {
                        myOleDbDatabase = database;
                    }
                }
                if (myOleDbDatabase == null)
                {
                    myOleDbDatabase = new StiOleDbDatabase("MyStiOleDbDatabase", connectionString2);
                    this.Report.Dictionary.Databases.Add(myOleDbDatabase);
                }
                if (myOleDbDatabase.GetType() == typeof(StiOleDbDatabase))
                {
                    foreach (string myItem in checkedListBox2.CheckedItems)
                    {
                        IsNameUnique = true;
                        foreach (StiDataSource source in this.Report.DataSources)
                        {
                            if (source.Name == myItem)
                            {
                                IsNameUnique = false;
                            }
                        }
                        if (IsNameUnique)
                        {
                            StiOleDbSource oleDbSource = new StiOleDbSource("MyStiOleDbDatabase", myItem, myItem, "SELECT * FROM [" + myItem + "]");
                            this.Report.Dictionary.DataSources.Add(oleDbSource);
                            this.Report.Dictionary.Synchronize();
                            oleDbSource.SynchronizeColumns();
                        }
                    }
                }
            }
            if (this.Report == null)
            {
                this.Report = new StiReport();
            }
            if (this.Report.Designer == null)
            {
                StiDesigner.CreatedReport   += new EventHandler(StiDesigner_CreatedReport);
                StiDesigner.ClosingDesigner += ClosingDesigner;
                MessageBox.Show("Click 'File' then 'New Report' and this dialog appears again.");
                this.Report.Design();
                this.Report = null;
            }
            else
            {
                this.Close();
            }
        }
        public override void ConnectDataSourceToData(StiDictionary dictionary, StiDataSource dataSource, bool loadData)
        {
            dataSource.Disconnect();

            if (!loadData)
            {
                dataSource.DataTable = new DataTable();
                return;
            }

            StiSqlSource sqlSource = dataSource as StiSqlSource;

            foreach (StiData data in dataSource.Dictionary.DataStore)
            {
                if (data.Name != sqlSource.NameInSource)
                {
                    continue;
                }

                try
                {
                    if (!(data.Data is NpgsqlConnection))
                    {
                        continue;
                    }

                    var connection = data.ViewData as NpgsqlConnection;
                    OpenConnection(connection, data, dataSource.Dictionary);

                    sqlSource.DataAdapter = new NpgsqlDataAdapter(sqlSource.SqlCommand, connection);

                    foreach (StiDataParameter parameter in sqlSource.Parameters)
                    {
                        ((NpgsqlDataAdapter)sqlSource.DataAdapter).SelectCommand.Parameters.Add(
                            parameter.Name, (NpgsqlTypes.NpgsqlDbType)parameter.Type, parameter.Size);
                    }

                    var dataTable = new DataTable();
                    dataTable.TableName  = sqlSource.Name;
                    dataSource.DataTable = dataTable;

                    sqlSource.DataAdapter.SelectCommand.CommandTimeout = sqlSource.CommandTimeout;
                    if (loadData && sqlSource.Parameters.Count > 0)
                    {
                        sqlSource.DataAdapter.SelectCommand.Prepare();
                        sqlSource.UpdateParameters();
                    }
                    else
                    {
                        if (loadData)
                        {
                            ((NpgsqlDataAdapter)sqlSource.DataAdapter).Fill(dataTable);
                            sqlSource.CheckColumnsIndexs();
                        }
                        else
                        {
                            ((NpgsqlDataAdapter)sqlSource.DataAdapter).FillSchema(dataTable, SchemaType.Source);
                        }
                    }

                    break;
                }
                catch (Exception e)
                {
                    StiLogService.Write(this.GetType(), e);
                    if (!StiOptions.Engine.HideExceptions)
                    {
                        throw;
                    }
                }
            }
        }