Exemplo n.º 1
0
        public bool GetMailDataBaseBydistinguishedName(Guid transactionid, string distinguishedName, out List <MailDataBaseInfo> list, out ErrorCodeInfo error)
        {
            error = new ErrorCodeInfo();
            list  = new List <MailDataBaseInfo>();
            string strError = string.Empty;
            bool   bResult  = true;

            try
            {
                CParameters  paras = new CParameters();
                SqlParameter paraDistinguishedName = new SqlParameter("@distinguishedName", distinguishedName);
                paras.Add(paraDistinguishedName);

                CBaseDB _db = new CBaseDB(Conntection.strConnection);
                do
                {
                    DataSet ds = new DataSet();
                    if (!_db.ExcuteByTransaction(paras, "dbo.[prc_GetMailboxDBBydistinguishedName]", out ds, out strError))
                    {
                        strError   = "prc_GetMailboxDBBydistinguishedName数据库执行失败,Error:" + strError;
                        bResult    = false;
                        error.Code = ErrorCode.SQLException;
                        break;
                    }

                    if (ds != null && ds.Tables.Count > 0)
                    {
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            DataRow          sdr  = ds.Tables[0].Rows[i];
                            MailDataBaseInfo info = new MailDataBaseInfo();
                            info.ID     = Guid.Parse(Convert.ToString(sdr["ID"]));
                            info.OuID   = Guid.Parse(Convert.ToString(sdr["OuID"]));
                            info.OuName = Convert.ToString(sdr["OuName"]);
                            info.OUdistinguishedName = Convert.ToString(sdr["OUdistinguishedName"]);
                            info.MailboxDBID         = Guid.Parse(Convert.ToString(sdr["MailboxDBID"]));
                            info.MailboxDB           = Convert.ToString(sdr["MailboxDB"]);
                            info.MailboxServer       = Convert.ToString(sdr["MailboxServer"]);
                            info.CreateTime          = Convert.ToDateTime(sdr["CreateTime"]);
                            list.Add(info);
                        }
                    }
                    else
                    {
                        bResult    = false;
                        error.Code = ErrorCode.Exception;
                        LoggerHelper.Error("数据库执行prc_GetMailboxDBBydistinguishedName失败", string.Empty, "ds = null 或者 ds.Tables.Count <= 0", transactionid);
                    }
                } while (false);
            }
            catch (Exception ex)
            {
                bResult    = false;
                error.Code = ErrorCode.Exception;
                LoggerHelper.Error("MailDataBaseDBProvider调用prc_GetMailboxDBBydistinguishedName异常", string.Empty, ex.ToString(), transactionid);
            }
            return(bResult);
        }
Exemplo n.º 2
0
        public bool GetMailDataBaseInfo(Guid transactionid, AdminInfo admin, MailDataBaseInfo maildb, out string strJsonResult)
        {
            bool result = true;

            strJsonResult = string.Empty;
            ErrorCodeInfo error    = new ErrorCodeInfo();
            string        errormsg = string.Empty;
            string        paramstr = string.Empty;

            paramstr += $"userID:{admin.UserID}";
            paramstr += $"||UserAccount:{admin.UserAccount}";
            string funname = "GetMailDataBaseInfo";

            try
            {
                do
                {
                    MailDataBaseDBProvider Provider = new MailDataBaseDBProvider();
                    if (!Provider.GetMailDataBaseInfo(transactionid, admin, ref maildb, out error))
                    {
                        error.Code = ErrorCode.Exception;
                        LoggerHelper.Error("MailDataBaseManager调用GetMailDataBaseInfo异常", paramstr, errormsg, transactionid);
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        strJsonResult = JsonHelper.ReturnJson(true, Convert.ToInt32(error.Code), error.Info);
                        result        = false;
                    }

                    error.Code = ErrorCode.None;
                    string json = JsonConvert.SerializeObject(maildb);
                    LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), true, transactionid);
                    strJsonResult = JsonHelper.ReturnJson(true, Convert.ToInt32(error.Code), error.Info, json);
                    result        = true;
                } while (false);
            }
            catch (Exception ex)
            {
                error.Code = ErrorCode.Exception;
                LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                LoggerHelper.Error("MailDataBaseManager调用GetMailDataBaseInfo异常", paramstr, ex.ToString(), transactionid);
                strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                result        = false;
            }
            return(result);
        }
