Пример #1
0
        public static AjaxReturn GetUsers()
        {
            AjaxReturn v_return      = new AjaxReturn();
            UsersData  v_return_data = new UsersData();
            Session    v_session     = (Session)System.Web.HttpContext.Current.Session ["OMNIDB_SESSION"];

            Spartacus.Utils.Cryptor v_cryptor = new Spartacus.Utils.Cryptor("omnidb_spartacus");

            if (v_session == null)
            {
                v_return.v_error    = true;
                v_return.v_error_id = 1;
                return(v_return);
            }

            System.Data.DataTable v_users = v_session.v_omnidb_database.v_connection.Query("select * from users order by user_id", "Users");

            System.Collections.Generic.List <System.Collections.Generic.List <string> > v_user_list = new System.Collections.Generic.List <System.Collections.Generic.List <string> >();
            System.Collections.Generic.List <string> v_user_id_list = new System.Collections.Generic.List <string>();

            int v_index = 0;

            foreach (System.Data.DataRow v_user in v_users.Rows)
            {
                System.Collections.Generic.List <string> v_user_data_list = new System.Collections.Generic.List <string>();

                v_user_data_list.Add(v_user["user_name"].ToString());

                try
                {
                    v_user_data_list.Add(v_cryptor.Decrypt(v_user["password"].ToString()));
                }
                catch (Spartacus.Utils.Exception)
                {
                    v_user_data_list.Add(v_user["password"].ToString());
                }

                if (v_user["user_name"].ToString() == "admin")
                {
                    v_user_data_list.Add("");
                }
                else
                {
                    v_user_data_list.Add("<img src='images/tab_close.png' class='img_ht' onclick='removeUser(" + v_user["user_id"].ToString() + ")'/>");
                }

                v_index++;

                v_user_list.Add(v_user_data_list);

                v_user_id_list.Add(v_user["user_id"].ToString());
            }

            v_return_data.v_data     = v_user_list;
            v_return_data.v_user_ids = v_user_id_list;

            v_return.v_data = v_return_data;
            return(v_return);
        }
