Пример #1
0
        //MOUSAVI
        public static DUser SelectByUsernameAndPassword(SqlTransaction _transaction, SqlConnection _connection, string userName, string password)
        {
            SqlConnection Connection = _connection;// new SqlConnection(Atend.Control.ConnectionString.LocalcnString);
            SqlCommand    sqlCommand = new SqlCommand("D_User_SelectByUserNameAndpassword", Connection);

            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Parameters.Add(new SqlParameter("iUserName", userName));
            sqlCommand.Parameters.Add(new SqlParameter("iPassword", password));
            sqlCommand.Transaction = _transaction;
            //Connection.Open();
            SqlDataReader reader = sqlCommand.ExecuteReader();
            DUser         user   = new DUser();

            if (reader.Read())
            {
                user.Code     = Convert.ToInt32(reader["Code"].ToString());
                user.UserName = reader["UserName"].ToString();
                user.Password = reader["Password"].ToString();
                user.Name     = reader["Name"].ToString();
                user.Family   = reader["Family"].ToString();
            }
            else
            {
                user.Code = -1;
            }
            //Connection.Close();
            reader.Close();
            return(user);
        }
Пример #2
0
        public static DUser SelectByUserName(string username)
        {
            SqlConnection Connection = new SqlConnection(Atend.Control.ConnectionString.ServercnString);
            SqlCommand    sqlCommand = new SqlCommand("D_User_SelectByUserName", Connection);

            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Parameters.Add(new SqlParameter("iUserName", username));
            Connection.Open();
            SqlDataReader reader = sqlCommand.ExecuteReader();
            DUser         user   = new DUser();

            if (reader.Read())
            {
                user.UserName = reader["UserName"].ToString();
                user.Password = reader["Password"].ToString();
            }
            Connection.Close();
            reader.Close();
            return(user);
        }
Пример #3
0
        public static DUser SelectByCode(int code, SqlConnection _Connection, SqlTransaction _Transaction)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            SqlConnection Connection = _Connection;
            SqlCommand    sqlCommand = new SqlCommand("D_User_SelectByCode", Connection);

            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Parameters.Add(new SqlParameter("iCode", code));
            sqlCommand.Transaction = _Transaction;

            SqlDataReader reader = sqlCommand.ExecuteReader();
            DUser         user   = new DUser();

            if (reader.Read())
            {
                user.Code     = Convert.ToInt32(reader["Code"].ToString());
                user.UserName = reader["UserName"].ToString();
                user.Password = reader["Password"].ToString();
                user.Name     = reader["Name"].ToString();
                user.Family   = reader["Family"].ToString();
            }
            else
            {
                user.code = -1;
            }
            reader.Close();

            if (user.Code != -1)
            {
                DataTable AccessForUser = DUserAccess.SelectByUserId(user.Code);
                foreach (DataRow dr in AccessForUser.Rows)
                {
                    user.AccessList.Add(Convert.ToInt32(dr["IdAccess"]));
                }
            }
            return(user);
        }
Пример #4
0
        public static bool GetFromServer()
        {
            Editor         ed = Application.DocumentManager.MdiActiveDocument.Editor;
            SqlTransaction ServerTransaction = null;
            SqlConnection  ServerConnection  = new SqlConnection(Atend.Control.ConnectionString.ServercnString);

            SqlTransaction LocalTransaction = null;
            SqlConnection  LocalConnection  = new SqlConnection(Atend.Control.ConnectionString.LocalcnString);

            try
            {
                ServerConnection.Open();
                LocalConnection.Open();
                try
                {
                    ServerTransaction = ServerConnection.BeginTransaction();
                    LocalTransaction  = LocalConnection.BeginTransaction();

                    if (Atend.Base.Design.DUser.DeleteAll(LocalConnection, LocalTransaction))
                    {
                        DataTable dtUser = Atend.Base.Design.DUser.SelectAll(ServerConnection, ServerTransaction);
                        foreach (DataRow dr in dtUser.Rows)
                        {
                            DUser User = new DUser();
                            User.UserName = dr["UserName"].ToString();
                            User.Password = dr["Password"].ToString();
                            User.Name     = dr["Name"].ToString();
                            User.Family   = dr["Family"].ToString();

                            DataTable dtUserAccess = DUserAccess.SelectByUserId(Convert.ToInt32(dr["Code"]), ServerConnection, ServerTransaction);
                            foreach (DataRow druseraccess in dtUserAccess.Rows)
                            {
                                User.AccessList.Add(Convert.ToInt32(druseraccess["IDAccess"].ToString()));
                            }

                            if (!User.insertX(LocalTransaction, LocalConnection))
                            {
                                throw new System.Exception("Local Insert failed");
                            }
                        }
                    }
                    else
                    {
                        throw new System.Exception("Local Delete failed");
                    }
                }
                catch (System.Exception ex)
                {
                    ed.WriteMessage("ERROR D_GetFromServer catch 1: {0} \n", ex.Message);
                    ServerTransaction.Rollback();
                    ServerConnection.Close();

                    LocalTransaction.Rollback();
                    LocalConnection.Close();
                    return(false);
                }

                ServerTransaction.Commit();
                ServerConnection.Close();

                LocalTransaction.Commit();
                LocalConnection.Close();
            }
            catch (System.Exception ex1)
            {
                ed.WriteMessage("ERROR D_GetFromServer catch 2: {0} \n", ex1.Message);
                ServerConnection.Close();
                LocalConnection.Close();
                return(false);
            }

            return(true);
        }