Exemplo n.º 3
0
        public bool ChangeMailDataBase(Guid transactionid, AdminInfo admin, MailDataBaseInfo maildb, out string strJsonResult)
        {
            bool result = true;

            strJsonResult = string.Empty;
            ErrorCodeInfo error    = new ErrorCodeInfo();
            string        errormsg = string.Empty;
            string        paramstr = string.Empty;

            paramstr += $"AdminID:{admin.UserID}";
            paramstr += $"||AdminAccount:{admin.UserAccount}";
            paramstr += $"||OuID:{maildb.OuID}";
            paramstr += $"||MailboxDB:{maildb.MailboxDB}";

            string funname = "ChangeMailDataBase";

            try
            {
                do
                {
                    DirectoryEntry ouEntry        = new DirectoryEntry();
                    CommonProvider commonProvider = new CommonProvider();
                    if (!commonProvider.GetADEntryByGuid(maildb.OuID, out ouEntry, out errormsg))
                    {
                        error.Code    = ErrorCode.SearchADDataError;
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        LoggerHelper.Error("GetADEntryByGuid异常", paramstr, errormsg, transactionid);
                        result = false;
                        break;
                    }

                    maildb.OUdistinguishedName = ouEntry.Properties["distinguishedName"].Value == null ? string.Empty : Convert.ToString(ouEntry.Properties["distinguishedName"].Value);
                    maildb.OuName = ouEntry.Properties["name"].Value == null ? string.Empty : Convert.ToString(ouEntry.Properties["name"].Value);

                    MailDataBaseDBProvider Provider = new MailDataBaseDBProvider();
                    MailDataBaseInfo       oldinfo  = new MailDataBaseInfo();
                    oldinfo.ID = maildb.ID;
                    if (!Provider.GetMailDataBaseInfo(transactionid, admin, ref oldinfo, out error))
                    {
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        result        = false;
                        break;
                    }
                    if (!Provider.ChangeMailDataBase(transactionid, admin, maildb, out error))
                    {
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        result        = false;
                        break;
                    }

                    error.Code = ErrorCode.None;
                    LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), true, transactionid);
                    strJsonResult = JsonHelper.ReturnJson(true, Convert.ToInt32(error.Code), error.Info);
                    //添加日志
                    #region 操作日志
                    LogInfo operateLog = new LogInfo();
                    operateLog.AdminID       = admin.UserID;
                    operateLog.AdminAccount  = admin.UserAccount;
                    operateLog.RoleID        = admin.RoleID;
                    operateLog.ClientIP      = _clientip;
                    operateLog.OperateResult = true;
                    operateLog.OperateType   = "修改邮箱数据库对应关系";
                    operateLog.OperateLog    = $"{admin.UserAccount}于{DateTime.Now}修改邮箱数据库对应关系。" +
                                               $"原OU:{oldinfo.OUdistinguishedName},现OU:{maildb.OUdistinguishedName}," +
                                               $"原MailboxDataBase:{oldinfo.MailboxDB},现MailboxDataBase:{maildb.MailboxDB}";
                    LogManager.AddOperateLog(transactionid, operateLog);
                    #endregion
                    result = true;
                } while (false);
            }
            catch (Exception ex)
            {
                error.Code = ErrorCode.Exception;
                LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                LoggerHelper.Error("MailDataBaseManager调用ChangeMailDataBase异常", paramstr, ex.ToString(), transactionid);
                strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                result        = false;
            }
            return(result);
        }
