public bool Insert_OutFallInfo(ref COutFallInfo outfall) { MySqlDataReader reader; string strcmd = "INSERT INTO [OutFallInfo] ([SystemID],[X_Coor],[Y_Coor],[ReceiveWater],[Category],[IsFlap],[BotEle]," + "[OutFallType],[DataSource],[Record_Date],[ReportDept],[ReportDate])" + "values(" + "'" + outfall.SystemID + "','" + outfall.X_Coor + "','" + outfall.Y_Coor + "','" + outfall.ReceiveWater + "'," + outfall.Category + " , " + Convert.ToInt32(outfall.IsFlap) + " ,'" + outfall.BotEle + "', " + outfall.OutFallType + " , " + outfall.DataSource + " ,#" + Convert.ToString(outfall.Record_Date) + "#,'" + outfall.ReportDept + "',#" + Convert.ToString(outfall.ReportDate) + "#)"; try { connect.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = connect; cmd.CommandType = CommandType.Text; cmd.CommandText = strcmd; strcmd = "SELECT MAX([ID]) AS MAXID FROM [OutFallInfo]"; cmd.ExecuteNonQuery(); cmd.CommandText = strcmd; reader = cmd.ExecuteReader(); reader.Read(); outfall.ID = Convert.ToInt32(reader[0].ToString()); } catch (System.Exception ex) { Console.WriteLine(ex.Message); return false; } finally { connect.Close(); } return true; }
public bool Delete_OutFallExtInfo(COutFallInfo outfall) { List <string> listcmd = new List <string>(); try { string cmd = "DELETE * FROM [OutFallInfo] where ID = " + outfall.ID; listcmd.Add(cmd); ExectueCmd(listcmd); } catch (System.Exception ex) { Console.WriteLine(ex.Message); return(false); } return(true); }
/// <summary> /// 插入出水口信息,同时添加出水口附加信息,若不存在则创建新信息 /// </summary> /// <returns></returns> private bool DoInsert() { TOutFallInfo outinfo = new TOutFallInfo(_dbpath, PassWord); TOutFallExtInfo outextinfo = new TOutFallExtInfo(_dbpath, PassWord); if (OutList == null || OutList.Count <= 0) { return(false); } int count = 0; foreach (COutFallInfo info in OutList) { COutFallInfo tmp = info; if (!outinfo.Insert_OutFallInfo(ref tmp)) { continue; } COutFallExtInfo extmp = null; if (OutExtList == null) { extmp = new COutFallExtInfo(); } else { if (count < OutExtList.Count) { extmp = OutExtList.ElementAt(count); } else { extmp = new COutFallExtInfo(); } } extmp.OutFallID = tmp.ID; outextinfo.Insert_OutFallExtInfo(ref extmp); count++; } if (count <= 0) { return(false); } return(true); }
public bool Insert_OutFallInfo(ref COutFallInfo outfall) { MySqlDataReader reader; string strcmd = "INSERT INTO [OutFallInfo] ([SystemID],[X_Coor],[Y_Coor],[ReceiveWater],[Category],[IsFlap],[BotEle]," + "[OutFallType],[DataSource],[Record_Date],[ReportDept],[ReportDate])" + "values(" + "'" + outfall.SystemID + "','" + outfall.X_Coor + "','" + outfall.Y_Coor + "','" + outfall.ReceiveWater + "'," + outfall.Category + " , " + Convert.ToInt32(outfall.IsFlap) + " ,'" + outfall.BotEle + "', " + outfall.OutFallType + " , " + outfall.DataSource + " ,#" + Convert.ToString(outfall.Record_Date) + "#,'" + outfall.ReportDept + "',#" + Convert.ToString(outfall.ReportDate) + "#)"; try { connect.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = connect; cmd.CommandType = CommandType.Text; cmd.CommandText = strcmd; strcmd = "SELECT MAX([ID]) AS MAXID FROM [OutFallInfo]"; cmd.ExecuteNonQuery(); cmd.CommandText = strcmd; reader = cmd.ExecuteReader(); reader.Read(); outfall.ID = Convert.ToInt32(reader[0].ToString()); } catch (System.Exception ex) { Console.WriteLine(ex.Message); return(false); } finally { connect.Close(); } return(true); }
private List <COutFallInfo> Select(string cmd) { List <COutFallInfo> listout = new List <COutFallInfo>(); MySqlCommand com; MySqlDataReader reader; try { connect.Open(); com = new MySqlCommand(cmd, connect); reader = com.ExecuteReader(); while (reader.Read()) { COutFallInfo outfall = new COutFallInfo(); int i = 0; string tmp; outfall.ID = Convert.ToInt32(reader[i++].ToString()); outfall.SystemID = reader[i++].ToString(); tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) { outfall.X_Coor = Convert.ToDouble(tmp); } tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) { outfall.Y_Coor = Convert.ToDouble(tmp); } outfall.ReceiveWater = reader[i++].ToString(); tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) { outfall.Category = Convert.ToInt32(tmp); } tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) { outfall.IsFlap = Convert.ToBoolean(tmp); } tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) { outfall.BotEle = Convert.ToDouble(tmp); } tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) { outfall.OutFallType = Convert.ToInt32(tmp); } tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) { outfall.DataSource = Convert.ToInt32(tmp); } tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) { outfall.Record_Date = Convert.ToDateTime(tmp); } outfall.ReportDept = reader[i++].ToString(); tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) { outfall.ReportDate = Convert.ToDateTime(tmp); } listout.Add(outfall); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); return(null); } finally { connect.Close(); } return(listout); }
public bool Delete_OutFallExtInfo(COutFallInfo outfall) { List<string> listcmd = new List<string>(); try { string cmd = "DELETE * FROM [OutFallInfo] where ID = " + outfall.ID; listcmd.Add(cmd); ExectueCmd(listcmd); } catch (System.Exception ex) { Console.WriteLine(ex.Message); return false; } return true; }
private List<COutFallInfo> Select(string cmd) { List<COutFallInfo> listout = new List<COutFallInfo>(); MySqlCommand com; MySqlDataReader reader; try { connect.Open(); com = new MySqlCommand(cmd, connect); reader = com.ExecuteReader(); while (reader.Read()) { COutFallInfo outfall = new COutFallInfo(); int i = 0; string tmp; outfall.ID = Convert.ToInt32(reader[i++].ToString()); outfall.SystemID = reader[i++].ToString(); tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) outfall.X_Coor = Convert.ToDouble(tmp); tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) outfall.Y_Coor = Convert.ToDouble(tmp); outfall.ReceiveWater = reader[i++].ToString(); tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) outfall.Category = Convert.ToInt32(tmp); tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) outfall.IsFlap = Convert.ToBoolean(tmp); tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) outfall.BotEle = Convert.ToDouble(tmp); tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) outfall.OutFallType = Convert.ToInt32(tmp); tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) outfall.DataSource = Convert.ToInt32(tmp); tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) outfall.Record_Date = Convert.ToDateTime(tmp); outfall.ReportDept = reader[i++].ToString(); tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) outfall.ReportDate = Convert.ToDateTime(tmp); listout.Add(outfall); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); return null; } finally { connect.Close(); } return listout; }