コード例 #1
0
ファイル: Program.cs プロジェクト: kbkc/wapro_export
        /// <summary>
        ///  Read data from SQL and write result to List<List<string>>
        /// </summary>
        /// <param name="conn_label"></param>
        /// <param name="connection"></param>
        /// <param name="qu"></param>
        /// <param name="add_field_name"></param>
        /// <param name="is_select_query"></param>
        /// <param name="replace_semicolon"></param>
        /// <returns></returns>
        static List <List <string> > reader_to_list(string conn_label, IDbConnection connection, string qu, Boolean add_field_name, Boolean is_select_query, Boolean replace_semicolon) //SqlConnection sqlConnection1,
        {
            List <List <string> > tmp02   = new List <List <string> >();
            List <string>         tmp01   = new List <string>();
            IDbCommand            command = connection.CreateCommand();

            command.CommandText = qu;

            try
            {
                connection.Open();

                Boolean f = true;

                if (is_select_query)
                {
                    using (IDataReader objReader = command.ExecuteReader())
                    {
                        if (!objReader.IsClosed) //.HasRows)
                        {
                            while (objReader.Read())
                            {
                                if (f && add_field_name)
                                {
                                    for (int i = 0; i < objReader.FieldCount; i++)
                                    {
                                        tmp01.Add(objReader.GetName(i).ToString());                                           // + sep;
                                    }
                                    tmp02.Add(tmp01);
                                    tmp01 = new List <string>();
                                    f     = false;
                                }
                                for (int i = 0; i < objReader.FieldCount; i++)
                                {
                                    tmp01.Add(replace_semicolon ? objReader.GetValue(i).ToString().Replace(';', ',') : objReader.GetValue(i).ToString());// + sep;
                                }
                                tmp02.Add(tmp01);
                                tmp01 = new List <string>();
                            }
                        }
                    }
                }
                else
                {
                    command.ExecuteNonQuery();
                }

                connection.Close();
            }
            catch (Exception ex)
            {
                CfgRead.mess(ex.ToString());
                CfgRead.error_flag    = true;
                CfgRead.mail_message += "\n\n* * *  " + conn_label + "connection Exception error:\n " + ex.ToString() + "\n" + connection.ConnectionString + "\n\n" + command.CommandText + "\n * * *\n";
            }
            return(tmp02);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: kbkc/wapro_export
        // public static string rest_ffname = AppDomain.CurrentDomain.BaseDirectory + "rest.csv";

        static void Main(string[] args)
        {
            // check exists error_log
            if (!File.Exists(flog))
            {
                FileStream fs = File.Create(flog); fs.Close();
            }
            try
            {
                CfgRead.mess("Hello. Wait, please");

                if (args.Length == 1)
                {
                    encrypt_arg_to_file(args[0]);
                    MessageBox.Show(args[0] + " is encrypted to " + enc_fname);
                }
                else
                {
                    // read data from .xml & proceed with startup arg
                    run_queries_from_cfg(CfgRead.start_arg01);

                    // write changed data data to .xml
                    foreach (write_params wp in CfgRead.db_list_write_params)
                    {
                        CfgRead.xml_save_node(wp);
                    }
                    // send mail (if needs)
                    CfgRead.do_mail_block(); //   do_mail_block();
                }
                CfgRead.mess("--- Job's done  ---");
            }
            catch (Exception e)
            {
                // StreamReader sr = File.OpenText(flog);
                File.AppendAllText(flog, "\n\n" + DateTime.Now.ToString() + "\n" + e.ToString());
                MessageBox.Show(e.ToString(), "Exception ERROR");
            }
            // Console.WriteLine("\n\n--- Bye, any key ---");Console.ReadKey();//.ReadLine();
        }