Exemplo n.º 4
0
        public bool DeleteMailDataBase(Guid transactionid, AdminInfo admin, MailDataBaseInfo maildb, out string strJsonResult)
        {
            bool result = true;

            strJsonResult = string.Empty;
            ErrorCodeInfo error    = new ErrorCodeInfo();
            string        errormsg = string.Empty;
            string        paramstr = string.Empty;

            paramstr += $"AdminID:{admin.UserID}";
            paramstr += $"||AdminAccount:{admin.UserAccount}";
            paramstr += $"||ID:{maildb.ID}";

            string funname = "DeleteMailDataBase";

            try
            {
                do
                {
                    MailDataBaseDBProvider Provider = new MailDataBaseDBProvider();
                    if (!Provider.GetMailDataBaseInfo(transactionid, admin, ref maildb, out error))
                    {
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        result        = false;
                        break;
                    }

                    if (!Provider.DeleteMailDataBase(transactionid, admin, maildb, out error))
                    {
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        result        = false;
                        break;
                    }

                    error.Code = ErrorCode.None;
                    LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), true, transactionid);
                    strJsonResult = JsonHelper.ReturnJson(true, Convert.ToInt32(error.Code), error.Info);
                    //添加日志
                    #region 操作日志
                    LogInfo operateLog = new LogInfo();
                    operateLog.AdminID       = admin.UserID;
                    operateLog.AdminAccount  = admin.UserAccount;
                    operateLog.RoleID        = admin.RoleID;
                    operateLog.ClientIP      = _clientip;
                    operateLog.OperateResult = true;
                    operateLog.OperateType   = "删除邮箱数据库对应关系";
                    operateLog.OperateLog    = $"{admin.UserAccount}于{DateTime.Now}删除邮箱数据库对应关系。" +
                                               $"OU:{maildb.OUdistinguishedName}," +
                                               $"MailboxDataBase:{maildb.MailboxDB}";
                    LogManager.AddOperateLog(transactionid, operateLog);
                    #endregion
                    result = true;
                } while (false);
            }
            catch (Exception ex)
            {
                error.Code = ErrorCode.Exception;
                LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                LoggerHelper.Error("MailDataBaseManager调用DeleteMailDataBase异常", paramstr, ex.ToString(), transactionid);
                strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                result        = false;
            }
            return(result);
        }
