Exemplo n.º 1
0
        private void ProcessSave(QueryInfo query_info)
        {
            //先收集数据
            List <List <string> > list_result = new List <List <string> >();

            for (int row = 0; row < m_find_result.Rows.Count; ++row)
            {
                List <string> list = new List <string>();
                for (int col = 0; col < m_find_result.Columns.Count; col++)
                {
                    string value = m_find_result.Rows[row].Cells[col].Value as string;
                    list.Add(value);
                }
                list_result.Add(list);
            }

            //序列化
            ByteArray by = new ByteArray(1024 * 8, int.MaxValue);

            for (int row = 0; row < list_result.Count; ++row)
            {
                int           start_pos       = by.Tail;
                List <string> list_row_result = list_result[row];
                for (int col = 0; col < m_list_bin_header.Count; ++col)
                {
                    BinHeader header_info = m_list_bin_header[col];
                    string    value       = list_row_result[col];
                    switch (header_info.type)
                    {
                    case "int":
                        if (value.Length == 0)
                        {
                            value = "0";
                        }
                        long   l = long.Parse(value);
                        byte[] b = BitConverter.GetBytes(l);
                        by.Write(b, header_info.length);
                        break;

                    case "uint":
                        if (value.Length == 0)
                        {
                            value = "0";
                        }
                        ulong ul = ulong.Parse(value);
                        b = BitConverter.GetBytes(ul);
                        by.Write(b, header_info.length);
                        break;

                    case "float":
                        if (value.Length == 0)
                        {
                            value = "0";
                        }
                        float f = float.Parse(value);
                        b = BitConverter.GetBytes(f);
                        by.Write(b, header_info.length);
                        break;

                    case "double":
                        if (value.Length == 0)
                        {
                            value = "0";
                        }
                        double d = double.Parse(value);
                        b = BitConverter.GetBytes(d);
                        by.Write(b, header_info.length);
                        break;

                    case "string":
                        by.WriteString(value);
                        break;

                    default: continue;
                    }
                }
                if (query_info.fixed_length > 0)
                {
                    by.WriteEmpty(query_info.fixed_length - (by.Tail - start_pos));
                }
            }

            //保存到db
            string key_sql = query_info.sql_key_value;

            if (query_info.sql_key_type == 1)
            {
                key_sql = "'" + key_sql + "'";
            }

            string sql = "replace into `" + query_info.table_name + "`" +
                         "(`" + query_info.sql_key_name + "`,`" + query_info.field_name + "`) " +
                         "values (" +
                         key_sql + "," +
                         "@bin_data)";

            List <MySqlParameter> param = new List <MySqlParameter>();
            MySqlParameter        p     = Database.MakeMysqlParam("@bin_data", query_info.bin_type, by.GetBuffer(), by.Available);

            param.Add(p);
            DatabaseManager.Instance.GetDB(query_info.db_type).Execute(sql, param);
        }
Exemplo n.º 2
0
        private void OnFieldConfigSelectedIndexChanged(object sender, EventArgs e)
        {
            int index = m_field_config_list.SelectedIndex;

            if (index < 0 || index >= ServerConfig.info.field_list.Count)
            {
                return;
            }

            m_field_list.Items.Clear();
            m_list_bin_header.Clear();

            ServerNetInfo.FieldItems field_info = ServerConfig.info.field_list[index];
            string str_fields = field_info.fields;

            if (string.IsNullOrEmpty(str_fields))
            {
                return;
            }

            string[] arr_fields = str_fields.Split(',');
            if (arr_fields == null || arr_fields.Length == 0)
            {
                return;
            }

            //显示当前配置表字段
            for (int i = 0; i < arr_fields.Length; ++i)
            {
                string str_field = arr_fields[i];
                if (string.IsNullOrEmpty(str_field))
                {
                    continue;
                }

                string[] arr_field = str_field.Split('|');
                if (arr_field == null || arr_field.Length == 0 || arr_field.Length >= 3)
                {
                    continue;
                }

                string str_name = "";
                int    length   = 0;
                if (arr_field.Length == 2)
                {
                    str_name = arr_field[0] + "_" + arr_field[1];
                    length   = int.Parse(arr_field[1]);
                }
                else
                {
                    str_name = arr_field[0];
                }

                m_field_list.Items.Add(str_name);
                m_list_bin_header.Add(new BinHeader(arr_field[0], length));
            }

            //查询结果标题
            m_find_result.Columns.Clear();
            for (int i = 0; i < m_list_bin_header.Count; ++i)
            {
                BinHeader header_info = m_list_bin_header[i];
                string    str_name    = header_info.type;
                if (header_info.length > 0)
                {
                    str_name += "_" + header_info.length;
                }
                this.m_find_result.Columns.Add(i.ToString(), str_name);
            }
            for (int i = 0; i < this.m_find_result.Columns.Count; i++)
            {
                this.m_find_result.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
            }


            ClearFind();
        }