//~~~~~~~~~~~~~~~~~~~~~~~~ServerPart~~~~~~~~~~~~~~~~~~~~~~~// //ASHKTORAB public bool insert(SqlTransaction _transaction, SqlConnection _connection) { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; SqlTransaction transaction = _transaction; SqlConnection connection = _connection;// SqlConnection(Atend.Control.ConnectionString.ServercnString); SqlCommand command = new SqlCommand("D_User_Insert", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("iUserName", UserName)); command.Parameters.Add(new SqlParameter("iPassword", Password)); command.Parameters.Add(new SqlParameter("iName", Name)); command.Parameters.Add(new SqlParameter("iFamily", Family)); try { //connection.Open(); //transaction = connection.BeginTransaction(); command.Transaction = transaction; try { Code = Convert.ToInt32(command.ExecuteScalar()); foreach (int AccessId in AccessList) { Atend.Base.Design.DUserAccess userAccess = new DUserAccess(); userAccess.IDUser = Code; userAccess.IdAccess = AccessId; if (userAccess.Insert(transaction, connection)) { //nothing } else { throw new System.Exception("userAccess.Insert failed"); } } } catch (System.Exception ex1) { //Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage(string.Format(" ERROR DUser.Insert : {0}\n", ex1.Message)); //transaction.Rollback(); //connection.Close(); return(false); } } catch (System.Exception ex1) { //Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage(string.Format(" ERROR Transaction DUser.Insert: {0} \n", ex1.Message)); //connection.Close(); return(false); } //transaction.Commit(); //connection.Close(); return(true); }
public static bool Delete(SqlTransaction _transaction, SqlConnection _connection, int Code) { SqlTransaction transaction = _transaction; SqlConnection Connection = _connection;// new SqlConnection(Atend.Control.ConnectionString.ServercnString); SqlCommand Command = new SqlCommand("D_User_Delete", Connection); Command.CommandType = CommandType.StoredProcedure; Command.Parameters.Add(new SqlParameter("iCode", Code)); try { //Connection.Open(); //transaction = Connection.BeginTransaction(); Command.Transaction = transaction; Boolean canComitTransaction = true; try { Command.ExecuteNonQuery(); if (DUserAccess.DeleteX(transaction, Connection, Code)) { //do nothing } else { throw new System.Exception("DUserAccess.Delete failed"); } //transaction.Commit(); //Connection.Close(); return(true); } catch (System.Exception ex1) { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage(string.Format(" ERROR DUser.DeleteX {0}\n", ex1.Message)); //transaction.Rollback(); //Connection.Close(); return(false); } } catch (System.Exception ex1) { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage(string.Format(" ERROR Transaction DUser.Delete: {0} \n", ex1.Message)); //Connection.Close(); return(false); } }
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); }
public static bool DeleteAll(SqlConnection _connection, SqlTransaction _transaction) { SqlTransaction transaction = _transaction; SqlConnection Connection = _connection;// new SqlConnection(Atend.Control.ConnectionString.ServercnString); SqlCommand Command = new SqlCommand("D_User_DeleteAll", Connection); Command.CommandType = CommandType.StoredProcedure; try { Command.Transaction = transaction; Boolean canComitTransaction = true; try { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; Command.ExecuteNonQuery(); if (!DUserAccess.DeleteAll(Connection, transaction)) { throw new System.Exception("DUserAccess.DeleteAll failed"); } return(true); } catch (System.Exception ex1) { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage(string.Format(" ERROR DUser.DeleteAll {0}\n", ex1.Message)); return(false); } } catch (System.Exception ex1) { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage(string.Format(" ERROR Transaction DUser.DeleteAll: {0} \n", ex1.Message)); return(false); } }
//public static bool ShareUserAccessOnServer() //{ // Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; // SqlConnection Serverconnection = new SqlConnection(Atend.Control.ConnectionString.ServercnString); // SqlTransaction Servertransaction; // try // { // Serverconnection.Open(); // Servertransaction = Serverconnection.BeginTransaction(); // try // { // DataTable LocalUserTbl = Atend.Base.Design.DUser.SelectAll(); // foreach (DataRow LocalUserRow in LocalUserTbl.Rows) // { // Atend.Base.Design.DUser User = Atend.Base.Design.DUser.ServerSelectByUsernameAndPassword(Servertransaction, Serverconnection, LocalUserRow["UserName"].ToString(), LocalUserRow["PassWord"].ToString()); // if (User.Code != -1) // { // if (!Atend.Base.Design.DUser.ServerDelete(Servertransaction, Serverconnection, User.Code)) // { // Servertransaction.Rollback(); // Serverconnection.Close(); // return false; // } // } // User.Name = LocalUserRow["Name"].ToString(); // User.Family = LocalUserRow["Family"].ToString(); // User.Password = LocalUserRow["Password"].ToString(); // User.UserName = LocalUserRow["UserName"].ToString(); // DataTable AccessForUser = DUserAccess.SelectByUserId(Convert.ToInt32(LocalUserRow["Code"].ToString())); // foreach (DataRow dr in AccessForUser.Rows) // { // User.AccessList.Add(Convert.ToInt32(dr["IdAccess"])); // } // if (!User.insert(Servertransaction, Serverconnection)) // { // Servertransaction.Rollback(); // Serverconnection.Close(); // return false; // } // } // Servertransaction.Commit(); // Serverconnection.Close(); // return true; // } // catch (System.Exception exp) // { // ed.WriteMessage(string.Format("Error In TransAction of ShareUserAccessOnServer:{0}\n", exp.Message)); // Servertransaction.Rollback(); // Serverconnection.Close(); // return false; // } // } // catch (System.Exception exp) // { // ed.WriteMessage(string.Format(" ERROR DACCESS.ShareUserAccessOnServer {0}\n", exp.Message)); // Serverconnection.Close(); // return false; // } // return true; //} public static bool GetUserAccessFromServer() { Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; SqlConnection Localconnection = new SqlConnection(Atend.Control.ConnectionString.LocalcnString); SqlTransaction Localtransaction; try { Localconnection.Open(); Localtransaction = Localconnection.BeginTransaction(); try { DataTable ServerUserTbl = Atend.Base.Design.DUser.ServerSelectAll(); foreach (DataRow ServerUserRow in ServerUserTbl.Rows) { Atend.Base.Design.DUser User = Atend.Base.Design.DUser.SelectByUsernameAndPassword(Localtransaction, Localconnection, ServerUserRow["UserName"].ToString(), ServerUserRow["PassWord"].ToString()); if (User.Code != -1) { if (!Atend.Base.Design.DUser.Delete(Localtransaction, Localconnection, User.Code)) { Localtransaction.Rollback(); Localconnection.Close(); return(false); } } User.Name = ServerUserRow["Name"].ToString(); User.Family = ServerUserRow["Family"].ToString(); User.Password = ServerUserRow["Password"].ToString(); User.UserName = ServerUserRow["UserName"].ToString(); DataTable AccessForUser = DUserAccess.ServerSelectByUserId(Convert.ToInt32(ServerUserRow["Code"].ToString())); foreach (DataRow dr in AccessForUser.Rows) { User.AccessList.Add(Convert.ToInt32(dr["IdAccess"])); } if (!User.insertX(Localtransaction, Localconnection)) { Localtransaction.Rollback(); Localconnection.Close(); return(false); } } Localtransaction.Commit(); Localconnection.Close(); return(true); } catch (System.Exception exp) { ed.WriteMessage(string.Format("Error In TransAction of GetUserAccessFromServer:{0}\n", exp.Message)); Localtransaction.Rollback(); Localconnection.Close(); return(false); } } catch (System.Exception exp) { ed.WriteMessage(string.Format(" ERROR DACCESS.GetUserAccessFromServer {0}\n", exp.Message)); Localconnection.Close(); return(false); } return(true); }
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); }
//MOUSAVI public bool updateX() { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; SqlTransaction transAction; SqlConnection connection = new SqlConnection(Atend.Control.ConnectionString.LocalcnString); SqlCommand command = new SqlCommand("D_User_Update", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("iUserName", UserName)); command.Parameters.Add(new SqlParameter("iPassword", Password)); command.Parameters.Add(new SqlParameter("iName", Name)); command.Parameters.Add(new SqlParameter("iFamily", Family)); command.Parameters.Add(new SqlParameter("iCode", Code)); try { connection.Open(); transAction = connection.BeginTransaction(); command.Transaction = transAction; try { command.ExecuteNonQuery(); if (Atend.Base.Design.DUserAccess.DeleteX(transAction, connection, Code)) { foreach (int AccessId in AccessList) { Atend.Base.Design.DUserAccess userAccess = new DUserAccess(); userAccess.IDUser = Code; userAccess.IdAccess = AccessId; if (userAccess.InsertX(transAction, connection)) { //nothing } else { throw new System.Exception("userAccess.InsertX failed"); } } } else { throw new System.Exception("DUserAccess.DeleteX failed"); } transAction.Commit(); connection.Close(); return(true); } catch (System.Exception ex1) { ed.WriteMessage(string.Format(" ERROR DUser.UpdateX {0}\n", ex1.Message)); transAction.Rollback(); connection.Close(); return(false); } } catch (System.Exception ex1) { ed.WriteMessage(string.Format(" ERROR Transaction EDUser.UpdateX: {0} \n", ex1.Message)); connection.Close(); return(false); } }