Exemplo n.º 5
0
        public bool GetMailDataBaseInfo(Guid transactionid, AdminInfo admin, ref MailDataBaseInfo maildb, out ErrorCodeInfo error)
        {
            error = new ErrorCodeInfo();
            string paramstr = string.Empty;

            paramstr += $"ID:{maildb.ID}";
            string strError = string.Empty;
            bool   bResult  = true;

            try
            {
                CParameters  paras      = new CParameters();
                SqlParameter paraUserID = new SqlParameter("@UserID", admin.UserID);
                paras.Add(paraUserID);
                SqlParameter paraID = new SqlParameter("@ID", maildb.ID);
                paras.Add(paraID);

                CBaseDB _db = new CBaseDB(Conntection.strConnection);
                do
                {
                    DataSet ds = new DataSet();
                    if (!_db.ExcuteByTransaction(paras, "dbo.[prc_GetMailDataBaseInfo]", out ds, out strError))
                    {
                        strError = "GetMailDataBaseInfo异常,Error:" + strError;
                        LoggerHelper.Error("MailDataBaseDBProvider调用GetMailDataBaseInfo异常", paramstr, strError, transactionid);
                        bResult    = false;
                        error.Code = ErrorCode.SQLException;
                        break;
                    }
                    if (ds != null && ds.Tables.Count > 0)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            int iResult = 0;
                            iResult = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
                            switch (iResult)
                            {
                            case 1:
                                bResult = true;
                                if (ds.Tables.Count > 1)
                                {
                                    DataRow sdr = ds.Tables[1].Rows[0];
                                    maildb.MailboxDBID         = Guid.Parse(Convert.ToString(sdr["MailboxDBID"]));
                                    maildb.MailboxDB           = Convert.ToString(sdr["MailboxDB"]);
                                    maildb.MailboxServer       = Convert.ToString(sdr["MailboxServer"]);
                                    maildb.OuID                = Guid.Parse(Convert.ToString(sdr["OuID"]));
                                    maildb.OuName              = Convert.ToString(sdr["OuName"]);
                                    maildb.OUdistinguishedName = Convert.ToString(sdr["OUdistinguishedName"]);
                                    maildb.Status              = (State)Convert.ToInt32(sdr["Status"]);
                                    maildb.CreateTime          = Convert.ToDateTime(sdr["CreateTime"]);
                                    maildb.ID = Guid.Parse(Convert.ToString(sdr["ID"]));
                                }
                                break;

                            case -1:
                                bResult    = false;
                                error.Code = ErrorCode.IdEmpty;
                                break;

                            case -9999:
                                bResult    = false;
                                error.Code = ErrorCode.SQLException;
                                LoggerHelper.Error("MailDataBaseDBProvider调用GetMailDataBaseInfo异常", paramstr, "-9999", transactionid);
                                break;

                            default:
                                bResult    = false;
                                error.Code = ErrorCode.Exception;
                                break;
                            }
                        }
                        else
                        {
                            bResult    = false;
                            error.Code = ErrorCode.Exception;
                            break;
                        }
                    }
                    else
                    {
                        bResult    = false;
                        error.Code = ErrorCode.Exception;
                        LoggerHelper.Error("MailDataBaseDBProvider调用GetMailDataBaseInfo异常", paramstr, "ds = null 或者 ds.Tables.Count <= 0", transactionid);
                    }
                } while (false);
            }
            catch (Exception ex)
            {
                bResult    = false;
                error.Code = ErrorCode.Exception;
                LoggerHelper.Error("MailDataBaseDBProvider调用GetMailDataBaseInfo异常", string.Empty, ex.ToString(), transactionid);
            }
            return(bResult);
        }
Exemplo n.º 6
0
        public bool DeleteMailDataBase(Guid transactionid, AdminInfo admin, MailDataBaseInfo maildb, out ErrorCodeInfo error)
        {
            error = new ErrorCodeInfo();
            string paramstr = string.Empty;

            paramstr += $"ID:{maildb.ID}";
            string strError = string.Empty;
            bool   bResult  = true;

            try
            {
                CParameters  paras      = new CParameters();
                SqlParameter paraUserID = new SqlParameter("@UserID", admin.UserID);
                paras.Add(paraUserID);
                SqlParameter paraID = new SqlParameter("@ID", maildb.ID);
                paras.Add(paraID);

                CBaseDB _db = new CBaseDB(Conntection.strConnection);
                do
                {
                    DataSet ds = new DataSet();
                    if (!_db.ExcuteByTransaction(paras, "dbo.[prc_DeleteMailDataBase]", out ds, out strError))
                    {
                        strError = "DeleteMailDataBase异常,Error:" + strError;
                        LoggerHelper.Error("MailDataBaseDBProvider调用DeleteMailDataBase异常", paramstr, strError, transactionid);
                        bResult    = false;
                        error.Code = ErrorCode.SQLException;
                        break;
                    }
                    if (ds != null && ds.Tables.Count > 0)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            int iResult = 0;
                            iResult = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
                            switch (iResult)
                            {
                            case 1:
                                bResult = true;
                                break;

                            case -1:
                                bResult    = false;
                                error.Code = ErrorCode.IdEmpty;
                                break;

                            case -9999:
                                bResult    = false;
                                error.Code = ErrorCode.SQLException;
                                LoggerHelper.Error("MailDataBaseDBProvider调用DeleteMailDataBase异常", paramstr, "-9999", transactionid);
                                break;

                            default:
                                bResult    = false;
                                error.Code = ErrorCode.Exception;
                                break;
                            }
                        }
                        else
                        {
                            bResult    = false;
                            error.Code = ErrorCode.Exception;
                            break;
                        }
                    }
                    else
                    {
                        bResult    = false;
                        error.Code = ErrorCode.Exception;
                        LoggerHelper.Error("MailDataBaseDBProvider调用DeleteMailDataBase异常", paramstr, "ds = null 或者 ds.Tables.Count <= 0", transactionid);
                    }
                } while (false);
            }
            catch (Exception ex)
            {
                bResult    = false;
                error.Code = ErrorCode.Exception;
                LoggerHelper.Error("MailDataBaseDBProvider调用DeleteMailDataBase异常", string.Empty, ex.ToString(), transactionid);
            }
            return(bResult);
        }
