Exemple #1
0
        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();
            }
        }
Exemple #2
0
 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();
     }
 }
Exemple #3
0
 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();
     }
 }