// ----------- Функции ------------- public static int DB_GetMaxLength(string table, string column) { System.Data.SqlServerCe.SqlCeCommand sqlQuery = DB.CreateQuery(); sqlQuery.CommandText = "select DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='" + table + "' and COLUMN_NAME='" + column + "'"; System.Data.SqlServerCe.SqlCeDataReader sqlReader = ExecuteReader(sqlQuery); int len = 0; if (sqlReader.Read()) { len = (int)sqlReader.GetSqlInt32(sqlReader.GetOrdinal("CHARACTER_MAXIMUM_LENGTH")); } sqlReader.Close(); return(len); }
// **** контролы **** //m_textbox1 добавить //m_textbox2 переименовать //m_combo1 source //m_combo2 destination //---------------------------------------------------------------------------------------------------- //Загрузка комбы папок void LoadFoldersToCombo(ComboBox combo) { bool is_from = (combo == m_combo1); bool is_to = (combo == m_combo2); // Сохранить SELECTOR_FOLDER... int saved__SELECTOR_FOLDER = SELECTOR_FOLDER; int saved__SELECTOR_FOLDER2 = SELECTOR_FOLDER2; bool saved__SELECTOR_FOLDER__is_enabled = SELECTOR_FOLDER__is_enabled; bool saved__SELECTOR_FOLDER2__is_enabled = SELECTOR_FOLDER2__is_enabled; // Сначала очистить: combo.Items.Clear(); combo.SelectedIndex = -1; // Теперь загрузить: //1. NULL System.Data.SqlServerCe.SqlCeCommand sqlQuery = DB.CreateQuery(); sqlQuery.CommandText = "SELECT COUNT(id) FROM Games WHERE fk_Folder_id is NULL"; object o = DB.ExecuteScalar(sqlQuery); int fid = -1; string fname = "- нет папки -"; if (o != null && o != DBNull.Value) { fname += " (" + (int)o + ")"; } int index = combo.Items.Add(new comboitem_id_name(fid, fname)); // Выбрать: if (is_from && saved__SELECTOR_FOLDER__is_enabled && saved__SELECTOR_FOLDER == fid || is_to && saved__SELECTOR_FOLDER2__is_enabled && saved__SELECTOR_FOLDER2 == fid) { combo.SelectedIndex = index; } // 2. остальные sqlQuery = DB.CreateQuery(); sqlQuery.CommandText = "SELECT f.id as [fid], f.Name as [fname], COUNT(g.id) as [fcount] FROM Folders f LEFT JOIN Games g ON f.id=g.fk_Folder_id GROUP BY f.id, f.Name ORDER BY [fname]"; System.Data.SqlServerCe.SqlCeDataReader sqlReader = DB.ExecuteReader(sqlQuery); while (sqlReader.Read()) { fid = sqlReader.IsDBNull(sqlReader.GetOrdinal("fid")) ? -1 : sqlReader.GetInt32(sqlReader.GetOrdinal("fid")); fname = ""; if (fid == -1) { fname = "- нет папки -"; } if (!sqlReader.IsDBNull(sqlReader.GetOrdinal("fname"))) { fname = sqlReader.GetString(sqlReader.GetOrdinal("fname")); } fname += " (" + (sqlReader.IsDBNull(sqlReader.GetOrdinal("fcount")) ? 0 : sqlReader.GetInt32(sqlReader.GetOrdinal("fcount"))) + ")"; index = combo.Items.Add(new comboitem_id_name(fid, fname)); // Выбрать: if (is_from && saved__SELECTOR_FOLDER__is_enabled && saved__SELECTOR_FOLDER == fid || is_to && saved__SELECTOR_FOLDER2__is_enabled && saved__SELECTOR_FOLDER2 == fid) { combo.SelectedIndex = index; } } sqlReader.Close(); }
// Загрузка 1 игры в список void Load1Game(ListViewItem lvi, System.Data.SqlServerCe.SqlCeDataReader sqlReader) { bool update = (lvi != null); //обновить существующий lvi или добавить новый? // Комментарий String str = ""; if (!sqlReader.IsDBNull(sqlReader.GetOrdinal("Comment"))) { str = sqlReader.GetString(sqlReader.GetOrdinal("Comment")).Trim(); } if (update) { lvi.Text = str; } else { lvi = m_listview_Games.Items.Add(new ListViewItem(str)); } // Дата str = ""; if (!sqlReader.IsDBNull(sqlReader.GetOrdinal("StartDate"))) { DateTime dt = sqlReader.GetDateTime(sqlReader.GetOrdinal("StartDate")); str = dt.ToString("dd.MM.yyyy HH") + "ч"; } if (update) { lvi.SubItems[1].Text = str; } else { lvi.SubItems.Add(str); } // id (тэг) if (!update) { lvi.Tag = sqlReader.GetInt32(sqlReader.GetOrdinal("id")); } // Тип GameType t = (GameType)sqlReader.GetByte(sqlReader.GetOrdinal("Type")); if (!update) { switch (t) { case GameType.Robber: lvi.SubItems.Add("Робб"); break; case GameType.Sport: lvi.SubItems.Add("Спорт"); break; case GameType.Compensat: lvi.SubItems.Add("Комп"); break; case GameType.SimpleIMP: lvi.SubItems.Add("IMP"); break; } } // Строка опций: if (!update) { ArrayOfString arrOptions = new ArrayOfString(); if (!sqlReader.IsDBNull(sqlReader.GetOrdinal("DealsInMatch"))) { arrOptions.Add(sqlReader.GetByte(sqlReader.GetOrdinal("DealsInMatch")).ToString() + "x"); } if (!sqlReader.IsDBNull(sqlReader.GetOrdinal("GameOptions"))) { byte GOptions = sqlReader.GetByte(sqlReader.GetOrdinal("GameOptions")); if (t == GameType.Robber) { bool BonusForOners = ((GOptions & 1) > 0); bool BonusForWholeRobber = ((GOptions & 2) > 0); arrOptions.Add(BonusForWholeRobber ? "за робб" : "за гейм"); if (BonusForOners) { arrOptions.Add("за онеры"); } } if (t == GameType.Compensat) { BridgeGameScoring.TypeOfCompensation CompType = (BridgeGameScoring.TypeOfCompensation)(GOptions & 3); //2 bits bool TenCardsIsTwoFits = ((GOptions & 4) > 0); //3rd bit bool LessCompFor2Fits23PC = ((GOptions & 8) > 0); //4th bit switch (CompType) { case BridgeGameScoring.TypeOfCompensation.Chicago: arrOptions.Add("чикаг"); break; case BridgeGameScoring.TypeOfCompensation.Europe: arrOptions.Add("европ"); if (TenCardsIsTwoFits) { arrOptions.Add("10 за 2"); } if (LessCompFor2Fits23PC) { arrOptions.Add("< 23-2"); } break; case BridgeGameScoring.TypeOfCompensation.Milton_York: arrOptions.Add("М-У"); break; case BridgeGameScoring.TypeOfCompensation.Moscow: arrOptions.Add("моск"); break; } } } str = ""; if (arrOptions.Count != 0) { for (int j = 0; j < arrOptions.Count; j++) { if (j > 0) { str += ", "; } str += arrOptions[j]; } } lvi.SubItems.Add(str); } // Место str = ""; if (!sqlReader.IsDBNull(sqlReader.GetOrdinal("Place"))) { str = sqlReader.GetString(sqlReader.GetOrdinal("Place")).Trim(); } if (update) { lvi.SubItems[4].Text = str; } else { lvi.SubItems.Add(str); } // Игроки str = ""; str += "N: "; if (!sqlReader.IsDBNull(sqlReader.GetOrdinal("N"))) { str += sqlReader.GetString(sqlReader.GetOrdinal("N")).Trim(); } str += ", S: "; if (!sqlReader.IsDBNull(sqlReader.GetOrdinal("S"))) { str += sqlReader.GetString(sqlReader.GetOrdinal("S")).Trim(); } str += ", E: "; if (!sqlReader.IsDBNull(sqlReader.GetOrdinal("E"))) { str += sqlReader.GetString(sqlReader.GetOrdinal("E")).Trim(); } str += ", W: "; if (!sqlReader.IsDBNull(sqlReader.GetOrdinal("W"))) { str += sqlReader.GetString(sqlReader.GetOrdinal("W")).Trim(); } if (update) { lvi.SubItems[5].Text = str; } else { lvi.SubItems.Add(str); } }
//Загрузка комбы папок void LoadFoldersToCombo(bool reload) { // Сначала очистить: m_combo_Folders.Items.Clear(); // Теперь загрузить: //1. NULL System.Data.SqlServerCe.SqlCeCommand sqlQuery = DB.CreateQuery(); sqlQuery.CommandText = "SELECT COUNT(id) FROM Games WHERE fk_Folder_id is NULL"; object o = DB.ExecuteScalar(sqlQuery); int fid = -1; string fname = "- нет папки -"; if (o != null && o != DBNull.Value) { fname += " (" + (int)o + ")"; } int index = m_combo_Folders.Items.Add(new comboitem_id_name(fid, fname)); // Выбрать: if (SELECTOR_FOLDER__is_enabled && SELECTOR_FOLDER == fid) { if (reload) { dont_react_on_folder_selection = true; } m_combo_Folders.SelectedIndex = index; if (reload) { dont_react_on_folder_selection = false; } } // 2. остальные sqlQuery = DB.CreateQuery(); sqlQuery.CommandText = "SELECT f.id as [fid], f.Name as [fname], COUNT(g.id) as [fcount] FROM Folders f LEFT JOIN Games g ON f.id=g.fk_Folder_id GROUP BY f.id, f.Name ORDER BY [fname]"; System.Data.SqlServerCe.SqlCeDataReader sqlReader = DB.ExecuteReader(sqlQuery); while (sqlReader.Read()) { fid = sqlReader.IsDBNull(sqlReader.GetOrdinal("fid")) ? -1 : sqlReader.GetInt32(sqlReader.GetOrdinal("fid")); fname = ""; if (fid == -1) { fname = "- нет папки -"; } if (!sqlReader.IsDBNull(sqlReader.GetOrdinal("fname"))) { fname = sqlReader.GetString(sqlReader.GetOrdinal("fname")); } fname += " (" + (sqlReader.IsDBNull(sqlReader.GetOrdinal("fcount")) ? 0 : sqlReader.GetInt32(sqlReader.GetOrdinal("fcount"))) + ")"; index = m_combo_Folders.Items.Add(new comboitem_id_name(fid, fname)); // Выбрать: if (SELECTOR_FOLDER__is_enabled && SELECTOR_FOLDER == fid) { if (reload) { dont_react_on_folder_selection = true; } m_combo_Folders.SelectedIndex = index; if (reload) { dont_react_on_folder_selection = false; } } } sqlReader.Close(); }