public RaiderRoundMetaDataInfo AddNewRaiderRoundMetaDataInfo(RaiderRoundMetaDataInfo roundInfo) { MySqlConnection myconn = null; MySqlCommand mycmd = null; try { myconn = MyDBHelper.Instance.CreateConnection(); myconn.Open(); //1. Save to DB string sqlTextA = "insert into raiderroundmetadatainfo (`State`) values ( @State) ;"; mycmd = myconn.CreateCommand(); mycmd.CommandText = sqlTextA; mycmd.Parameters.AddWithValue("@State", (int)roundInfo.State); mycmd.ExecuteNonQuery(); mycmd.Dispose(); //2. Select from DB string sqlTextB = "SELECT * FROM raiderroundmetadatainfo order by id desc limit 1; "; mycmd = myconn.CreateCommand(); mycmd.CommandText = sqlTextB; DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(mycmd); adapter.Fill(table); var roundInfos = MetaDBAdapter <RaiderRoundMetaDataInfo> .GetRaiderRoundMetaDataInfoFromDataTable(table); table.Clear(); table.Dispose(); adapter.Dispose(); if (roundInfos == null || roundInfos.Length == 0) { return(null); } return(roundInfos[0]); } finally { if (mycmd != null) { mycmd.Dispose(); } MyDBHelper.Instance.DisposeConnection(myconn); } }
public RaiderRoundMetaDataInfo[] GetHistoryRaiderRoundRecords(int pageItemCount, int pageIndex) { MySqlConnection myconn = null; MySqlCommand mycmd = null; try { myconn = MyDBHelper.Instance.CreateConnection(); string sqlTextA = "SELECT * FROM raiderroundmetadatainfo where State = @State "; string sqlOrderLimit = " order by id desc "; if (pageItemCount > 0) { int start = pageIndex <= 0 ? 0 : (pageIndex - 1) * pageItemCount; sqlOrderLimit += " limit " + start.ToString() + ", " + pageItemCount; } string sqlAllText = sqlTextA + sqlOrderLimit; mycmd = myconn.CreateCommand(); mycmd.CommandText = sqlAllText; mycmd.Parameters.AddWithValue("@State", (int)RaiderRoundState.Finished); myconn.Open(); DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(mycmd); adapter.Fill(table); var lists = MetaDBAdapter <RaiderRoundMetaDataInfo> .GetRaiderRoundMetaDataInfoFromDataTable(table); table.Clear(); table.Dispose(); adapter.Dispose(); return(lists); } finally { if (mycmd != null) { mycmd.Dispose(); } if (myconn != null) { myconn.Close(); myconn.Dispose(); } } }
public RaiderRoundMetaDataInfo GetLastRaiderRoundMetaDataInfo() { MySqlConnection myconn = null; MySqlCommand mycmd = null; try { myconn = MyDBHelper.Instance.CreateConnection(); string sqlText = "SELECT * FROM raiderroundmetadatainfo order by id desc limit 1; "; mycmd = myconn.CreateCommand(); mycmd.CommandText = sqlText; myconn.Open(); DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(mycmd); adapter.Fill(table); var roundInfos = MetaDBAdapter <RaiderRoundMetaDataInfo> .GetRaiderRoundMetaDataInfoFromDataTable(table); table.Clear(); table.Dispose(); adapter.Dispose(); if (roundInfos == null || roundInfos.Length == 0) { return(null); } return(roundInfos[0]); } finally { if (mycmd != null) { mycmd.Dispose(); } if (myconn != null) { myconn.Close(); myconn.Dispose(); } } }