Пример #2
0
        private void DecryptString(string p_input)
        {
            Spartacus.Utils.Cryptor v_cryptor;

            try
            {
                Console.Write("Type the password to decrypt the string: ");
                v_cryptor = new Spartacus.Utils.Cryptor(Console.ReadLine());

                Console.WriteLine("                The decrypted string is: {0}", v_cryptor.Decrypt(p_input));
            }
            catch (Spartacus.Utils.Exception e)
            {
                Console.WriteLine(e.v_message);
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #3
0
        /// <summary>
        /// Informa o texto ou valor a ser mostrado no Textbox.
        /// Usado para mostrar ao usuário um formulário já preenchido.
        /// O texto é passado criptografado, e é descriptografado para ser exibido ao usuário.
        /// </summary>
        /// <param name="p_text">Texto a ser mostrado no Textbox.</param>
        /// <param name="p_decryptpassword">Senha para descriptografar.</param>
        public void SetEncryptedValue(string p_text, string p_decryptpassword)
        {
            Spartacus.Utils.Cryptor v_cryptor;
            string v_decrypted;

            v_cryptor = new Spartacus.Utils.Cryptor(p_decryptpassword);

            try
            {
                v_decrypted = v_cryptor.Decrypt(p_text);
            }
            catch (Spartacus.Utils.Exception)
            {
                v_decrypted = p_text;
            }
            catch (System.Exception)
            {
                v_decrypted = p_text;
            }

            this.v_textbox.Text = v_decrypted;
        }
Пример #4
0
        public static AjaxReturn SignIn(string p_username, string p_pwd)
        {
            AjaxReturn v_return = new AjaxReturn();

            Spartacus.Utils.Cryptor v_cryptor = new Spartacus.Utils.Cryptor("omnidb_spartacus");

            // Instantiating tool management database.
            OmniDatabase.Generic v_omnidb_database = OmniDatabase.Generic.InstantiateDatabase("", "0",
                                                                                              "sqlite",
                                                                                              "",
                                                                                              "",
                                                                                              System.Web.Configuration.WebConfigurationManager.AppSettings ["OmniDB.Database"].ToString(),
                                                                                              "",
                                                                                              "",
                                                                                              "");


            if (p_username == "admin")
            {
                string v_encrypted_pwd = System.IO.File.ReadAllText("config/admin.txt");

                string v_pwd;
                try {
                    v_pwd = v_cryptor.Decrypt(v_encrypted_pwd);

                    if (v_pwd == p_pwd)
                    {
                        Session v_session = new Session("-1", p_username, v_omnidb_database, "", "", "", "");
                        v_session.v_omnidb_version = System.Web.Configuration.WebConfigurationManager.AppSettings ["OmniDB.Version"].ToString();
                        System.Web.HttpContext.Current.Session ["OMNIDB_SESSION"] = v_session;
                        v_return.v_data = true;
                    }
                    else
                    {
                        System.Web.HttpContext.Current.Session ["OMNIDB_SESSION"] = null;
                        v_return.v_data = false;
                    }
                } catch (Spartacus.Utils.Exception) {
                    System.Web.HttpContext.Current.Session ["OMNIDB_SESSION"] = null;
                    v_return.v_data = false;
                }

                return(v_return);
            }
            else
            {
                try {
                    // Querying user information.
                    System.Data.DataTable v_user_data = v_omnidb_database.v_connection.Query(
                        "select u.user_id,              " +
                        "       u.password,             " +
                        "       t.theme_id,             " +
                        "       t.theme_name,           " +
                        "       t.theme_type,           " +
                        "       u.editor_font_size      " +
                        "from users u,                  " +
                        "     themes t                  " +
                        " where u.theme_id = t.theme_id " +
                        "and u.user_name = '" + p_username + "' ", "db_data");

                    // If username exists, decrypt password.
                    if (v_user_data.Rows.Count > 0)
                    {
                        string v_pwd;
                        try {
                            v_pwd = v_cryptor.Decrypt(v_user_data.Rows [0] ["password"].ToString());
                        } catch (Spartacus.Utils.Exception) {
                            v_pwd = v_user_data.Rows [0] ["password"].ToString();
                        }

                        // If password is correct, set user as logged in, instantiate Session and return true.
                        if (v_pwd == p_pwd)
                        {
                            Session v_session = new Session(v_user_data.Rows [0] ["user_id"].ToString(), p_username, v_omnidb_database, v_user_data.Rows[0]["theme_name"].ToString(), v_user_data.Rows[0]["theme_type"].ToString(), v_user_data.Rows[0]["theme_id"].ToString(), v_user_data.Rows [0] ["editor_font_size"].ToString());
                            v_session.v_omnidb_version = System.Web.Configuration.WebConfigurationManager.AppSettings ["OmniDB.Version"].ToString();
                            System.Web.HttpContext.Current.Session ["OMNIDB_SESSION"] = v_session;

                            if (!((Dictionary <string, Session>)System.Web.HttpContext.Current.Application["OMNIDB_SESSION_LIST"]).ContainsKey(v_session.v_user_id))
                            {
                                ((Dictionary <string, Session>)System.Web.HttpContext.Current.Application["OMNIDB_SESSION_LIST"]).Add(v_session.v_user_id, v_session);
                            }
                            else
                            {
                                ((Dictionary <string, Session>)System.Web.HttpContext.Current.Application["OMNIDB_SESSION_LIST"])[v_session.v_user_id] = v_session;
                            }

                            v_return.v_data = true;
                        }
                        else
                        {
                            System.Web.HttpContext.Current.Session ["OMNIDB_SESSION"] = null;
                            v_return.v_data = false;
                        }
                    }
                    else
                    {
                        System.Web.HttpContext.Current.Session ["OMNIDB_SESSION"] = null;
                        v_return.v_data = false;
                    }
                } catch (Spartacus.Database.Exception e) {
                    v_return.v_error = true;
                    v_return.v_data  = e.v_message;
                }

                return(v_return);
            }
        }
Пример #5
0
        /// <summary>
        /// Inicializa uma nova instância da classe <see cref="Spartacus.Utils.File"/>.
        /// </summary>
        /// <param name='p_type'>
        /// Indica se é um arquivo ou um diretório.
        /// </param>
        /// <param name='p_completename'>
        /// Nome completo, absoluto ou relativo, do arquivo ou diretório atual.
        /// </param>
        /// <param name='p_encryptedname'>
        /// Se o nome do arquivo está criptografado ou não.
        /// </param>
        /// <param name='p_lastwritedate'>
        /// Data da última modificação do arquivo ou diretório.
        /// </param>
        /// <param name='p_size'>
        /// Tamanho do arquivo.
        /// </param>
        /// <param name='p_encoding'>
        /// Codificação do arquivo.
        /// </param>
        public File(Spartacus.Utils.FileType p_type, string p_completename, bool p_encryptedname, System.DateTime p_lastwritedate, long p_size, System.Text.Encoding p_encoding)
        {
            Spartacus.Utils.Cryptor v_cryptor;
            string v_completename;

            if (p_encryptedname)
            {
                try
                {
                    v_cryptor = new Spartacus.Utils.Cryptor("spartacus");
                    v_completename = v_cryptor.Decrypt(p_completename);
                }
                catch (System.Exception)
                {
                    v_completename = p_completename;
                }
            }
            else
                v_completename = p_completename;

            this.v_filetype = p_type;
            this.v_pathseparator = Spartacus.Utils.PathSeparator.SLASH;
            this.v_name = this.GetBaseName(v_completename);
            this.v_extension = this.GetExtension(v_completename);
            this.v_path = this.GetPath(v_completename);
            this.v_lastwritedate = p_lastwritedate;
            this.v_size = p_size;
            this.v_encoding = p_encoding;
            this.v_protected = false;
            this.v_hidden = this.GetHidden();
        }
Пример #6
0
        /// <summary>
        /// Inicializa uma nova instância da classe <see cref="Spartacus.Utils.File"/>.
        /// </summary>
        /// <param name='p_type'>
        /// Indica se é um arquivo ou um diretório.
        /// </param>
        /// <param name='p_completename'>
        /// Nome completo, absoluto ou relativo, do arquivo ou diretório atual.
        /// </param>
        /// <param name='p_encryptedname'>
        /// Se o nome do arquivo está criptografado ou não.
        /// </param>
        /// <param name='p_separator'>
        /// Separador de diretórios do caminho completo do arquivo.
        /// </param>
        public File(Spartacus.Utils.FileType p_type, string p_completename, bool p_encryptedname, Spartacus.Utils.PathSeparator p_separator)
        {
            Spartacus.Utils.Cryptor v_cryptor;
            string v_completename;

            if (p_encryptedname)
            {
                try
                {
                    v_cryptor = new Spartacus.Utils.Cryptor("spartacus");
                    v_completename = v_cryptor.Decrypt(p_completename);
                }
                catch (System.Exception)
                {
                    v_completename = p_completename;
                }
            }
            else
                v_completename = p_completename;

            this.v_filetype = p_type;
            this.v_pathseparator = p_separator;
            this.v_name = this.GetBaseName(v_completename);
            this.v_extension = this.GetExtension(v_completename);
            this.v_path = this.GetPath(v_completename);
            this.v_size = -1;
            this.v_encoding = System.Text.Encoding.GetEncoding("utf-8");
            this.v_protected = false;
            this.v_hidden = this.GetHidden();
        }
Пример #7
0
        public static AjaxReturn GetConnections()
        {
            AjaxReturn      v_return      = new AjaxReturn();
            ConnectionsData v_return_data = new ConnectionsData();
            Session         v_session     = (Session)System.Web.HttpContext.Current.Session ["OMNIDB_SESSION"];

            Spartacus.Utils.Cryptor v_cryptor = new Spartacus.Utils.Cryptor("omnidb_spartacus");

            if (v_session == null)
            {
                v_return.v_error    = true;
                v_return.v_error_id = 1;
                return(v_return);
            }

            System.Data.DataTable v_connections = v_session.v_omnidb_database.v_connection.Query("select * from connections where user_id = " + v_session.v_user_id + " order by dbt_st_name, conn_id", "Connections");
            System.Data.DataTable v_techs       = v_session.v_omnidb_database.v_connection.Query("select dbt_st_name from db_type", "Technologies");

            System.Collections.Generic.List <System.Collections.Generic.List <string> > v_connection_list = new System.Collections.Generic.List <System.Collections.Generic.List <string> >();
            System.Collections.Generic.List <string> v_tech_list    = new System.Collections.Generic.List <string>();
            System.Collections.Generic.List <string> v_conn_id_list = new System.Collections.Generic.List <string>();

            foreach (System.Data.DataRow v_tech in v_techs.Rows)
            {
                v_tech_list.Add(v_tech["dbt_st_name"].ToString());
            }

            int v_index = 0;

            foreach (System.Data.DataRow v_connection in v_connections.Rows)
            {
                System.Collections.Generic.List <string> v_connection_data_list = new System.Collections.Generic.List <string>();

                v_connection_data_list.Add(v_connection["dbt_st_name"].ToString());

                try
                {
                    v_connection_data_list.Add(v_cryptor.Decrypt(v_connection["server"].ToString()));
                    v_connection_data_list.Add(v_cryptor.Decrypt(v_connection["port"].ToString()));
                    v_connection_data_list.Add(v_cryptor.Decrypt(v_connection["service"].ToString()));
                    v_connection_data_list.Add(v_cryptor.Decrypt(v_connection["schema"].ToString()));
                    v_connection_data_list.Add(v_cryptor.Decrypt(v_connection["user"].ToString()));
                    v_connection_data_list.Add(v_cryptor.Decrypt(v_connection["password"].ToString()));
                }
                catch (Spartacus.Utils.Exception)
                {
                    v_connection_data_list.Add(v_connection["server"].ToString());
                    v_connection_data_list.Add(v_connection["port"].ToString());
                    v_connection_data_list.Add(v_connection["service"].ToString());
                    v_connection_data_list.Add(v_connection["schema"].ToString());
                    v_connection_data_list.Add(v_connection["user"].ToString());
                    v_connection_data_list.Add(v_connection["password"].ToString());
                }

                v_connection_data_list.Add("<img src='images/tab_close.png' class='img_ht' onclick='removeConnection(" + v_connection["conn_id"].ToString() + ")'/>" +
                                           "<img src='images/test.png' class='img_ht' onclick='testConnection(" + v_index + ")'/>");

                v_index++;

                v_connection_list.Add(v_connection_data_list);

                v_conn_id_list.Add(v_connection["conn_id"].ToString());
            }

            v_return_data.v_data         = v_connection_list;
            v_return_data.v_technologies = v_tech_list;
            v_return_data.v_conn_ids     = v_conn_id_list;

            v_return.v_data = v_return_data;
            return(v_return);
        }
Пример #8
0
        /// <summary>
        /// Substitui valores de células conforme configuração do cabeçalho, que deve estar na célula A1 e seguir formato específico.
        /// Cada planilha a princípio está em um arquivo diferente, e o arquivo resultante contém todas as planilhas de todos os arquivos.
        /// </summary>
        /// <returns>Nome do arquivo XLSX com cabeçalho aplicado em todas as planilhas.</returns>
        /// <param name="p_templatenames">Nome dos arquivo XLSX usados como templates.</param>
        private string ReplaceMarkup(System.Collections.ArrayList p_templatenames)
        {
            Spartacus.Utils.Cryptor v_cryptor;
            System.IO.FileInfo v_src;
            System.IO.FileInfo v_dst;
            string v_dstname;
            System.Data.DataTable v_table;
            string v_imagefilename;
            string v_line;
            string[] v_options;
            int k;
            System.Drawing.Bitmap v_image;
            OfficeOpenXml.Drawing.ExcelPicture v_picture;
            int v_col, v_row;
            int v_offset;
            int v_datastart = 1;
            int v_width, v_height;

            v_cryptor = new Spartacus.Utils.Cryptor("spartacus");

            v_dstname = v_cryptor.RandomString() + ".xlsx";
            v_dst = new System.IO.FileInfo(v_dstname);

            using (OfficeOpenXml.ExcelPackage v_package_dst = new OfficeOpenXml.ExcelPackage(v_dst))
            {
                for (int t = 0; t < p_templatenames.Count; t++)
                {
                    v_src = new System.IO.FileInfo((string)p_templatenames[t]);

                    using (OfficeOpenXml.ExcelPackage v_package_src = new OfficeOpenXml.ExcelPackage(v_src))
                    {
                        foreach (OfficeOpenXml.ExcelWorksheet v_worksheet_src in v_package_src.Workbook.Worksheets)
                        {
                            OfficeOpenXml.ExcelWorksheet v_worksheet = v_package_dst.Workbook.Worksheets.Add(v_worksheet_src.Name);
                            v_package_dst.Workbook.Styles.UpdateXml();

                            v_worksheet.View.ShowGridLines = v_worksheet_src.View.ShowGridLines;

                            v_table = this.v_set.Tables[v_worksheet.Name];
                            if (v_table != null && v_table.Rows.Count > 0)
                            {
                                using (System.IO.StringReader v_reader = new System.IO.StringReader(v_worksheet_src.Cells["A1"].Value.ToString()))
                                {
                                    /* EXEMPLO DE CONFIGURACAO DE MARKUP:
                                        TIPO|CAMPO|POSICAO|OPCIONAL
                                        CA||A1:AD12|
                                        CX|A:AD|11|30
                                        ST|titulo|A6|
                                        ST|filtro|A8|
                                        ST|ano|E2:J2|
                                        ST|empresa|E4:J4|
                                        FO|U10/S10|V7|
                                        TO|SUM(#)|M9|M12
                                        TO|SUBTOTAL(9,#)|M10|M12
                                        TO|SUMIF(#0,2,#1)|N10|O12;N12
                                        CF|#DBE5F1|A11:AD11|
                                        TA|A:AD|11|30
                                        IM|imagem|0:0|80;240
                                        TD|metodo,margem;qtdetotal,custototal,ajustetotal|Método,Margem,Qtde Total,Custo Total,Ajuste Total|F6
                                        FC|$W2=2|#D3D3D3|A:AD
                                     */

                                    v_line = string.Empty;
                                    k = 0;

                                    do
                                    {
                                        v_line = v_reader.ReadLine();

                                        if (v_line != null && k > 0)
                                        {
                                            v_options = v_line.Split('|');

                                            switch (v_options[0])
                                            {
                                                case "CA":
                                                    foreach (OfficeOpenXml.ExcelRangeBase v_cell in v_worksheet_src.Cells[v_options[2]])
                                                    {
                                                        // valor
                                                        v_worksheet.Cells[v_cell.Address].Value = v_worksheet_src.Cells[v_cell.Address].Value;

                                                        // alinhamento
                                                        v_worksheet.Cells[v_cell.Address].Style.VerticalAlignment = v_worksheet_src.Cells[v_cell.Address].Style.VerticalAlignment;
                                                        v_worksheet.Cells[v_cell.Address].Style.HorizontalAlignment = v_worksheet_src.Cells[v_cell.Address].Style.HorizontalAlignment;

                                                        // bordas
                                                        v_worksheet.Cells[v_cell.Address].Style.Border.Top.Style = v_worksheet_src.Cells[v_cell.Address].Style.Border.Top.Style;
                                                        v_worksheet.Cells[v_cell.Address].Style.Border.Left.Style = v_worksheet_src.Cells[v_cell.Address].Style.Border.Left.Style;
                                                        v_worksheet.Cells[v_cell.Address].Style.Border.Right.Style = v_worksheet_src.Cells[v_cell.Address].Style.Border.Right.Style;
                                                        v_worksheet.Cells[v_cell.Address].Style.Border.Bottom.Style = v_worksheet_src.Cells[v_cell.Address].Style.Border.Bottom.Style;

                                                        // padrão de cor de fundo
                                                        v_worksheet.Cells[v_cell.Address].Style.Fill.PatternType = v_worksheet_src.Cells[v_cell.Address].Style.Fill.PatternType;

                                                        // fonte
                                                        v_worksheet.Cells[v_cell.Address].Style.Font.Bold = v_worksheet_src.Cells[v_cell.Address].Style.Font.Bold;
                                                        v_worksheet.Cells[v_cell.Address].Style.Font.Italic = v_worksheet_src.Cells[v_cell.Address].Style.Font.Italic;
                                                        v_worksheet.Cells[v_cell.Address].Style.Font.Size = v_worksheet_src.Cells[v_cell.Address].Style.Font.Size;
                                                        v_worksheet.Cells[v_cell.Address].Style.Font.Family = v_worksheet_src.Cells[v_cell.Address].Style.Font.Family;
                                                        if (v_worksheet_src.Cells[v_cell.Address].Style.Font.Color.Theme == "0")
                                                            v_worksheet.Cells[v_cell.Address].Style.Font.Color.SetColor(System.Drawing.Color.White);

                                                        // formato numérico
                                                        v_worksheet.Cells[v_cell.Address].Style.Numberformat.Format = v_worksheet_src.Cells[v_cell.Address].Style.Numberformat.Format;

                                                        // quebrar texto automaticamente
                                                        v_worksheet.Cells[v_cell.Address].Style.WrapText = v_worksheet_src.Cells[v_cell.Address].Style.WrapText;

                                                        // comentários
                                                        if (v_worksheet_src.Cells[v_cell.Address].Comment != null)
                                                        {
                                                            v_worksheet.Cells[v_cell.Address].AddComment(v_worksheet_src.Cells[v_cell.Address].Comment.Text, v_worksheet_src.Cells[v_cell.Address].Comment.Author);
                                                            v_worksheet.Cells[v_cell.Address].Comment.AutoFit = true;
                                                        }
                                                    }
                                                    break;
                                                case "CX":
                                                    v_row = int.Parse(v_options[2]);
                                                    for (int i = 1; i <= v_row; i++)
                                                        v_worksheet.Row(i).Height = v_worksheet_src.Row(i).Height;
                                                    v_col = int.Parse(v_options[3]);
                                                    for (int j = 1; j <= v_col; j++)
                                                        v_worksheet.Column(j).Width = v_worksheet_src.Column(j).Width;
                                                    // passando informação para demais configurações
                                                    v_datastart = int.Parse(v_options[2]);
                                                    // passando informação para SejExcel
                                                    v_worksheet.Cells["A1"].Value = v_options[2];
                                                    break;
                                                case "ST":
                                                    v_worksheet.Cells[v_options[2]].Value = System.Net.WebUtility.HtmlDecode(v_table.Rows[0][v_options[1]].ToString());
                                                    if (v_options[2].Contains(':'))
                                                        v_worksheet.Cells[v_options[2]].Merge = true;
                                                    break;
                                                case "FO":
                                                    v_worksheet.Cells[v_options[2]].Formula = v_options[1];
                                                    break;
                                                case "IM":
                                                    try
                                                    {
                                                        v_imagefilename = v_cryptor.Decrypt(v_table.Rows[0][v_options[1]].ToString());
                                                    }
                                                    catch (Spartacus.Utils.Exception)
                                                    {
                                                        v_imagefilename = "";
                                                    }
                                                    if (v_imagefilename != "")
                                                    {
                                                        try
                                                        {
                                                            v_image = new System.Drawing.Bitmap(v_imagefilename);
                                                            v_picture = null;
                                                            if (v_image != null)
                                                            {
                                                                v_picture = v_worksheet.Drawings.AddPicture(v_imagefilename, v_image);
                                                                v_picture.SetPosition(int.Parse(v_options[2].Split(':')[0]), int.Parse(v_options[2].Split(':')[1]));

                                                                if (v_options[3].Split(';').Length > 1)
                                                                {
                                                                    v_height = int.Parse(v_options[3].Split(';')[0]);
                                                                    v_width = v_height * v_image.Width / v_image.Height;
                                                                    if (v_width > int.Parse(v_options[3].Split(';')[1]))
                                                                    {
                                                                        v_width = int.Parse(v_options[3].Split(';')[1]);
                                                                        v_height = v_width * v_image.Height / v_image.Width;
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    v_height = int.Parse(v_options[3].Split(';')[0]);
                                                                    v_width = v_height * v_image.Width / v_image.Height;
                                                                }
                                                                v_picture.SetSize(v_width, v_height);
                                                            }
                                                        }
                                                        catch (System.Exception)
                                                        {
                                                        }
                                                    }
                                                    break;
                                                case "TO":
                                                    v_worksheet.Cells [v_options[2]].Value = "";
                                                    if (v_options[3].Split(';').Length > 1)
                                                    {
                                                        k = 0;
                                                        v_worksheet.Cells [v_options[2]].Formula = v_options[1];
                                                        foreach (string v_dest in v_options[3].Split(';'))
                                                        {
                                                            v_row = v_worksheet.Cells[v_dest].Start.Row;
                                                            v_col = v_worksheet.Cells[v_dest].Start.Column;
                                                            if (v_options[1] != "")
                                                                v_worksheet.Cells [v_options[2]].Formula = v_worksheet.Cells [v_options[2]].Formula.Replace("#" + k.ToString(), v_worksheet.Cells [v_row, v_col].Address + ":" + v_worksheet.Cells [v_table.Rows.Count + v_row - 1, v_col].Address);
                                                            else
                                                                v_worksheet.Cells [v_options[2]].Formula = "SUM(" + v_worksheet.Cells [v_row, v_col].Address + ":" + v_worksheet.Cells [v_table.Rows.Count + v_row - 1, v_col].Address + ")";
                                                            k++;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        v_row = v_worksheet.Cells[v_options[3]].Start.Row;
                                                        v_col = v_worksheet.Cells[v_options[3]].Start.Column;
                                                        if (v_options[1] != "")
                                                            v_worksheet.Cells [v_options[2]].Formula = v_options[1].Replace("#", v_worksheet.Cells [v_row, v_col].Address + ":" + v_worksheet.Cells [v_table.Rows.Count + v_row - 1, v_col].Address);
                                                        else
                                                            v_worksheet.Cells [v_options[2]].Formula = "SUM(" + v_worksheet.Cells [v_row, v_col].Address + ":" + v_worksheet.Cells [v_table.Rows.Count + v_row - 1, v_col].Address + ")";
                                                    }
                                                    break;
                                                case "CF":
                                                    v_worksheet.Cells[v_options[2]].Style.Fill.BackgroundColor.SetColor(System.Drawing.ColorTranslator.FromHtml(v_options[1]));
                                                    break;
                                                case "TA":
                                                    v_row = int.Parse(v_options[2]);
                                                    for (int i = 1; i <= v_row; i++)
                                                        v_worksheet.Row(i).Height = v_worksheet_src.Row(i).Height;
                                                    v_col = int.Parse(v_options[3]);
                                                    for (int j = 1; j <= v_col; j++)
                                                        v_worksheet.Column(j).Width = v_worksheet_src.Column(j).Width;
                                                    v_worksheet.View.FreezePanes(v_row + 1, 1);
                                                    v_worksheet.Tables.Add(v_worksheet.Cells[v_options[1].Split(':')[0] + v_options[2] + ":" + v_options[1].Split(':')[1] + (v_table.Rows.Count + v_row).ToString()], v_worksheet_src.Name);
                                                    v_worksheet.Tables[0].TableStyle = OfficeOpenXml.Table.TableStyles.None;
                                                    v_worksheet.Tables[0].ShowFilter = true;
                                                    // passando informação para demais configurações
                                                    v_datastart = int.Parse(v_options[2]);
                                                    // passando informação para SejExcel
                                                    v_worksheet.Cells["A1"].Value = v_options[2];
                                                    break;
                                                case "TD":
                                                    v_worksheet.Cells[v_options[3]].LoadFromDataTable(this.CreatePivotTable(v_table, v_options[1], v_options[2]), true, OfficeOpenXml.Table.TableStyles.Medium23);
                                                    v_worksheet.Tables[v_table.TableName.Replace(' ', '_') + "_PIVOT"].ShowTotal = true;
                                                    v_offset = v_options[1].Split(';')[0].Split(',').Length;
                                                    for (int j = 0; j < v_options[1].Split(';')[1].Split(',').Length; j++)
                                                        v_worksheet.Tables[v_table.TableName.Replace(' ', '_') + "_PIVOT"].Columns[j + v_offset].TotalsRowFunction = OfficeOpenXml.Table.RowFunctions.Sum;
                                                    break;
                                                case "FC":
                                                    var v_rule = v_worksheet.ConditionalFormatting.AddExpression(new OfficeOpenXml.ExcelAddress(v_options[3].Split(':')[0] + (v_datastart + 1).ToString() + ":" + v_options[3].Split(':')[1] + (v_table.Rows.Count + v_datastart).ToString()));
                                                    v_rule.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                                                    v_rule.Style.Fill.BackgroundColor.Color = System.Drawing.ColorTranslator.FromHtml(v_options[2]);
                                                    v_rule.Formula = v_options[1];
                                                    break;
                                                default:
                                                    break;
                                            }
                                        }

                                        k++;
                                    }
                                    while (v_line != null);
                                }
                            }
                        }
                    }
                }

                v_package_dst.Save();
            }

            return v_dstname;
        }
Пример #9
0
        /// <summary>
        /// Refreshing session databases.
        /// </summary>
        public void RefreshDatabaseList()
        {
            Spartacus.Utils.Cryptor v_cryptor = new Spartacus.Utils.Cryptor("omnidb_spartacus");

            v_databases.Clear();

            // Getting connections from OmniDB database and instantiating databases.
            System.Data.DataTable v_connections = v_omnidb_database.v_connection.Query("select * " +
                                                                                       "from connections " +
                                                                                       "where user_id=" + v_user_id + " " +
                                                                                       "order by dbt_st_name, conn_id",
                                                                                       "Connections");

            int v_count = 0;

            foreach (System.Data.DataRow v_connection in v_connections.Rows)
            {
                OmniDatabase.Generic v_database;
                string v_timeout;

                try
                {
                    v_database = OmniDatabase.Generic.InstantiateDatabase(
                        v_cryptor.Decrypt(v_connection["alias"].ToString()),
                        v_connection["conn_id"].ToString(),
                        v_connection["dbt_st_name"].ToString(),
                        v_cryptor.Decrypt(v_connection["server"].ToString()),
                        v_cryptor.Decrypt(v_connection["port"].ToString()),
                        v_cryptor.Decrypt(v_connection["service"].ToString()),
                        v_cryptor.Decrypt(v_connection["user"].ToString()),
                        v_cryptor.Decrypt(v_connection["password"].ToString()),
                        v_cryptor.Decrypt(v_connection["schema"].ToString())
                        );

                    v_timeout = System.Web.Configuration.WebConfigurationManager.AppSettings ["OmniDB.Timeout." + v_connection["dbt_st_name"].ToString()].ToString();

                    if (v_timeout != "-1")
                    {
                        v_database.v_connection.SetTimeout(Convert.ToInt32(v_timeout));
                    }

                    v_database.v_connection.SetExecuteSecurity(false);

                    AddDatabase(v_database);
                }
                catch (Spartacus.Utils.Exception)
                {
                    v_database = OmniDatabase.Generic.InstantiateDatabase(
                        v_connection ["alias"].ToString(),
                        v_connection ["conn_id"].ToString(),
                        v_connection ["dbt_st_name"].ToString(),
                        v_connection ["server"].ToString(),
                        v_connection ["port"].ToString(),
                        v_connection ["service"].ToString(),
                        v_connection ["user"].ToString(),
                        v_connection ["password"].ToString(),
                        v_connection ["schema"].ToString()
                        );

                    v_timeout = System.Web.Configuration.WebConfigurationManager.AppSettings ["OmniDB.Timeout." + v_connection["dbt_st_name"].ToString()].ToString();

                    if (v_timeout != "-1")
                    {
                        v_database.v_connection.SetTimeout(Convert.ToInt32(v_timeout));
                    }

                    AddDatabase(v_database);
                }

                v_count++;
            }
        }
        /// <summary>
        /// Renderiza uma imagem no Bloco.
        /// Essa imagem precisa vir de um arquivo em disco.
        /// </summary>
        /// <param name="p_object">Objeto a ser renderizado.</param>
        /// <param name="p_posx">Posição X.</param>
        /// <param name="p_posy">Posição Y.</param>
        /// <param name="p_rightmargin">Margem direita.</param>
        /// <param name="p_pdf">Objeto PDF.</param>
        /// <param name="p_page">Página onde o objeto será renderizado.</param>
        private void RenderImage(Spartacus.Reporting.Object p_object, double p_posx, double p_posy, double p_rightmargin, PDFjet.NET.PDF p_pdf, PDFjet.NET.Page p_page)
        {
            PDFjet.NET.Image        v_image;
            System.IO.FileInfo      v_info;
            char[]                  v_ch;
            string[]                v_temp;
            Spartacus.Utils.Cryptor v_cryptor;
            string                  v_path;

            if (p_object.v_pdfobject == null)
            {
                v_ch    = new char[1];
                v_ch[0] = '.';

                v_cryptor = new Spartacus.Utils.Cryptor("spartacus");
                try
                {
                    v_path = v_cryptor.Decrypt(p_object.v_value);
                }
                catch (System.Exception)
                {
                    v_path = p_object.v_value;
                }

                v_info = new System.IO.FileInfo(v_path);
                if (v_info.Exists)
                {
                    v_temp = v_path.Split(v_ch);
                    switch (v_temp[v_temp.Length - 1].ToUpper())
                    {
                    case "BMP":
                        v_image = new PDFjet.NET.Image(p_pdf, new System.IO.FileStream(v_path, System.IO.FileMode.Open, System.IO.FileAccess.Read), PDFjet.NET.ImageType.BMP);
                        break;

                    case "JPG":
                        v_image = new PDFjet.NET.Image(p_pdf, new System.IO.FileStream(v_path, System.IO.FileMode.Open, System.IO.FileAccess.Read), PDFjet.NET.ImageType.JPG);
                        break;

                    case "JPEG":
                        v_image = new PDFjet.NET.Image(p_pdf, new System.IO.FileStream(v_path, System.IO.FileMode.Open, System.IO.FileAccess.Read), PDFjet.NET.ImageType.JPG);
                        break;

                    case "PNG":
                        v_image = new PDFjet.NET.Image(p_pdf, new System.IO.FileStream(v_path, System.IO.FileMode.Open, System.IO.FileAccess.Read), PDFjet.NET.ImageType.PNG);
                        break;

                    case "JET":
                        v_image = new PDFjet.NET.Image(p_pdf, new System.IO.FileStream(v_path, System.IO.FileMode.Open, System.IO.FileAccess.Read), PDFjet.NET.ImageType.JET);
                        break;

                    default:
                        v_image = null;
                        break;
                    }

                    if (v_image != null)
                    {
                        switch (p_object.v_align)
                        {
                        case Spartacus.Reporting.FieldAlignment.LEFT:
                            v_image.SetPosition(p_posx + p_object.v_posx, p_posy + p_object.v_posy);
                            break;

                        case Spartacus.Reporting.FieldAlignment.RIGHT:
                            v_image.SetPosition(p_page.GetWidth() - p_rightmargin - v_image.GetWidth(), p_posy + p_object.v_posy);
                            break;

                        case Spartacus.Reporting.FieldAlignment.CENTER:
                            v_image.SetPosition(p_posx + ((p_page.GetWidth() - p_rightmargin - p_posx) / 2) - (v_image.GetWidth() / 2), p_posy + p_object.v_posy);
                            break;

                        default:
                            break;
                        }
                        v_image.DrawOn(p_page);

                        p_object.v_pdfobject = v_image;
                    }
                }
            }
            else
            {
                ((PDFjet.NET.Image)p_object.v_pdfobject).DrawOn(p_page);
            }
        }
Пример #11
0
        /// <summary>
        /// Renderiza uma imagem no Bloco.
        /// Essa imagem precisa vir de um arquivo em disco.
        /// </summary>
        /// <param name="p_object">Objeto a ser renderizado.</param>
        /// <param name="p_posx">Posição X.</param>
        /// <param name="p_posy">Posição Y.</param>
        /// <param name="p_rightmargin">Margem direita.</param>
        /// <param name="p_pdf">Objeto PDF.</param>
        /// <param name="p_page">Página onde o objeto será renderizado.</param>
        private void RenderImage(Spartacus.Reporting.Object p_object, double p_posx, double p_posy, double p_rightmargin, PDFjet.NET.PDF p_pdf, PDFjet.NET.Page p_page)
        {
            PDFjet.NET.Image v_image;
            System.IO.FileInfo v_info;
            char[] v_ch;
            string[] v_temp;
            Spartacus.Utils.Cryptor v_cryptor;
            string v_path;

            if (p_object.v_pdfobject == null)
            {
                v_ch = new char[1];
                v_ch [0] = '.';

                v_cryptor = new Spartacus.Utils.Cryptor("spartacus");
                try
                {
                    v_path = v_cryptor.Decrypt(p_object.v_value);
                }
                catch (System.Exception)
                {
                    v_path = p_object.v_value;
                }

                v_info = new System.IO.FileInfo(v_path);
                if (v_info.Exists)
                {
                    v_temp = v_path.Split(v_ch);
                    switch (v_temp[v_temp.Length - 1].ToUpper())
                    {
                        case "BMP":
                            v_image = new PDFjet.NET.Image(p_pdf, new System.IO.FileStream(v_path, System.IO.FileMode.Open, System.IO.FileAccess.Read), PDFjet.NET.ImageType.BMP);
                            break;
                        case "JPG":
                            v_image = new PDFjet.NET.Image(p_pdf, new System.IO.FileStream(v_path, System.IO.FileMode.Open, System.IO.FileAccess.Read), PDFjet.NET.ImageType.JPG);
                            break;
                        case "JPEG":
                            v_image = new PDFjet.NET.Image(p_pdf, new System.IO.FileStream(v_path, System.IO.FileMode.Open, System.IO.FileAccess.Read), PDFjet.NET.ImageType.JPG);
                            break;
                        case "PNG":
                            v_image = new PDFjet.NET.Image(p_pdf, new System.IO.FileStream(v_path, System.IO.FileMode.Open, System.IO.FileAccess.Read), PDFjet.NET.ImageType.PNG);
                            break;
                        case "JET":
                            v_image = new PDFjet.NET.Image(p_pdf, new System.IO.FileStream(v_path, System.IO.FileMode.Open, System.IO.FileAccess.Read), PDFjet.NET.ImageType.JET);
                            break;
                        default:
                            v_image = null;
                            break;
                    }

                    if (v_image != null)
                    {
                        switch (p_object.v_align)
                        {
                            case Spartacus.Reporting.FieldAlignment.LEFT:
                                v_image.SetPosition(p_posx + p_object.v_posx, p_posy + p_object.v_posy);
                                break;
                            case Spartacus.Reporting.FieldAlignment.RIGHT:
                                v_image.SetPosition(p_page.GetWidth() - p_rightmargin - v_image.GetWidth(), p_posy + p_object.v_posy);
                                break;
                            case Spartacus.Reporting.FieldAlignment.CENTER:
                                v_image.SetPosition(p_posx + ((p_page.GetWidth() - p_rightmargin - p_posx) / 2) - (v_image.GetWidth() / 2), p_posy + p_object.v_posy);
                                break;
                            default:
                                break;
                        }
                        v_image.DrawOn(p_page);

                        p_object.v_pdfobject = v_image;
                    }
                }
            }
            else
                ((PDFjet.NET.Image)p_object.v_pdfobject).DrawOn(p_page);
        }