public updateClassModellator(MysqlClass rifClass) : base() { this.ClasseRiferimento = rifClass; this.Type = _rifClass.Name; this.AccessModifier = ListAccessModifiers.PUBLIC.Value; //public }
private void Btn_add_Click(object sender, RoutedEventArgs e) { try { if (!validate()) { return; } if (_mysql == null) { _mysql = new MysqlClass(constring); } string query = "insert into qpaper(title,_desc,dept,sem,url) values ('" + title.Text + "','" + _desc.Text + "','" + class_dept.Text + "','" + sem.Text + "','" + url_add.Text + "')"; _mysql.Execute_query(query); MessageBox.Show("Question Paper Details added sucessfully", "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Information); _mysql.CloseConnection(); _mysql = null; loadgrid(); clear(); } catch (Exception ex) { MessageBox.Show(ex.Message, "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
/// <summary> /// mysql修改操作,包括查询和更新等,失败后重试一次 /// </summary> /// <param name="MysqlClass1">MysqlClass对象</param> /// <param name="sqlstring">执行的sql语句</param> /// <returns>返回一个ExecuteNonQuery执行是否成功的bool值</returns> public bool doMysqlAlter(MysqlClass MysqlClass1, string sqlstring) { bool mysqlAlterResult = mysqlAlter(MysqlClass1, sqlstring); //第一次就成功执行 if (mysqlAlterResult) { MysqlClass1.exceptionString = null; return mysqlAlterResult; } //失败后重试一次 else { mysqlAlterResult = mysqlAlter(MysqlClass1, sqlstring); //重试后成功 if (mysqlAlterResult) { MysqlClass1.exceptionString = null; return mysqlAlterResult; } //重试后仍然失败 else { return mysqlAlterResult; } } }
private void Search_qpaper_Click(object sender, RoutedEventArgs e) { try { if (_mysql == null) { _mysql = new MysqlClass(constring); } string query = string.Empty; query = "Select * from qpaper where dept='" + search_class_dept.Text + "' and sem ='" + search_sem.Text + "'"; DataSet ds = _mysql.ExecuteQueryReturnDataset(query); if (ds != null && ds.Tables[0].Rows.Count > 0) { qpaper_grid.ItemsSource = ds.Tables[0].DefaultView; } else { MessageBox.Show("Question Paper details not found", "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Exclamation); } _mysql.CloseConnection(); _mysql = null; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public getListClassModellator(MysqlClass rifClass) : base() { _rifClass = rifClass; base.AccessModifier = ListAccessModifiers.PUBLIC.Value; //public base.Name = _rifClass.Name; }
private void Btn_update_Click(object sender, RoutedEventArgs e) { try { if (!validate()) { return; } if (_mysql == null) { _mysql = new MysqlClass(constring); } string query = "update qpaper set title = '" + title.Text + "', _desc = '" + _desc.Text + "', dept = '" + class_dept.Text + "' , sem = '" + sem.Text + "', url = '" + url_add.Text + "' where id = '" + id.Content + "'"; MessageBoxResult result = MessageBox.Show("Are you sure?, The Question paper record will be updated.", "Confirmation", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (result == MessageBoxResult.OK) { _mysql.Execute_query(query); MessageBox.Show("The Question paper Record has been updated successfully.", "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Information); } else { } _mysql.CloseConnection(); _mysql = null; loadgrid(); btn_add.IsEnabled = true; clear(); } catch (Exception ex) { MessageBox.Show(ex.Message, "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void Btn_del_Click(object sender, RoutedEventArgs e) { try { if (_mysql == null) { _mysql = new MysqlClass(constring); } string delquery = "delete from std_register where id = '" + id.Content + "'"; MessageBoxResult result = MessageBox.Show("Are you sure? The student record(" + reg_no.Text + ") will be deleted.", "Confirmation", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (result == MessageBoxResult.OK) { _mysql.Execute_query(delquery); MessageBox.Show("The Student Record has been deleted successfully.", "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Information); } else { } _mysql.CloseConnection(); _mysql = null; loadgrid(); btn_add.IsEnabled = true; clear(); } catch (Exception ex) { MessageBox.Show(ex.Message, "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Error); } }
private bool IsAlreadyRegistered(string value) { try { if (_mysql == null) { _mysql = new MysqlClass(constring); } string query = "Select * from std_register where reg_no='" + value + "'"; DataSet ds = _mysql.ExecuteQueryReturnDataset(query); if (ds != null && ds.Tables[0].Rows.Count > 0) { _mysql.CloseConnection(); _mysql = null; return(true); } _mysql.CloseConnection(); _mysql = null; } catch (Exception ex) { MessageBox.Show(ex.Message, "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Error); } return(false); }
private void Search_std_Click(object sender, RoutedEventArgs e) { try { if (_mysql == null) { _mysql = new MysqlClass(constring); } string query = string.Empty; if (!string.IsNullOrWhiteSpace(search_std_name.Text)) { query = "Select * from login where admin_name='" + search_std_name.Text + "'"; } else { MessageBox.Show("Enter Admin Name", "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } DataSet ds = _mysql.ExecuteQueryReturnDataset(query); if (ds != null && ds.Tables[0].Rows.Count > 0) { student_grid.ItemsSource = ds.Tables[0].DefaultView; } else { MessageBox.Show("Student details not found", "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Exclamation); } _mysql.CloseConnection(); _mysql = null; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public updateClassModellator(MysqlClass rifClass, String nameConnection) : base() { this.ClasseRiferimento = rifClass; this.Type = _rifClass.Name; _nameConnection = nameConnection; this.AccessModifier = ListAccessModifiers.PUBLIC.Value; //public }
public getListClassModellator(MysqlClass rifClass, String nameConnection) : base() { _rifClass = rifClass; _nameConnection = nameConnection; base.AccessModifier = ListAccessModifiers.PUBLIC.Value; //public base.Name = _rifClass.Name; }
public void loadTTGrid() { try { clearlist(); if (_mysql == null) { _mysql = new MysqlClass(constring); } string query = "Select * from timetable where course='" + class_dept.Text + "' and sem ='" + sem.Text + "'"; DataSet ds = _mysql.ExecuteQueryReturnDataset(query); if (ds != null && ds.Tables.Count > 0) { foreach (DataTable table in ds.Tables) { foreach (DataRow dr in table.Rows) { if (!day.Contains(dr.ItemArray[1].ToString())) { day.Add(dr.ItemArray[1].ToString()); } if (!classtime.Contains(dr.ItemArray[2].ToString())) { classtime.Add(dr.ItemArray[2].ToString()); } if (!subject.Contains(dr.ItemArray[5].ToString()) && dr.ItemArray[5].ToString() != string.Empty) { subject.Add(dr.ItemArray[5].ToString()); } } } if (classtime.Count != 0) { createDataTable(ds); } else { MessageBox.Show("No TimeTable Data found.", "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Exclamation); } } _mysql.CloseConnection(); _mysql = null; } catch (Exception ex) { MessageBox.Show(ex.Message, "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
private void btn_add_Click(object sender, RoutedEventArgs e) { try { string pass = getpassword(); if (!validate()) { return; } if (IsAlreadyRegistered(reg_no.Text)) { MessageBox.Show("The Student record with " + reg_no.Text + " already Exists", "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (_mysql == null) { _mysql = new MysqlClass(constring); } string query = "insert into std_register(name,reg_no,password,dept,sem,designation,ph_no,email,address,gender,dob) values ('" + std_name.Text + "','" + reg_no.Text + "','" + pass + "','" + class_dept.Text + "','" + sem.Text + "','student','" + ph_no.Text + "','" + email.Text + "','" + address.Text + "','" + gender.Text + "','" + dob.Text + "')"; _mysql.Execute_query(query); _mysql.CloseConnection(); _mysql = null; bool status = emailClass.SendEmail(email.Text, Username_emailId, "Application - Registration", "Dear " + std_name.Text + "," + message1 + "Username: "******" Password: "******"Student Detail added sucessfully", "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Information); } else { if (_mysql == null) { _mysql = new MysqlClass(constring); } string delquery = "delete from std_register where reg_no = '" + reg_no.Text + "'"; _mysql.Execute_query(delquery); _mysql.CloseConnection(); _mysql = null; MessageBox.Show("Check your internet connection", "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Error); } loadgrid(); clear(); } catch (Exception ex) { MessageBox.Show(ex.Message, "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
private bool change_pass(string query) { try { if (_mysql == null) { _mysql = new MysqlClass(constring); } _mysql.Execute_query(query); } catch (Exception ex) { MessageBox.Show(ex.Message, "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } return(true); }
/// <summary> /// 执行sql非查询操作,并输出日志到ILog1 /// </summary> /// <param name="MysqlClass1">MysqlClass对象</param> /// <param name="sqlString">sql非查询语句</param> /// <param name="businessLog">mysql执行成功时的log4net.ILog对象</param> /// <param name="errorLog">mysql执行失败时的log4net.ILog对象</param> /// <param name="logHeadString">log4net日志每一行的前面字符</param> /// <returns>mysql语句执行成功返回true,失败返回false</returns> public bool doMysqlAlterWithLog4net(MysqlClass MysqlClass1, string sqlString, log4net.ILog businessLog, log4net.ILog errorLog, string logHeadString) { lock (MysqlClass1) { bool queryResult = doMysqlAlter(MysqlClass1, sqlString); if (!queryResult) { errorLog.Info(logHeadString + "mysql插入失败:" + sqlString + ":" + MysqlClass1.exceptionString); return false; } else { businessLog.Info(logHeadString + "mysql插入成功:" + sqlString); MysqlClass1.exceptionString = null; return true; } } }
private void deleteTimeTable() { try { if (_mysql == null) { _mysql = new MysqlClass(constring); } string delquery = "delete from timetable where course ='" + class_dept.Text + "' and sem ='" + sem.Text + "'"; _mysql.Execute_query(delquery); _mysql.CloseConnection(); _mysql = null; } catch (Exception ex) { MessageBox.Show(ex.Message, "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void Btn_reset_Click(object sender, RoutedEventArgs e) { try { if (!validate()) { return; } if (_mysql == null) { _mysql = new MysqlClass(constring); } string user = ValidationFile._getusername; string password = curr_pass.Password; string query = "Select * from login where username='******' and password='******'"; DataSet dataSet = _mysql.ExecuteQueryReturnDataset(query); if (dataSet.Tables[0].Rows.Count > 0) { if (new_pass.Password != con_pass.Password) { MessageBox.Show("The new password and confirm password doesn't match.", "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Error); } else { string updatequery = "update login set password = '******' where username='******'"; if (change_pass(updatequery)) { clear(); MessageBox.Show("The password has been changed.", "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Information); } } } else { MessageBox.Show("The current password is invalid.", "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Error); } _mysql.CloseConnection(); _mysql = null; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Btn_update_Click(object sender, RoutedEventArgs e) { try { if (!validate()) { return; } if (_mysql == null) { _mysql = new MysqlClass(constring); } string query = "update std_register set name = '" + std_name.Text + "', reg_no = '" + reg_no.Text + "', dept = '" + class_dept.Text + "' , sem = '" + sem.Text + "', ph_no = '" + ph_no.Text + "', email = '" + email.Text + "', address = '" + address.Text + "', gender = '" + gender.Text + "', dob = '" + dob.Text + "' where id = '" + id.Content + "'"; MessageBoxResult result = MessageBox.Show("Are you sure? The student record(" + reg_no.Text + ") will be updated.", "Confirmation", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (result == MessageBoxResult.OK) { if (temp != reg_no.Text && IsAlreadyRegistered(reg_no.Text)) { MessageBox.Show("The Student record with " + reg_no.Text + " already Exists", "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (_mysql == null) { _mysql = new MysqlClass(constring); } _mysql.Execute_query(query); MessageBox.Show("The Student Record has been updated successfully.", "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Information); } else { } _mysql.CloseConnection(); _mysql = null; loadgrid(); btn_add.IsEnabled = true; clear(); } catch (Exception ex) { MessageBox.Show(ex.Message, "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Error); } }
public bool addTimeTable(string day, string time, string cls, string sem, string sub, string staffid) { try { if (_mysql == null) { _mysql = new MysqlClass(constring); } string query = "insert into timetable(day,time,course,sem,subject,staffid) values ('" + day + "','" + time + "','" + cls + "','" + sem + "','" + sub + "','" + staffid + "')"; _mysql.Execute_query(query); _mysql.CloseConnection(); _mysql = null; } catch (Exception ex) { MessageBox.Show(ex.Message, "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Stop); return(false); } return(true); }
public void loadgrid() { try { if (_mysql == null) { _mysql = new MysqlClass(constring); } string query = "Select * from std_register where designation='student' order by id desc"; DataSet ds = _mysql.ExecuteQueryReturnDataset(query); if (ds != null && ds.Tables.Count > 0) { student_grid.ItemsSource = ds.Tables[0].DefaultView; } _mysql.CloseConnection(); _mysql = null; } catch (Exception ex) { MessageBox.Show(ex.Message, "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
private void Search_std_Click(object sender, RoutedEventArgs e) { try { if (_mysql == null) { _mysql = new MysqlClass(constring); } string query = string.Empty; if (search_std_name.Text != string.Empty && search_class_dept.SelectedIndex != 0 && search_sem.SelectedIndex != 0) { query = "Select * from std_register where dept='" + search_class_dept.Text + "' and sem ='" + search_sem.Text + "' and name='" + search_std_name.Text + "' or reg_no ='" + search_std_name.Text + "' and designation = 'student'"; } else if (search_std_name.Text != string.Empty && search_class_dept.SelectedIndex == 0 && search_sem.SelectedIndex == 0) { query = "Select * from std_register where name='" + search_std_name.Text + "' and designation = 'student'"; } else { query = "Select * from std_register where dept='" + search_class_dept.Text + "' and sem ='" + search_sem.Text + "' and designation = 'student'"; } DataSet ds = _mysql.ExecuteQueryReturnDataset(query); if (ds != null && ds.Tables[0].Rows.Count > 0) { student_grid.ItemsSource = ds.Tables[0].DefaultView; } else { MessageBox.Show("Student details not found", "St. Anne's Admin DashBoard", MessageBoxButton.OK, MessageBoxImage.Exclamation); } _mysql.CloseConnection(); _mysql = null; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 以默认的mysql.xml初始化mysql连接 /// </summary> /// <param name="xmlPath">mysql.xml的地址</param> /// <returns>返回MySqlClass对象</returns> public MysqlClass initMysqlByDefaultXml(string xmlPath) { MysqlClass MysqlClass1 = new MysqlClass(); XmlDocument xd = new XmlDocument(); try { xd.Load(xmlPath); } catch (Exception e) { MysqlClass1.exceptionString = e.Message; return MysqlClass1; } string Server = xd.SelectSingleNode("//mysql").SelectSingleNode("Server").InnerText; string Port = xd.SelectSingleNode("//mysql").SelectSingleNode("Port").InnerText; string Database = xd.SelectSingleNode("//mysql").SelectSingleNode("Database").InnerText; string Uid = xd.SelectSingleNode("//mysql").SelectSingleNode("Uid").InnerText; string Pwd = xd.SelectSingleNode("//mysql").SelectSingleNode("Pwd").InnerText; string CharSet = xd.SelectSingleNode("//mysql").SelectSingleNode("CharSet").InnerText; string netConnectionStrings = buildNetConnectionStrings(Server, Port, Database, Uid, Pwd, CharSet); MysqlClass1 = mysqlInit(netConnectionStrings); return MysqlClass1; }
/// <summary> /// mysql连接初始化 /// </summary> /// <param name="netConnectionStrings">mysql连接字符串</param> /// <returns>返回MysqlClass对象</returns> public MysqlClass mysqlInit(string netConnectionStrings) { MysqlClass MysqlClass1 = new MysqlClass(); MySqlConnection MySqlConnection1 = new MySql.Data.MySqlClient.MySqlConnection(netConnectionStrings); try { MySqlConnection1.Open(); MysqlClass1.MySqlConnection1 = MySqlConnection1; MysqlClass1.netConnectionStrings = netConnectionStrings; MysqlClass1.exceptionString = null; return MysqlClass1; } catch (Exception e) { MysqlClass1.exceptionString = e.Message; return MysqlClass1; } }
/// <summary> /// mysql查询操作 /// </summary> /// <param name="MysqlClass1">MysqlClass对象</param> /// <param name="sqlstring">sql语句</param> /// <returns>返回List List string 的结果</returns> public List<List<string>> mysqlSelect(MysqlClass MysqlClass1, string sqlstring) { List<List<string>> result = new List<List<string>>(); lock (MysqlClass1) { string netConnectionStrings = MysqlClass1.netConnectionStrings; //将mysql中的数据读取到dataset MySqlDataAdapter MySqlDataAdapter1 = new MySqlDataAdapter(sqlstring, netConnectionStrings); DataSet DataSet1 = new DataSet(); try { MySqlDataAdapter1.Fill(DataSet1); } catch (Exception e) { DataSet1.Dispose(); MySqlDataAdapter1.Dispose(); MysqlClass1.exceptionString = e.Message; return null; } //判断是否有结果 if (DataSet1.Tables[0].Rows.Count != 0) { //遍历dataset中的所有数据 for (int i = 0; i < DataSet1.Tables[0].Rows.Count; i++) { List<string> rowtemp = new List<string>(); for (int j = 0; j < DataSet1.Tables[0].Columns.Count; j++) { rowtemp.Add(DataSet1.Tables[0].Rows[i][j].ToString()); } result.Add(rowtemp); } } //释放资源 DataSet1.Dispose(); MySqlDataAdapter1.Dispose(); MysqlClass1.exceptionString = null; } return result; }
/// <summary> /// mysql查询操作 /// </summary> /// <param name="MysqlClass1">MysqlClass对象</param> /// <param name="sqlstring">sql语句</param> /// <returns>返回System.Data.DataTable的结果</returns> public DataTable mysqlSelectToDataSet(MysqlClass MysqlClass1, string sqlstring) { string netConnectionStrings = MysqlClass1.netConnectionStrings; DataTable DataTable1 = new DataTable(); lock (MysqlClass1) { //将mysql中的数据读取到dataset MySqlDataAdapter MySqlDataAdapter1 = new MySqlDataAdapter(sqlstring, netConnectionStrings); DataSet DataSet1 = new DataSet(); try { MySqlDataAdapter1.SelectCommand.CommandTimeout = 36000; MySqlDataAdapter1.Fill(DataSet1); } catch (Exception e) { DataSet1.Dispose(); MySqlDataAdapter1.Dispose(); MysqlClass1.exceptionString = e.Message; return null; } DataTable1 = DataSet1.Tables[0]; MysqlClass1.exceptionString = null; //释放资源 DataSet1.Dispose(); MySqlDataAdapter1.Dispose(); } return DataTable1; }
/// <summary> /// mysql查询操作 /// </summary> /// <param name="MysqlClass1">MysqlClass对象</param> /// <param name="sqlCommand">sql语句</param> /// <param name="businessLog">mysql执行成功时的log4net.ILog对象</param> /// <param name="errorLog">mysql执行失败时的log4net.ILog对象</param> /// <param name="logHeadString">log4net日志每一行的前面字符</param> /// <returns>成功返回指定的json(按查询结果的行构建),失败返回null</returns> public string doMysqlSelectToRowsJsonWithLog4net(MysqlClass MysqlClass1, string sqlCommand, log4net.ILog businessLog, log4net.ILog errorLog, string logHeadString) { string result = null; DataTable DataTable1 = mysqlSelectToDataSet(MysqlClass1, sqlCommand); if (MysqlClass1.exceptionString != null) { errorLog.Info(logHeadString + "mysql查询失败:" + sqlCommand + ":" + MysqlClass1.exceptionString); return result; } businessLog.Info(logHeadString + "mysql查询成功:" + sqlCommand); StringBuilder jsonStringBuilder = new StringBuilder(); jsonStringBuilder.Append("["); for (int i = 0; i < DataTable1.Rows.Count; i++) { jsonStringBuilder.Append("["); for (int j = 0; j < DataTable1.Columns.Count; j++) { jsonStringBuilder.Append("\"" + DataTable1.Rows[i][j].ToString() + "\","); } //移除最后的逗号 if (jsonStringBuilder.ToString().Substring(jsonStringBuilder.Length - 1) == ",") { jsonStringBuilder.Remove(jsonStringBuilder.Length - 1, 1); } jsonStringBuilder.Append("],"); } //移除最后的逗号 if (jsonStringBuilder.ToString().Substring(jsonStringBuilder.Length - 1) == ",") { jsonStringBuilder.Remove(jsonStringBuilder.Length - 1, 1); } jsonStringBuilder.Append("]"); result = jsonStringBuilder.ToString(); MysqlClass1.exceptionString = null; return result; }
public MysqlManagerClassModellator(String OutputNameClass, MysqlClass MysqlClassRiferimento) : base(OutputNameClass) { this.inizializzaClasse(MysqlClassRiferimento); }
public MysqlManagerClassModellator(MysqlClass MysqlClassRiferimento) : base() { this.inizializzaClasse(MysqlClassRiferimento); }
/// <summary> /// mysql查询操作 /// </summary> /// <param name="MysqlClass1">MysqlClass对象</param> /// <param name="sqlString">sql语句</param> /// <param name="businessLog">mysql执行成功时的log4net.ILog对象</param> /// <param name="errorLog">mysql执行失败时的log4net.ILog对象</param> /// <param name="logHeadString">log4net日志每一行的前面字符</param> /// <returns>返回DataTable类型的结果</returns> public DataTable doMysqlSelectToDataSetWithLog4net(MysqlClass MysqlClass1, string sqlString, log4net.ILog businessLog, log4net.ILog errorLog, string logHeadString) { DataTable DataTable1 = mysqlSelectToDataSet(MysqlClass1, sqlString); if (MysqlClass1.exceptionString != null) { errorLog.Info(logHeadString + "mysql查询失败:" + sqlString + ":" + MysqlClass1.exceptionString); return null; } businessLog.Info(logHeadString + "mysql查询成功:" + sqlString); MysqlClass1.exceptionString = null; return DataTable1; }
private void inizializzaClasse(MysqlClass MysqlClassRiferimento) { base.ListUsing.Add(Environment.NewLine); this.MysqlClassRiferimento = MysqlClassRiferimento; this.Name = "Manager_" + _mysqlClassRiferimento.Name; this.NameSpace = _mysqlClassRiferimento.NameSpace + ".Manager"; base.AccessModifier = ListAccessModifiers.PUBLIC_PARTIAL.Value; this.setProperty(); this.setListaFunzioni(_mysqlClassRiferimento); this.DriverUsed = TypeOfDriver.MySqlDriver; this.addUsing(); }
private void setListaFunzioni(MysqlClass MysqlClassRiferimento) { _getClassModellator = new getClassModellator(MysqlClassRiferimento,"this._connection"); _getClassModellator = new getClassModellator(MysqlClassRiferimento, "this._connection"); _getListClassModellator = new getListClassModellator(MysqlClassRiferimento, "this._connection"); _insertClassModellator = new insertClassModellator(MysqlClassRiferimento, "this._connection"); _deleteClassModellator = new deleteClassModellator(MysqlClassRiferimento, "this._connection"); _updateClassModellator = new updateClassModellator(MysqlClassRiferimento, "this._connection"); _createTableModellator = new createTableModellator(MysqlClassRiferimento, "this._connection"); }
/// <summary> /// mysql修改操作,包括查询和更新等 /// </summary> /// <param name="MysqlClass1">MysqlClass对象</param> /// <param name="sqlstring">执行的sql语句</param> /// <returns>返回一个ExecuteNonQuery执行是否成功的bool值</returns> private bool mysqlAlter(MysqlClass MysqlClass1, string sqlstring) { MySqlConnection MySqlConnection1 = MysqlClass1.MySqlConnection1; string netConnectionStrings = MysqlClass1.netConnectionStrings; //如果mysql连接失效,就重新初始化连接 if (MySqlConnection1 == null || MySqlConnection1.State == System.Data.ConnectionState.Closed || MySqlConnection1.State == System.Data.ConnectionState.Broken) { if (MySqlConnection1 != null) { MySqlConnection1.Close(); MySqlConnection1.Dispose(); } //判断mysql连接失效后,mysql初始化是否失败 MysqlClass1 = mysqlInit(netConnectionStrings); if (MysqlClass1.exceptionString != null) { return false; } //成功后赋值MySqlConnection1 MySqlConnection1 = MysqlClass1.MySqlConnection1; } //执行指定的sql lock (MysqlClass1) { MySqlCommand MySqlCommand1 = MySqlConnection1.CreateCommand(); MySqlCommand1.CommandText = sqlstring; try { MySqlCommand1.ExecuteNonQuery(); MysqlClass1.exceptionString = null; return true; } catch (Exception e) { MySqlConnection1.Close(); MySqlConnection1.Dispose(); MySqlCommand1.Dispose(); MysqlClass1.exceptionString = e.Message; return false; } } }