Exemplo n.º 7
0
        public bool GetMailDataBaseList(Guid transactionid, AdminInfo admin, int curpage, int pagesize, string searchstr, out BaseListInfo lists, out ErrorCodeInfo error)
        {
            error = new ErrorCodeInfo();
            lists = new BaseListInfo();
            string strError = string.Empty;
            bool   bResult  = true;

            try
            {
                CParameters  paras      = new CParameters();
                SqlParameter paraUserID = new SqlParameter("@UserID", admin.UserID);
                paras.Add(paraUserID);
                SqlParameter paraPageIndex = new SqlParameter("@PageIndex", curpage);
                paras.Add(paraPageIndex);
                SqlParameter paraPageSize = new SqlParameter("@PageSize", pagesize);
                paras.Add(paraPageSize);
                SqlParameter paraSearchstr = new SqlParameter("@Searchstr", $"%{searchstr}%");
                paras.Add(paraSearchstr);
                SqlParameter paraRecordCount = new SqlParameter("@RecordCount", SqlDbType.Int);
                paraRecordCount.Direction = ParameterDirection.Output;
                paras.Add(paraRecordCount);
                SqlParameter paraPageCount = new SqlParameter("@PageCount", SqlDbType.Int);
                paraPageCount.Direction = ParameterDirection.Output;
                paras.Add(paraPageCount);

                CBaseDB _db = new CBaseDB(Conntection.strConnection);
                do
                {
                    DataSet ds = new DataSet();
                    if (!_db.ExcuteByTransaction(paras, "dbo.[prc_GetMailDataBaseList]", out ds, out strError))
                    {
                        strError   = "prc_GetMailDataBaseList数据库执行失败,Error:" + strError;
                        bResult    = false;
                        error.Code = ErrorCode.SQLException;
                        break;
                    }

                    lists.RecordCount = (int)paraRecordCount.Value;
                    lists.PageCount   = (int)paraPageCount.Value;

                    if (ds != null && ds.Tables.Count > 0)
                    {
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            DataRow          sdr  = ds.Tables[0].Rows[i];
                            MailDataBaseInfo info = new MailDataBaseInfo();
                            info.ID     = Guid.Parse(Convert.ToString(sdr["ID"]));
                            info.OuID   = Guid.Parse(Convert.ToString(sdr["OuID"]));
                            info.OuName = Convert.ToString(sdr["OuName"]);
                            info.OUdistinguishedName = Convert.ToString(sdr["OUdistinguishedName"]);
                            info.MailboxDBID         = Guid.Parse(Convert.ToString(sdr["MailboxDBID"]));
                            info.MailboxDB           = Convert.ToString(sdr["MailboxDB"]);
                            info.MailboxServer       = Convert.ToString(sdr["MailboxServer"]);
                            info.CreateTime          = Convert.ToDateTime(sdr["CreateTime"]);
                            lists.Lists.Add(info);
                        }
                    }
                    else
                    {
                        bResult    = false;
                        error.Code = ErrorCode.Exception;
                        LoggerHelper.Error("数据库执行prc_GetMailDataBaseList失败", string.Empty, "ds = null 或者 ds.Tables.Count <= 0", transactionid);
                    }
                } while (false);
            }
            catch (Exception ex)
            {
                bResult    = false;
                error.Code = ErrorCode.Exception;
                LoggerHelper.Error("MailDataBaseDBProvider调用prc_GetMailDataBaseList异常", string.Empty, ex.ToString(), transactionid);
            }
            return(bResult);
        }