Example #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            welcome_form form = new welcome_form();

            Application.Run(form);

            //form.ShowDialog();
            data_process _form = new data_process();

            Application.Run(_form);
            //_form.ShowDialog();
        }
Example #2
0
        public int Select(string table_name,
                          string column_name,
                          process_html_text_callback callback,
                          data_process context)
        {
            int  ret  = 0;
            int  _ret = 0;
            bool __ret;

            Int32           read_row_count;
            Int32           _row_count = 0;
            Int32           row_index  = 0;
            Int32           _row_index;
            string          query;
            MySqlCommand    cmd;
            MySqlDataReader dataReader;

            string[] datas;
            string[] ids;

            do
            {
                if (column_name.Length == 0)
                {
                    ret = -1;
                    break;
                }

                if (this.OpenConnection() != true)
                {
                    break;
                }

                query  = "SELECT COUNT(*) FROM ";
                query += table_name;

                cmd        = new MySqlCommand(query, connection);
                dataReader = cmd.ExecuteReader();
                cmd.Parameters.Clear();

                do
                {
                    _ret = 0;
                    try
                    {
                        __ret = dataReader.Read();

                        if (__ret == false)
                        {
                            _ret = -1;
                            break;
                        }
                    }
                    catch (MySqlException ex)
                    {
                        _ret = -1;

                        //When handling errors, you can your application's response based on the error number.
                        //The two most common error numbers when connecting are as follows:
                        //0: Cannot connect to server.
                        //1045: Invalid user name and/or password.

                        System.Diagnostics.Debug.WriteLine(string.Format("execuate sql error {0} {1}\n", ex.Number, ex.Message));
                    }

                    if (_ret < 0)
                    {
                        break;
                    }

                    _row_count = dataReader.GetInt32(0);
                }while(false);

                dataReader.Close();
                this.CloseConnection();

                row_index = 0;

                if (row_index >= _row_count)
                {
                    break;
                }

                datas = new string[ROW_COUNT_ONCE];
                ids   = new string[ROW_COUNT_ONCE];

                for ( ; ;)
                {
                    if (row_index >= _row_count)
                    {
                        break;
                    }

                    if (this.OpenConnection() != true)
                    {
                        break;
                    }

                    query  = "SELECT * FROM ";
                    query += table_name;
                    query += " ";
                    query += "LIMIT ";
                    query += row_index.ToString();
                    query += ",";

                    if ((_row_count - row_index) < ROW_COUNT_ONCE)
                    {
                        read_row_count = _row_count - row_index;
                    }
                    else
                    {
                        read_row_count = ROW_COUNT_ONCE;
                    }

                    query += read_row_count.ToString();
                    query += ";";

                    cmd = new MySqlCommand(query, connection);

                    dataReader = cmd.ExecuteReader();
                    cmd.Parameters.Clear();

                    _row_index = 0;

                    for ( ; ;)
                    {
                        do
                        {
                            _ret = 0;

                            try
                            {
                                __ret = dataReader.Read();

                                if (__ret == false)
                                {
                                    _ret = -1;
                                    break;
                                }
                            }
                            catch (MySqlException ex)
                            {
                                _ret = -1;
                                System.Diagnostics.Debug.WriteLine(string.Format("execuate sql error {0} {1}\n", ex.Number, ex.Message));
                            }
                        }while(false);

                        if (_ret == -1)
                        {
                            break;
                        }

                        ids[_row_index]   = dataReader["id"].ToString();
                        datas[_row_index] = dataReader[column_name].ToString();
                        _row_index       += 1;
                    }

                    dataReader.Close();
                    this.CloseConnection();

                    for (Int32 i = 0; i < _row_index; i++)
                    {
                        _ret = callback(ids[i], datas[i].ToString(), context);
                        if (_ret == STOP_DATA_BASE_PROCESS)
                        {
                            break;
                        }
                    }

                    if (_ret == STOP_DATA_BASE_PROCESS)
                    {
                        break;
                    }

                    row_index += ROW_COUNT_ONCE;;
                }
            } while (false);

            return(ret);
        }