public User getUser(string code) { try { OpenConnection(); MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(User.GetByExactCodeSQL(code)); cmd.Connection = m_connection; MySql.Data.MySqlClient.MySqlDataReader r = cmd.ExecuteReader(); User u = User.TransformReader(r); r.Close(); if (u == null) { return(null); } FormAccess p = new FormAccess(); MySql.Data.MySqlClient.MySqlCommand aCommand = new MySql.Data.MySqlClient.MySqlCommand(FormAccess.GetAllByUserSQL(u.ID), m_connection); MySql.Data.MySqlClient.MySqlDataReader aReader = aCommand.ExecuteReader(); IList a = p.GetAll(aReader); aReader.Close(); foreach (FormAccess fa in a) { u.FORM_ACCESS_LIST.Add(fa.CODE, fa); } return(u); } catch (Exception x) { throw new Exception(getErrorMessage(x)); } finally { m_connection.Close(); } }
public override void Update(IEntity en) { OpenConnection(); MySql.Data.MySqlClient.MySqlTransaction trans = m_connection.BeginTransaction(); MySql.Data.MySqlClient.MySqlCommand aCommand = new MySql.Data.MySqlClient.MySqlCommand(); aCommand.Connection = m_connection; aCommand.Transaction = trans; try { User e = (User)en; aCommand.CommandText = e.GetUpdateSQL(); aCommand.ExecuteNonQuery(); foreach (string kys in e.FORM_ACCESS_LIST.Keys) { if (e.FORM_ACCESS_LIST[kys].ID > 0) { aCommand.CommandText = e.FORM_ACCESS_LIST[kys].GetUpdateSQL(); aCommand.ExecuteNonQuery(); } else { aCommand.CommandText = e.FORM_ACCESS_LIST[kys].GetInsertSQL(); aCommand.ExecuteNonQuery(); aCommand.CommandText = e.FORM_ACCESS_LIST[kys].GetMaximumIDSQL(); e.FORM_ACCESS_LIST[kys].ID = Convert.ToInt32(aCommand.ExecuteScalar()); } } aCommand.CommandText = FormAccess.GetAllByUserSQL(e.ID); MySql.Data.MySqlClient.MySqlDataReader r = aCommand.ExecuteReader(); IList luc = FormAccess.GetAllStatic(r); r.Close(); foreach (FormAccess chk in luc) { chk.UPDATED = e.FORM_ACCESS_LIST.Contains(new KeyValuePair <string, FormAccess>(chk.CODE, chk)); } foreach (FormAccess chk in luc) { if (!chk.UPDATED) { aCommand.CommandText = chk.GetDeleteSQL(); aCommand.ExecuteNonQuery(); } } trans.Commit(); } catch (Exception x) { trans.Rollback(); throw new Exception(getErrorMessage(x)); } finally { m_connection.Close(); } }
public override bool Equals(object obj) { FormAccess o = (FormAccess)obj; if (o == null) { return(false); } return(o.ID == this.ID); }
public IEntity Get(MySql.Data.MySqlClient.MySqlDataReader aReader) { FormAccess formaccess = null; while (aReader.Read()) { formaccess = new FormAccess(); formaccess.ID = Convert.ToInt32(aReader[0]); formaccess.CODE = aReader[1].ToString(); formaccess.NAME = aReader[2].ToString(); formaccess.SAVE = Convert.ToBoolean(aReader[3]); formaccess.DELETE = Convert.ToBoolean(aReader[4]); formaccess.VIEW = Convert.ToBoolean(aReader[5]); formaccess.POST = Convert.ToBoolean(aReader[6]); formaccess.PRINT = Convert.ToBoolean(aReader[7]); formaccess.USER = new User(Convert.ToInt32(aReader[8])); formaccess.MODIFIED_BY = aReader["modified_by"].ToString(); formaccess.MODIFIED_DATE = Convert.ToDateTime(aReader["modified_date"].ToString()); formaccess.MODIFIED_COMPUTER_NAME = aReader["modified_computer"].ToString(); formaccess.FORM_TYPE = (FormType)Enum.Parse(typeof(FormType), aReader["form_type"].ToString()); } return(formaccess); }
public static IList GetAllStatic(MySql.Data.MySqlClient.MySqlDataReader aReader) { IList result = new ArrayList(); while (aReader.Read()) { FormAccess formaccess = new FormAccess(); formaccess.ID = Convert.ToInt32(aReader[0]); formaccess.CODE = aReader[1].ToString(); formaccess.NAME = aReader[2].ToString(); formaccess.SAVE = Convert.ToBoolean(aReader[3]); formaccess.DELETE = Convert.ToBoolean(aReader[4]); formaccess.VIEW = Convert.ToBoolean(aReader[5]); formaccess.POST = Convert.ToBoolean(aReader[6]); formaccess.PRINT = Convert.ToBoolean(aReader[7]); formaccess.USER = new User(Convert.ToInt32(aReader[8])); formaccess.MODIFIED_BY = aReader["modified_by"].ToString(); formaccess.MODIFIED_DATE = Convert.ToDateTime(aReader["modified_date"].ToString()); formaccess.MODIFIED_COMPUTER_NAME = aReader["modified_computer"].ToString(); result.Add(formaccess); } return(result); }
public User GetFormAccessByUserID(User userID) { try { OpenConnection(); FormAccess p = new FormAccess(); MySql.Data.MySqlClient.MySqlCommand aCommand = new MySql.Data.MySqlClient.MySqlCommand(FormAccess.GetAllByUserSQL(userID.ID), m_connection); MySql.Data.MySqlClient.MySqlDataReader aReader = aCommand.ExecuteReader(); IList a = p.GetAll(aReader); foreach (FormAccess fa in a) { userID.FORM_ACCESS_LIST.Add(fa.CODE, fa); } return(userID); } catch (Exception x) { throw new Exception(getErrorMessage(x)); } finally { m_connection.Close(); } }