Example #1
0
        public async Task SoapResult_WithBody()
        {
            var result = new SoapResult(header: null, body: new SimpleBody {
                Value = 17
            });

            await ActionResultAssert.WritesToBody(@"<SOAP-ENV:Envelope SOAP-ENV:encodingStyle=""http://www.w3.org/2001/12/soap-encoding"" xmlns:SOAP-ENV=""http://www.w3.org/2001/12/soap-envelope"">
  <SOAP-ENV:Body>
    <SimpleBody xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
      <Value>17</Value>
    </SimpleBody>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>", result);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="WebServiceUrl"></param>
        /// <param name="ID"></param>
        /// <param name="Password"></param>
        /// <param name="Log"></param>
        /// <returns></returns>
        public SoapResult IdVerify(string WebServiceUrl, string ID, string Password, ref ILog Log)
        {
            SoapResult result = new SoapResult();

            XmlDocument xmlDocRequest = null, xmlDocResponse = null;

            string soap_result = string.Empty;

            try
            {
                Log.WriteLog(Mode.LogMode.INFO, string.Format("[SOAP]IdVerify::ID:{0},Password:{1}", ID, Password.EncryptDES()));

                string soap_request_path = Utility.AppConfig.LandBank_IdVerifyPath;

                string soap_request = File.ReadAllText(soap_request_path, Encoding.UTF8);

                soap_request = soap_request.Replace("[ID]", ID).Replace("[Password]", Password);

                Log.WriteLog(Mode.LogMode.DEBUG, string.Format("[SOAP]IdVerify.Request::{0}", soap_request.EncryptDES()));

                xmlDocRequest = new XmlDocument();
                xmlDocRequest.LoadXml(soap_request);

                soap_result = GetSoapResponse(WebServiceUrl, xmlDocRequest.OuterXml, ref Log);

                Log.WriteLog(Mode.LogMode.DEBUG, string.Format("[SOAP]IdVerify.Response::{0}", soap_result.EncryptDES()));

                xmlDocResponse = new XmlDocument();
                xmlDocResponse.LoadXml(soap_result);

                result.Mgr = new XmlNamespaceManager(xmlDocResponse.NameTable);
                result.Mgr.AddNamespace("soap", "http://www.w3.org/2003/05/soap-envelope");
                result.Mgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
                result.Mgr.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
                result.Mgr.AddNamespace("cg", "http://microsoft.com/taiwan/mcs");

                XmlNode xmlNodeResult = xmlDocResponse.SelectSingleNode(string.Format("./soap:Envelope/soap:Body/cg:IdVerifyResponse/cg:IdVerifyResult"), result.Mgr);

                XmlNode xmlNodeStatus = xmlNodeResult.SelectSingleNode("./cg:Status", result.Mgr);

                result.StatusCode = Convert.ToInt32(xmlNodeStatus.SelectSingleNode("./cg:StatusCode", result.Mgr).InnerText.Trim());
                result.Severity   = xmlNodeStatus.SelectSingleNode("./cg:Severity", result.Mgr).InnerText.Trim();
                result.Desciption = xmlNodeStatus.SelectSingleNode("./cg:Desciption", result.Mgr).InnerText.Trim();

                result.Info = xmlNodeResult.SelectNodes("./cg:Users/cg:UserInfo", result.Mgr);

                if (!result.StatusCode.Equals(0))
                {
                    Log.WriteLog(Mode.LogMode.ERROR, string.Format("[SOAP]IdVerify.ERROR::{0},{1},{2}", result.StatusCode, result.Severity, result.Desciption));
                }
            }
            catch (System.Exception ex)
            {
                soap_result = ex.ToString();

                Log.WriteLog(Mode.LogMode.ERROR, string.Format("[SOAP]IdVerify.Exception::\r\n{0}", ex.ToString()));
            }
            finally
            {
                if (xmlDocRequest != null)
                {
                    xmlDocRequest = null;
                }

                if (xmlDocResponse != null)
                {
                    xmlDocResponse = null;
                }
            }
            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            List <IDataParameter> para = null;

            string strSql = string.Empty, message = string.Empty;

            DataTable dt_User = null;

            int result = -1;

            try
            {
                string role_id = this.ddlRole.SelectedValue;

                string group_id = this.ddlDept.SelectedValue;

                if (String.IsNullOrEmpty(role_id) || String.IsNullOrEmpty(group_id))
                {
                    return;
                }

                string role_name = this.ddlRole.SelectedItem.Text;

                this.WriteLog(string.Format("準備新增角色成員 ({0})", this.txtUserAccount.Text.Trim()));

                strSql = this.Select.US(null, this.txtUserAccount.Text.Trim(), null, group_id, "0", ref para);

                #region SQL Debug

                this.WriteLog(Mode.LogMode.DEBUG, strSql);

                this.WriteLog(para.ToLog());

                #endregion

                dt_User = this.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para);

                string acct_id = dt_User.Rows.Count > 0 ? dt_User.Rows[0]["acct_id"].ToString().Trim() : string.Empty;

                if (String.IsNullOrEmpty(acct_id))
                {
                    if (!String.IsNullOrEmpty(group_id) && Utility.WebConfig.LoginMode.Equals(1))
                    {
                        #region AggregateInquiry
                        try
                        {
                            SoapResult soapDepartmentResult = null;

                            string adws_url = this.GetSystemSetting("ADWS");

                            string adws_group_name = this.GetSystemSetting("AdwsGroupName");

                            strSql = this.Select.Group(group_id, null, null, null, ref para);

                            #region SQL Debug

                            this.WriteLog(Mode.LogMode.DEBUG, strSql);

                            this.WriteLog(para.ToLog());

                            #endregion

                            string group_code = this.DBConnTransac.GeneralSqlCmd.ExecuteByColumnName(strSql, para, "group_code");

                            if (!String.IsNullOrEmpty(group_code))
                            {
                                this.WriteLog(string.Format("AggregateInquiry:{0},{1},{2}", adws_url, group_code, adws_group_name));

                                soapDepartmentResult = this.AggregateInquiry(adws_url, group_code, adws_group_name);

                                this.WriteLog(string.Format("AggregateInquiry.Result:{0}", soapDepartmentResult.Info != null ? soapDepartmentResult.Info.Count.ToString() : "Null"));

                                if (soapDepartmentResult.Info != null && soapDepartmentResult.Info.Count > 0)
                                {
                                    for (int i = 0; i < soapDepartmentResult.Info.Count; i++)
                                    {
                                        XmlNode xmlNodeUserInfo = soapDepartmentResult.Info[i];

                                        string acct_account2 = xmlNodeUserInfo.SelectSingleNode("./cg:Id", soapDepartmentResult.Mgr).InnerText.Trim();

                                        string acct_name2 = xmlNodeUserInfo.SelectSingleNode("./cg:DisplayName", soapDepartmentResult.Mgr).InnerText.Trim();

                                        string acct_type2 = xmlNodeUserInfo.SelectSingleNode("./cg:Title", soapDepartmentResult.Mgr).InnerText.Trim();

                                        if (!acct_account2.Equals(this.txtUserAccount.Text.Trim()))
                                        {
                                            continue;
                                        }
                                        try
                                        {
                                            strSql = this.Select.AccountType(acct_type2, ref para);

                                            #region SQL Debug

                                            this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                            this.WriteLog(para.ToLog());

                                            #endregion

                                            string type2 = this.DBConnTransac.GeneralSqlCmd.ExecuteByColumnName(strSql, para, "cus_role_role_id");

                                            this.WriteLog(string.Format("Type:{0}={1}", acct_type2, type2));

                                            strSql = this.Insert.LandBack_Account(acct_account2, acct_name2, type2, ref para);

                                            #region SQL Debug

                                            this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                            this.WriteLog(para.ToLog());

                                            #endregion

                                            object acct_id_temp2 = this.DBConnTransac.GeneralSqlCmd.ExecuteItentity(strSql, para);

                                            this.WriteLog(string.Format("同步單位新增使用者:{0}", acct_id_temp2 == null ? "Fail" : "Pass"));

                                            if (acct_id_temp2 == null)
                                            {
                                                this.Rollback();

                                                this.MessageBox(Mode.LogMode.ERROR, message = string.Format("同步單位新增使用者失敗"));

                                                this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, acct_account2)); return;
                                            }
                                            string acct_id_2 = acct_id_temp2.ToString();

                                            strSql = this.Insert.LandBack_AccountExt(acct_id_2, ref para);

                                            #region SQL Debug

                                            this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                            this.WriteLog(para.ToLog());

                                            #endregion

                                            result = this.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para);

                                            this.WriteLog(string.Format("同步單位新增使用者失敗(Ext):{0}", result.Equals(0) ? "Fail" : "Pass"));

                                            if (result.Equals(0))
                                            {
                                                this.Rollback();

                                                this.MessageBox(Mode.LogMode.ERROR, message = string.Format("同步單位新增使用者失敗(Ext)"));

                                                this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, acct_account2)); return;
                                            }
                                            strSql = this.Insert.LandBack_AccountGroup(acct_id_2, group_id, ref para);

                                            #region SQL Debug

                                            this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                            this.WriteLog(para.ToLog());

                                            #endregion

                                            result = this.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para);

                                            this.WriteLog(string.Format("同步單位新增使用者失敗(Group):{0}", result.Equals(0) ? "Fail" : "Pass"));

                                            if (result.Equals(0))
                                            {
                                                this.Rollback();

                                                this.MessageBox(Mode.LogMode.ERROR, message = string.Format("同步單位新增使用者失敗(Group)"));

                                                this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, acct_account2)); return;
                                            }
                                            this.WriteLog(message = string.Format("Account:{0}\r\n同步帳號至資料庫完成", acct_account2));
                                        }
                                        catch (System.Exception ex)
                                        {
                                            this.WriteLog(Log.Mode.LogMode.ERROR, string.Format("btnAdd_Click.AggregateInquiry.Exception::\r\n{0}", ex.ToString()));
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                        catch (System.Exception ex)
                        {
                            this.WriteLog(Log.Mode.LogMode.ERROR, string.Format("btnAdd_Click.AggregateInquiry.Exception::\r\n{0}", ex.ToString()));
                        }
                        #endregion

                        strSql = this.Select.US(null, this.txtUserAccount.Text.Trim(), null, group_id, "0", ref para);

                        #region SQL Debug

                        this.WriteLog(Mode.LogMode.DEBUG, strSql);

                        this.WriteLog(para.ToLog());

                        #endregion

                        dt_User = this.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para);

                        acct_id = dt_User.Rows.Count > 0 ? dt_User.Rows[0]["acct_id"].ToString().Trim() : string.Empty;
                    }

                    if (String.IsNullOrEmpty(acct_id))
                    {
                        this.Rollback();

                        this.MessageBox(Mode.LogMode.ERROR, message = string.Format("查無該使用者編號 ({0})", this.txtUserAccount.Text.Trim().HtmlEncode()));

                        this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, message);

                        return;
                    }
                }
                string acct_name = dt_User.Rows[0]["acct_name"].ToString().Trim();

                string acct_status = dt_User.Rows[0]["acct_status"].ToString().Trim();

                if (!acct_status.Equals("0"))
                {
                    this.Rollback();

                    this.MessageBox(Mode.LogMode.ERROR, message = string.Format("使用者非啟用狀態 ({0} ({1}))", acct_name.HtmlEncode(), this.txtUserAccount.Text.Trim().HtmlEncode()));

                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, message);

                    return;
                }
                if (role_id.Equals("-1"))
                {
                    strSql = this.Select.DefaultRole(this.txtUserAccount.Text.Trim(), ref para);

                    #region SQL Debug

                    this.WriteLog(Mode.LogMode.DEBUG, strSql);

                    this.WriteLog(para.ToLog());

                    #endregion

                    role_id = this.DBConnTransac.GeneralSqlCmd.ExecuteByColumnName(strSql, para, "role_id");

                    if (String.IsNullOrEmpty(role_id))
                    {
                        this.Rollback();

                        this.MessageBox(Mode.LogMode.ERROR, message = string.Format("該使用者沒有預設的角色 ({0})", this.txtUserAccount.Text.Trim().HtmlEncode()));

                        this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, message);

                        return;
                    }
                }
                int verify_status = 1;

                string detail = JsonConvert.SerializeObject(new VerifyInfo()
                {
                    RoleID = role_id, RoleName = role_name.EncryptBase64(), AcctID = acct_id, AcctName = acct_name.EncryptBase64(), CreaterID = this.SessionMgr.UserInfos.UserID, CreaterName = this.SessionMgr.UserInfos.RealName, VerifyStatus = verify_status
                });

                this.WriteLog(detail);

                string status = this.CheckVerify(group_id, acct_id);

                if (!String.IsNullOrEmpty(status))
                {
                    this.Rollback();

                    this.MessageBox(Mode.LogMode.ERROR, message = string.Format("該使用者目前已在審核階段【{0}】", status.GetVerifyStatusCH()));

                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, message);

                    return;
                }
                strSql = this.Select.UserRoles(acct_id, null, group_id, ref para);

                #region SQL Debug

                this.WriteLog(Mode.LogMode.DEBUG, strSql);

                this.WriteLog(para.ToLog());

                #endregion

                dt_User = this.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para);

                if (dt_User.Rows.Count > 0)
                {
                    this.Rollback();

                    this.MessageBox(Mode.LogMode.ERROR, message = string.Format("該使用者已有指派角色 ({0})", dt_User.Rows[0]["acct_role_role_name"].ToString().HtmlEncode()));

                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, message);

                    return;
                }
                strSql = this.Insert.Verify("1", detail.EncryptBase64(), verify_status.ToString(), this.SessionMgr.UserInfos.UserID, ref para);

                #region SQL Debug

                this.WriteLog(Mode.LogMode.DEBUG, strSql);

                this.WriteLog(para.ToLog());

                #endregion

                result = this.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para);

                if (!result.Equals(1))
                {
                    this.Rollback();

                    this.MessageBox(Mode.LogMode.ERROR, message = string.Format("新增送審失敗 {0}", detail.HtmlEncode()));

                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, message);

                    return;
                }
                this.WriteLog(message = string.Format("新增送審角色成員 {0}", detail.HtmlEncode()));

                this.DBConnTransac.GeneralSqlCmd.Transaction.Commit();

                this.MessageBox(Mode.LogMode.INFO, string.Format("新增送審成功"));

                this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.Add), this.PageName, message);
            }
            catch (System.Exception ex)
            {
                this.Rollback();

                this.MessageBox(ex);

                this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.SystemError), this.PageName, ex.Message);
            }
            finally
            {
                dt_User = null;

                para = null;

                this.CloseConnTransac();

                this.WriteLog(string.Format("新增角色成員結束"));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnVerify_Click(object sender, EventArgs e)
        {
            List <IDataParameter> para = null;

            string strSql = string.Empty, message = string.Empty;

            try
            {
                this.WriteLog(string.Format("覆核開始"));

                string role_id = this.ViewState["RoleID"].ToString();

                string group_id = this.ViewState["GroupID"].ToString();

                string user_id = this.ViewState["UserID"].ToString();

                int verify_status = (int)this.ViewState["VerifyStatus"];

                message = string.Format("審核編號:{0},單位編號:{1},角色編號:{2},被覆核人員:{3}", this.UID, group_id, role_id, user_id);

                if (String.IsNullOrEmpty(role_id) || String.IsNullOrEmpty(group_id) || String.IsNullOrEmpty(this.UID))
                {
                    this.MessageBox(Mode.LogMode.ERROR, string.Format("發生資訊參數取得錯誤"));

                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Overrule, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.VerifyFail), this.PageName, message);

                    return;
                }
                VerifyInfo verifyInfo = JsonConvert.DeserializeObject <VerifyInfo>(this.ViewState["Detail"].ToString());

                verifyInfo.ApprovedID = this.SessionMgr.UserInfos.UserID;

                verifyInfo.ApprovedName = this.SessionMgr.UserInfos.RealName;

                string detail = JsonConvert.SerializeObject(verifyInfo);

                strSql = this.Update.UserRolesVerifyStatus(this.UID, "8", detail.EncryptBase64(), ref para);

                #region SQL Debug

                this.WriteLog(Mode.LogMode.DEBUG, strSql);

                this.WriteLog(para.ToLog());

                #endregion

                int result = this.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para);

                if (!result.Equals(1))
                {
                    this.Rollback();

                    this.MessageBox(Mode.LogMode.ERROR, "覆核失敗");

                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Overrule, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.VerifyFail), this.PageName, message);

                    return;
                }
                strSql = this.Select.UserRoles(user_id, null, group_id, ref para);

                #region SQL Debug

                this.WriteLog(Mode.LogMode.DEBUG, strSql);

                this.WriteLog(para.ToLog());

                #endregion

                string acct_role_id = this.DBConnTransac.GeneralSqlCmd.ExecuteByColumnName(strSql, para, "acct_role_id");

                string status = verify_status == 1 || verify_status == 2 ? "0" : "99";

                if (String.IsNullOrEmpty(acct_role_id))
                {
                    strSql = this.Insert.UserRoles(role_id, user_id, status, ref para);
                }
                else
                {
                    strSql = this.Update.UserRoles(acct_role_id, role_id, status, ref para);
                }

                #region SQL Debug

                this.WriteLog(Mode.LogMode.DEBUG, strSql);

                this.WriteLog(para.ToLog());

                #endregion

                result = this.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para);

                if (!result.Equals(1))
                {
                    this.Rollback();

                    this.MessageBox(Mode.LogMode.ERROR, "覆核失敗");

                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Overrule, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.VerifyFail), this.PageName, message);

                    return;
                }
                if (Utility.WebConfig.LoginMode.Equals(1))
                {
                    SoapResult soapDepartmentResult = null;

                    string adws_url = this.GetSystemSetting("ADWS");

                    string adws_group_name = this.GetSystemSetting("AdwsGroupName");

                    string group_code = this.ViewState["GroupCode"].ToString();

                    this.WriteLog(string.Format("AggregateInquiry:{0},{1},{2}", adws_url, group_code, adws_group_name));

                    soapDepartmentResult = this.AggregateInquiry(adws_url, group_code, adws_group_name);

                    this.WriteLog(string.Format("AggregateInquiry.Result:{0}", soapDepartmentResult.Info != null ? soapDepartmentResult.Info.Count.ToString() : "Null"));

                    if (soapDepartmentResult.Info != null && soapDepartmentResult.Info.Count > 0)
                    {
                        bool add_member = true;

                        for (int i = 0; i < soapDepartmentResult.Info.Count; i++)
                        {
                            XmlNode xmlNodeUserInfo = soapDepartmentResult.Info[i];

                            string acct_account = xmlNodeUserInfo.SelectSingleNode("./cg:Id", soapDepartmentResult.Mgr).InnerText.Trim();
                            string acct_name    = xmlNodeUserInfo.SelectSingleNode("./cg:DisplayName", soapDepartmentResult.Mgr).InnerText.Trim();
                            string acct_type    = xmlNodeUserInfo.SelectSingleNode("./cg:Title", soapDepartmentResult.Mgr).InnerText.Trim();

                            if (this.ViewState["Account"].ToString().Equals(acct_account))
                            {
                                add_member = false; break;
                            }
                        }
                        if (status.Equals("0"))
                        {
                            this.WriteLog(string.Format("AddMember::{0},{1},{2}", this.ViewState["Account"].ToString(), add_member, status));
                        }
                        else
                        {
                            this.WriteLog(string.Format("RemoveMember::{0},{1},{2}", this.ViewState["Account"].ToString(), add_member, status));
                        }

                        if (add_member && status.Equals("0") && !this.AddMember(adws_url, this.ViewState["Account"].ToString(), adws_group_name))
                        {
                            this.Rollback();

                            this.MessageBox(Mode.LogMode.ERROR, "覆核失敗,AddMember 發生錯誤");

                            this.MyMonitor.LogMonitor(this, MonitorActionMode.Overrule, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.VerifyFail), this.PageName, message);

                            return;
                        }
                        else if (!add_member && status.Equals("99") && !this.RemoveMember(adws_url, this.ViewState["Account"].ToString(), adws_group_name))
                        {
                            this.Rollback();

                            this.MessageBox(Mode.LogMode.ERROR, "覆核失敗,RemoveMember 發生錯誤");

                            this.MyMonitor.LogMonitor(this, MonitorActionMode.Overrule, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.VerifyFail), this.PageName, message);

                            return;
                        }
                    }
                }

                strSql = this.Select.US(user_id, string.Empty, string.Empty, ref para);

                #region SQL Debug

                this.WriteLog(Mode.LogMode.DEBUG, strSql);

                this.WriteLog(para.ToLog());

                #endregion

                string acct_desc = this.DBConnTransac.GeneralSqlCmd.ExecuteByColumnName(strSql, para, "acct_desc");

                if (String.IsNullOrEmpty(acct_desc) || Convert.ToInt32(acct_desc) < 1)
                {
                    #region Login Count

                    strSql = this.Update.LoginCount(user_id, ref para);

                    #region SQL Debug

                    this.WriteLog(Mode.LogMode.DEBUG, strSql);

                    this.WriteLog(para.ToLog());

                    #endregion

                    this.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para);

                    #endregion
                }
                this.DBConnTransac.GeneralSqlCmd.Transaction.Commit();

                this.MessageBox(Mode.LogMode.INFO, "覆核成功");

                this.LoadUserInfo();

                this.MyMonitor.LogMonitor(this, MonitorActionMode.Overrule, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.Verify), this.PageName, message);
            }
            catch (System.Exception ex)
            {
                this.Rollback();

                this.MessageBox(ex);

                this.MyMonitor.LogMonitor(this, MonitorActionMode.Overrule, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.SystemError), this.PageName, ex.Message);
            }
            finally
            {
                para = null;

                this.CloseConnTransac();

                this.WriteLog(string.Format("覆核結束"));
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Response.Clear();

            string group_id = this.RequestQueryString("group").HtmlEncode();

            string q = this.RequestQueryString("q").HtmlEncode();

            try
            {
                string sn = string.Format("G{0}", group_id);

                if ((this.Session[sn] == null || ((DataTable)this.Session[sn]).Rows.Count.Equals(0)) && !String.IsNullOrEmpty(group_id))
                {
                    List <IDataParameter> para = null;

                    DataTable dt = new DataTable();
                    dt.Columns.Add("acct_account", typeof(string));
                    dt.Columns.Add("acct_name", typeof(string));
                    dt.Columns.Add("group_code", typeof(string));
                    try
                    {
                        SoapResult soapDepartmentResult = null;

                        string adws_url = this.GetSystemSetting("ADWS");

                        string strSql = this.Select.Group(group_id, null, null, null, ref para);

                        #region SQL Debug

                        this.WriteLog(Log.Mode.LogMode.DEBUG, strSql);

                        this.WriteLog(para.ToLog());

                        #endregion

                        string group_code = this.DBConn.GeneralSqlCmd.ExecuteByColumnName(strSql, para, "group_code");

                        if (!String.IsNullOrEmpty(group_code))
                        {
                            this.WriteLog(string.Format("AggregateInquiry:{0},{1},{2}", adws_url, group_code, string.Empty));

                            soapDepartmentResult = this.AggregateInquiry(adws_url, group_code, string.Empty);

                            this.WriteLog(string.Format("AggregateInquiry.Result:{0}", soapDepartmentResult.Info != null ? soapDepartmentResult.Info.Count.ToString() : "Null"));

                            if (soapDepartmentResult.Info != null && soapDepartmentResult.Info.Count > 0)
                            {
                                for (int i = 0; i < soapDepartmentResult.Info.Count; i++)
                                {
                                    XmlNode xmlNodeUserInfo = soapDepartmentResult.Info[i];

                                    string acct_account = xmlNodeUserInfo.SelectSingleNode("./cg:Id", soapDepartmentResult.Mgr).InnerText.Trim();

                                    string acct_name = xmlNodeUserInfo.SelectSingleNode("./cg:DisplayName", soapDepartmentResult.Mgr).InnerText.Trim();

                                    dt.Rows.Add(acct_account, acct_name, group_code);
                                }
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        this.WriteLog(Log.Mode.LogMode.ERROR, string.Format("AutoCompleteUserAccount.Query.Exception::\r\n{0}", ex.ToString()));
                    }
                    finally
                    {
                        this.Session[sn] = dt;

                        para = null;

                        this.CloseConn();
                    }
                }
                DataRow[] dr = ((DataTable)this.Session[sn]).Select(string.Format("acct_account Like '{0}%'", q));

                for (int i = 0; i < dr.Length; i++)
                {
                    this.Response.Write(dr[i]["acct_account"].ToString().HtmlEncode() + "|" + dr[i]["acct_name"].ToString().HtmlEncode() + Environment.NewLine);
                }
            }
            catch (System.Exception ex)
            {
                this.WriteLog(Log.Mode.LogMode.ERROR, string.Format("AutoCompleteUserAccount.Exception::\r\n{0}", ex.ToString()));
            }
            this.Response.End();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnOK_Click(object sender, EventArgs e)
        {
            List <IDataParameter> para = null;

            string strSql = string.Empty, message = string.Empty;

            SoapResult soapDepartmentResult = null;

            try
            {
                this.WriteLog(string.Format("新增單位"));

                strSql = this.Select.Group(null, this.txtGroupCode.Text.Trim(), null, null, ref para);

                #region SQL Debug

                this.WriteLog(Mode.LogMode.DEBUG, strSql);

                this.WriteLog(para.ToLog());

                #endregion

                if (this.DBConnTransac.GeneralSqlCmd.ExecuteScalar(strSql, para))
                {
                    this.Rollback();

                    this.MessageBox(Mode.LogMode.ERROR, message = string.Format("單位代碼重覆了 ({0})", this.txtGroupCode.Text.Trim().HtmlEncode()));

                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, message);

                    return;
                }
                strSql = this.Insert.Group(this.txtGroupCode.Text.Trim(), this.txtGroupName.Text.Trim(), "0", this.SessionMgr.UserInfos.UserID, ref para);

                #region SQL Debug

                this.WriteLog(Mode.LogMode.DEBUG, strSql);

                this.WriteLog(para.ToLog());

                #endregion

                object group_id_temp = this.DBConnTransac.GeneralSqlCmd.ExecuteItentity(strSql, para);

                if (group_id_temp == null)
                {
                    this.Rollback();

                    this.MessageBox(Mode.LogMode.ERROR, string.Format("新增失敗"));

                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, string.Format("單位代碼:{0},單位名稱:{1}", this.txtGroupCode.Text.Trim(), this.txtGroupName.Text.Trim()));

                    return;
                }
                string group_id = group_id_temp.ToString();

                this.WriteLog(message = string.Format("新增單位編號:{0}", group_id));

                if (this.CopyRoles(group_id))
                {
                    if (Utility.WebConfig.LoginMode.Equals(1))
                    {
                        #region  步單位人員

                        string group_code = this.txtGroupCode.Text.Trim();

                        string adws_url = this.GetSystemSetting("ADWS");

                        string adws_group_name = string.Empty;

                        this.WriteLog(string.Format("AggregateInquiry:{0},{1},{2}", adws_url, group_code, adws_group_name));

                        soapDepartmentResult = this.AggregateInquiry(adws_url, group_code, string.Empty);

                        this.WriteLog(string.Format("AggregateInquiry.Result:{0}", soapDepartmentResult.Info != null ? soapDepartmentResult.Info.Count.ToString() : "Null"));

                        if (soapDepartmentResult.Info != null && soapDepartmentResult.Info.Count > 0)
                        {
                            for (int i = 0; i < soapDepartmentResult.Info.Count; i++)
                            {
                                XmlNode xmlNodeUserInfo = soapDepartmentResult.Info[i];

                                string acct_account = xmlNodeUserInfo.SelectSingleNode("./cg:Id", soapDepartmentResult.Mgr).InnerText.Trim();
                                string acct_name    = xmlNodeUserInfo.SelectSingleNode("./cg:DisplayName", soapDepartmentResult.Mgr).InnerText.Trim();
                                string acct_type    = xmlNodeUserInfo.SelectSingleNode("./cg:Title", soapDepartmentResult.Mgr).InnerText.Trim();

                                strSql = this.Select.AccountType(acct_type, ref para);

                                #region SQL Debug

                                this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                this.WriteLog(para.ToLog());

                                #endregion

                                string type = this.DBConnTransac.GeneralSqlCmd.ExecuteByColumnName(strSql, para, "cus_role_role_id");

                                this.WriteLog(string.Format("Type:{0}={1}", acct_type, type));

                                strSql = this.Select.US(string.Empty, acct_account, string.Empty, ref para);

                                #region SQL Debug

                                this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                this.WriteLog(para.ToLog());

                                #endregion

                                bool check = this.DBConnTransac.GeneralSqlCmd.ExecuteScalar(strSql, para);

                                if (check)
                                {
                                    continue;
                                }

                                this.WriteLog(message = string.Format("Account:{0}\r\n準備同步帳號至資料庫", acct_account));

                                this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.None), this.PageName, message);

                                strSql = this.Insert.LandBack_Account(acct_account, acct_name, type, ref para);

                                #region SQL Debug

                                this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                this.WriteLog(para.ToLog());

                                #endregion

                                object acct_id_temp = this.DBConnTransac.GeneralSqlCmd.ExecuteItentity(strSql, para);

                                if (acct_id_temp == null)
                                {
                                    this.Rollback();

                                    this.MessageBox(Mode.LogMode.ERROR, message = string.Format("同步單位新增使用者失敗"));

                                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, acct_account)); return;
                                }
                                string acct_id = acct_id_temp.ToString();

                                strSql = this.Insert.LandBack_AccountExt(acct_id, ref para);

                                #region SQL Debug

                                this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                this.WriteLog(para.ToLog());

                                #endregion

                                int result = this.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para);

                                if (result.Equals(0))
                                {
                                    this.Rollback();

                                    this.MessageBox(Mode.LogMode.ERROR, message = string.Format("同步單位新增使用者失敗(Ext)"));

                                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.LoginFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, acct_account)); return;
                                }
                                strSql = this.Insert.LandBack_AccountGroup(acct_id, group_id, ref para);

                                #region SQL Debug

                                this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                this.WriteLog(para.ToLog());

                                #endregion

                                result = this.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para);

                                if (result.Equals(0))
                                {
                                    this.Rollback();

                                    this.MessageBox(Mode.LogMode.ERROR, message = string.Format("同步單位新增使用者失敗(Group)"));

                                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.LoginFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, acct_account)); return;
                                }
                                this.WriteLog(message = string.Format("Account:{0}\r\n同步帳號至資料庫完成", acct_account));

                                this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.None), this.PageName, message);
                            }
                        }
                        #endregion
                    }
                    this.DBConnTransac.GeneralSqlCmd.Transaction.Commit();

                    this.MessageBox(Mode.LogMode.INFO, string.Format("新增成功"));

                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.Add), this.PageName, message);
                }
                else
                {
                    this.Rollback();

                    this.MessageBox(Mode.LogMode.ERROR, string.Format("新增失敗,同步權限發生錯誤"));

                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, string.Empty);
                }
            }
            catch (System.Exception ex)
            {
                this.Rollback();

                this.MessageBox(ex);

                this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.SystemError), this.PageName, ex.Message);
            }
            finally
            {
                soapDepartmentResult = null;

                para = null;

                this.CloseConnTransac();

                this.WriteLog(string.Format("新增單位結束"));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string strSql = string.Empty;

            DataTable dt = null, dt_User = null;

            List <IDataParameter> para = null;

            string message             = string.Empty;

            SessionManager.UserInfoLib user_info = null;

            SoapResult soapUserResult = null;

            string aid = string.Empty;

            string ac = this.txtAccount.Value.HtmlEncode();

            string pd = this.txtPassword.Value.HtmlEncode();

            int result = -1;

            try
            {
                if (!String.IsNullOrEmpty(ac) && !String.IsNullOrEmpty(pd))
                {
                    if (!ac.ToLower().Equals("Changingtec".ToLower()) && Utility.WebConfig.LoginMode.Equals(1))
                    {
                        #region LandBank

                        string adws_url = this.GetSystemSetting("ADWS");

                        string adws_group_name = this.GetSystemSetting("AdwsGroupName");

                        this.WriteLog(string.Format("ADWS_URL:{0},GroupName:{1}", adws_url, adws_group_name));

                        if (String.IsNullOrEmpty(adws_group_name))
                        {
                            this.MessageBox("系統錯誤", message = string.Format("缺少系統群組名稱設定(AdwsGroupName)"));

                            this.MyMonitor.LogMonitor(this, MonitorActionMode.Login, null, CaptionMode.Get(CaptionLib.Mode.SystemError), this.PageName, message); return;
                        }
                        this.WriteLog(string.Format("IdVerify:{0},{1},{2}", adws_url, ac, pd.EncryptDES()));

                        soapUserResult = this.IdVerify(adws_url, ac, pd);

                        this.WriteLog(string.Format("IdVerify.StatusCode:{0}", soapUserResult != null ? soapUserResult.StatusCode.ToString() : "Null"));

                        if (soapUserResult == null || !soapUserResult.StatusCode.Equals(0))
                        {
                            this.MyMonitor.LogMonitor(this, MonitorActionMode.Login, null, CaptionMode.Get(CaptionLib.Mode.Login), this.PageName, message = string.Format("Account:{0}\r\nStatus:{1}\r\nSeverity:{2}\r\nDesciption:{3}", ac, soapUserResult.StatusCode, soapUserResult.Severity.HtmlEncode(), soapUserResult.Desciption.HtmlEncode()));

                            this.MessageBox("ADWS 錯誤", message);

                            return;
                        }
                        XmlNode xmlNodeUserInfo = soapUserResult.Info[0];

                        string acct_account = xmlNodeUserInfo.SelectSingleNode("./cg:Id", soapUserResult.Mgr).InnerText.Trim();

                        string acct_name = xmlNodeUserInfo.SelectSingleNode("./cg:DisplayName", soapUserResult.Mgr).InnerText.Trim();

                        string acct_dept = xmlNodeUserInfo.SelectSingleNode("./cg:Department", soapUserResult.Mgr).InnerText.Trim();

                        int acct_type = Convert.ToInt16(xmlNodeUserInfo.SelectSingleNode("./cg:Title", soapUserResult.Mgr).InnerText.Trim());

                        strSql = this.Select.US(string.Empty, acct_account, string.Empty, ref para);

                        #region SQL Debug

                        this.WriteLog(Mode.LogMode.DEBUG, strSql);

                        this.WriteLog(para.ToLog());

                        #endregion

                        dt_User = this.DBConn.GeneralSqlCmd.ExecuteToDataTable(strSql, para);

                        int acct_desc = dt_User.Rows.Count > 0 && dt_User.Rows[0]["acct_desc"] != DBNull.Value && !String.IsNullOrEmpty(dt_User.Rows[0]["acct_desc"].ToString()) ? Convert.ToInt32(dt_User.Rows[0]["acct_desc"].ToString()) : -1;

                        bool check = dt_User.Rows.Count.Equals(0) || (dt_User.Rows.Count > 0 && (acct_desc.Equals(-1) || acct_desc.Equals(0)));

                        this.WriteLog(string.Format("dt_User.Rows.Count:{0},acct_desc:{1},check:{2}", dt_User.Rows.Count, acct_desc, check));

                        if (check && (acct_type == 1 || acct_type == 2))
                        {
                            #region 新增帳號

                            string group_id = string.Empty;

                            DataTable dt_Dept = null;
                            try
                            {
                                this.CloseConn();

                                string acct_id = string.Empty;

                                if (dt_User.Rows.Count.Equals(0))
                                {
                                    strSql = this.Select.Group(null, acct_dept, null, null, ref para);

                                    #region SQL Debug

                                    this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                    this.WriteLog(para.ToLog());

                                    #endregion

                                    dt_Dept = this.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para);

                                    this.WriteLog(string.Format("Group.Result::{0}", dt_Dept.Rows.Count.ToString()));

                                    if (dt_Dept.Rows.Count.Equals(0))
                                    {
                                        strSql = this.Insert.Group(acct_dept, acct_dept, "0", this.SessionMgr.UserInfos.UserID, ref para);

                                        #region SQL Debug

                                        this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                        this.WriteLog(para.ToLog());

                                        #endregion

                                        object group_id_temp = this.DBConnTransac.GeneralSqlCmd.ExecuteItentity(strSql, para);

                                        if (group_id_temp == null)
                                        {
                                            this.Rollback();

                                            this.MessageBox(Mode.LogMode.ERROR, message = string.Format("新增單位失敗"));

                                            this.WriteLog(message);

                                            this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, string.Format("單位代碼:{0},單位名稱:{1}", acct_dept, acct_dept));

                                            return;
                                        }
                                        group_id = group_id_temp.ToString();

                                        if (this.CopyRoles(group_id))
                                        {
                                            #region  步單位人員

                                            string group_code = acct_dept;

                                            this.WriteLog(string.Format("AggregateInquiry:{0},{1},{2}", adws_url, group_code, adws_group_name));

                                            SoapResult soapDepartmentResult = this.AggregateInquiry(adws_url, group_code, string.Empty);

                                            this.WriteLog(string.Format("AggregateInquiry.Result:{0}", soapDepartmentResult.Info != null ? soapDepartmentResult.Info.Count.ToString() : "Null"));

                                            if (soapDepartmentResult.Info != null && soapDepartmentResult.Info.Count > 0)
                                            {
                                                for (int i = 0; i < soapDepartmentResult.Info.Count; i++)
                                                {
                                                    XmlNode xmlNodeUserInfo2 = soapDepartmentResult.Info[i];

                                                    string acct_account2 = xmlNodeUserInfo2.SelectSingleNode("./cg:Id", soapDepartmentResult.Mgr).InnerText.Trim();
                                                    string acct_name2    = xmlNodeUserInfo2.SelectSingleNode("./cg:DisplayName", soapDepartmentResult.Mgr).InnerText.Trim();
                                                    string acct_type2    = xmlNodeUserInfo2.SelectSingleNode("./cg:Title", soapDepartmentResult.Mgr).InnerText.Trim();

                                                    strSql = this.Select.AccountType(acct_type2, ref para);

                                                    #region SQL Debug

                                                    this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                                    this.WriteLog(para.ToLog());

                                                    #endregion

                                                    string type2 = this.DBConnTransac.GeneralSqlCmd.ExecuteByColumnName(strSql, para, "cus_role_role_id");

                                                    this.WriteLog(string.Format("Type:{0}={1}", acct_type2, type2));

                                                    strSql = this.Select.US(string.Empty, acct_account2, string.Empty, ref para);

                                                    #region SQL Debug

                                                    this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                                    this.WriteLog(para.ToLog());

                                                    #endregion

                                                    check = this.DBConnTransac.GeneralSqlCmd.ExecuteScalar(strSql, para);

                                                    if (check)
                                                    {
                                                        continue;
                                                    }

                                                    this.WriteLog(message = string.Format("Account:{0}\r\n準備同步帳號至資料庫", acct_account2));

                                                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.None), this.PageName, message);

                                                    strSql = this.Insert.LandBack_Account(acct_account2, acct_name2, type2, ref para);

                                                    #region SQL Debug

                                                    this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                                    this.WriteLog(para.ToLog());

                                                    #endregion

                                                    object acct_id_temp2 = this.DBConnTransac.GeneralSqlCmd.ExecuteItentity(strSql, para);

                                                    if (acct_id_temp2 == null)
                                                    {
                                                        this.Rollback();

                                                        this.MessageBox(Mode.LogMode.ERROR, message = string.Format("同步單位新增使用者失敗"));

                                                        this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, acct_account2)); return;
                                                    }
                                                    string acct_id2 = acct_id_temp2.ToString();

                                                    strSql = this.Insert.LandBack_AccountExt(acct_id2, ref para);

                                                    #region SQL Debug

                                                    this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                                    this.WriteLog(para.ToLog());

                                                    #endregion

                                                    result = this.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para);

                                                    if (result.Equals(0))
                                                    {
                                                        this.Rollback();

                                                        this.MessageBox(Mode.LogMode.ERROR, message = string.Format("同步單位新增使用者失敗(Ext)"));

                                                        this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.LoginFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, acct_account2)); return;
                                                    }
                                                    strSql = this.Insert.LandBack_AccountGroup(acct_id2, group_id, ref para);

                                                    #region SQL Debug

                                                    this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                                    this.WriteLog(para.ToLog());

                                                    #endregion

                                                    result = this.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para);

                                                    if (result.Equals(0))
                                                    {
                                                        this.Rollback();

                                                        this.MessageBox(Mode.LogMode.ERROR, message = string.Format("同步單位新增使用者失敗(Group)"));

                                                        this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.LoginFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, acct_account2)); return;
                                                    }
                                                    this.WriteLog(message = string.Format("Account:{0}\r\n同步帳號至資料庫完成", acct_account2));

                                                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.None), this.PageName, message);
                                                }
                                            }
                                            #endregion
                                        }
                                        else
                                        {
                                            this.Rollback();

                                            this.MessageBox(Mode.LogMode.ERROR, message = string.Format("新增失敗,同步權限發生錯誤"));

                                            this.WriteLog(message);

                                            this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, string.Empty);
                                        }
                                    }
                                    else
                                    {
                                        group_id = dt_Dept.Rows[0]["group_id"].ToString().Trim();
                                    }

                                    dt_Dept = null;

                                    this.WriteLog(string.Format("GroupID:{0}", group_id));

                                    strSql = this.Select.AccountType(acct_type.ToString(), ref para);

                                    #region SQL Debug

                                    this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                    this.WriteLog(para.ToLog());

                                    #endregion

                                    string type = this.DBConnTransac.GeneralSqlCmd.ExecuteByColumnName(strSql, para, "cus_role_role_id");

                                    this.WriteLog(string.Format("Type:{0}={1}", acct_type.ToString(), type));

                                    strSql = this.Insert.LandBack_Account(acct_account, acct_name, type, ref para);

                                    #region SQL Debug

                                    this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                    this.WriteLog(para.ToLog());

                                    #endregion

                                    object acct_id_temp = this.DBConnTransac.GeneralSqlCmd.ExecuteItentity(strSql, para);

                                    this.WriteLog(string.Format("同步單位新增使用者:{0}", acct_id_temp == null ? "Fail" : "Pass"));

                                    if (acct_id_temp == null)
                                    {
                                        this.Rollback();

                                        this.MessageBox(Mode.LogMode.ERROR, message = string.Format("同步單位新增使用者失敗"));

                                        this.WriteLog(message);

                                        this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, acct_account)); return;
                                    }
                                    acct_id = acct_id_temp.ToString();

                                    strSql = this.Insert.LandBack_AccountExt(acct_id, ref para);

                                    #region SQL Debug

                                    this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                    this.WriteLog(para.ToLog());

                                    #endregion

                                    result = this.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para);

                                    this.WriteLog(string.Format("同步單位新增使用者失敗(Ext):{0}", result.Equals(0) ? "Fail" : "Pass"));

                                    if (result.Equals(0))
                                    {
                                        this.Rollback();

                                        this.MessageBox(Mode.LogMode.ERROR, message = string.Format("同步單位新增使用者失敗(Ext)"));

                                        this.WriteLog(message);

                                        this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, acct_account)); return;
                                    }
                                    strSql = this.Insert.LandBack_AccountGroup(acct_id, group_id, ref para);

                                    #region SQL Debug

                                    this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                    this.WriteLog(para.ToLog());

                                    #endregion

                                    result = this.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para);

                                    this.WriteLog(string.Format("同步單位新增使用者失敗(Group):{0}", result.Equals(0) ? "Fail" : "Pass"));

                                    if (result.Equals(0))
                                    {
                                        this.Rollback();

                                        this.MessageBox(Mode.LogMode.ERROR, message = string.Format("同步單位新增使用者失敗(Group)"));

                                        this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, acct_account)); return;
                                    }
                                }
                                else
                                {
                                    acct_id = dt_User.Rows[0]["acct_id"].ToString().Trim();
                                }

                                #region 新增預設角色

                                strSql = this.Select.DefaultRole(acct_account, ref para);

                                #region SQL Debug

                                this.WriteLog(Mode.LogMode.DEBUG, strSql);

                                this.WriteLog(para.ToLog());

                                #endregion

                                string role_id = this.DBConnTransac.GeneralSqlCmd.ExecuteByColumnName(strSql, para, "role_id");

                                if (String.IsNullOrEmpty(role_id))
                                {
                                    this.Rollback();

                                    this.MessageBox(Mode.LogMode.ERROR, message = string.Format("該使用者沒有預設的角色 ({0})", acct_account.HtmlEncode()));

                                    this.WriteLog(message);

                                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, this.SessionMgr.UserInfos.UserID, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, message);

                                    return;
                                }
                                strSql = this.Insert.UserRoles(role_id, acct_id, "0", ref para);

                                result = this.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para);

                                this.WriteLog(string.Format("同步預設角色失敗(Role):{0}", result.Equals(0) ? "Fail" : "Pass"));

                                if (result.Equals(0))
                                {
                                    this.Rollback();

                                    this.MessageBox(Mode.LogMode.ERROR, message = string.Format("同步預設角色失敗(Role)"));

                                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Add, null, CaptionMode.Get(CaptionLib.Mode.AddFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, acct_account)); return;
                                }
                                #endregion

                                this.DBConnTransac.GeneralSqlCmd.Transaction.Commit();

                                check = true;

                                this.WriteLog(message = string.Format("Account:{0}\r\n同步帳號至資料庫完成", acct_account));
                            }
                            catch (System.Exception ex)
                            {
                                this.WriteLog(Log.Mode.LogMode.ERROR, ex.ToString());

                                this.Rollback();
                            }
                            finally
                            {
                                this.CloseConnTransac();
                            }
                            #endregion
                        }
                        else
                        {
                            check = dt_User.Rows.Count > 0;
                        }

                        if (!check)
                        {
                            this.MessageBox("登入錯誤", message = string.Format("帳號尚未建立"));

                            this.MyMonitor.LogMonitor(this, MonitorActionMode.Login, null, CaptionMode.Get(CaptionLib.Mode.LoginFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, ac)); return;
                        }
                        else
                        {
                            strSql = this.Select.US(string.Empty, ac, string.Empty, ref para);

                            #region SQL Debug

                            this.WriteLog(Mode.LogMode.DEBUG, strSql);

                            this.WriteLog(para.ToLog());

                            #endregion

                            dt = this.DBConn.GeneralSqlCmd.ExecuteToDataTable(strSql, para);

                            if (dt.Rows.Count.Equals(0))
                            {
                                this.MessageBox("登入錯誤", message = string.Format("帳號錯誤"));

                                this.MyMonitor.LogMonitor(this, MonitorActionMode.Login, null, CaptionMode.Get(CaptionLib.Mode.LoginFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, ac)); return;
                            }
                            aid = dt.Rows[0]["acct_id"].ToString().Trim();
                        }
                        #endregion
                    }
                    else
                    {
                        #region 一般登入

                        strSql = this.Select.US(string.Empty, ac, pd.EncryptDES(), ref para);

                        #region SQL Debug

                        this.WriteLog(Mode.LogMode.DEBUG, strSql);

                        this.WriteLog(para.ToLog());

                        #endregion

                        dt = this.DBConn.GeneralSqlCmd.ExecuteToDataTable(strSql, para);

                        if (dt.Rows.Count.Equals(0))
                        {
                            this.MessageBox("登入錯誤", message = string.Format("帳號或密碼錯誤"));

                            this.MyMonitor.LogMonitor(this, MonitorActionMode.Login, null, CaptionMode.Get(CaptionLib.Mode.LoginFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, ac)); return;
                        }
                        aid = dt.Rows[0]["acct_id"].ToString().Trim();

                        #endregion
                    }
                    user_info = this.GetUserInfo(aid.HtmlEncode());

                    if (!user_info.IsSuperUser && user_info.Status.Equals(99))
                    {
                        this.MessageBox("登入錯誤", message = string.Format("帳號已停用"));

                        this.MyMonitor.LogMonitor(this, MonitorActionMode.Login, null, CaptionMode.Get(CaptionLib.Mode.LoginFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, ac)); return;
                    }

                    #region Login Count

                    strSql = this.Update.LoginCount(user_info.UserID, ref para);

                    #region SQL Debug

                    this.WriteLog(Mode.LogMode.DEBUG, strSql);

                    this.WriteLog(para.ToLog());

                    #endregion

                    this.DBConn.GeneralSqlCmd.ExecuteNonQuery(strSql, para);

                    #endregion

                    this.SessionMgr.UserInfos = user_info;

                    this.InitLog();

                    this.WriteLog(this.IPv4);

                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Login, null, CaptionMode.Get(CaptionLib.Mode.Login), this.PageName, string.Format("Account:{0}", ac));

                    Server.Transfer(this.AppendToken("Main.aspx"), false);
                }
                else
                {
                    this.MessageBox("登入錯誤", message = string.Format("未填入帳號與密碼"));

                    this.MyMonitor.LogMonitor(this, MonitorActionMode.Login, null, CaptionMode.Get(CaptionLib.Mode.LoginFail), this.PageName, string.Format("Account:{1}\r\n{0}", message, ac));
                }
            }
            catch (System.Threading.ThreadAbortException) { }
            catch (System.Exception ex)
            {
                this.Rollback();

                this.WriteLog(Log.Mode.LogMode.ERROR, ex.ToString()); this.MessageBox("發生錯誤", string.Format("一般登入發生錯誤"));

                this.MyMonitor.LogMonitor(this, MonitorActionMode.Login, null, CaptionMode.Get(CaptionLib.Mode.SystemError), this.PageName, string.Format("Account:{1}\r\n{0}", ex.Message, ac));
            }
            finally
            {
                soapUserResult = null;

                dt = dt_User = null;

                para = null;

                this.CloseConn();
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="WebServiceUrl"></param>
        /// <param name="ID"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public SoapResult AggregateInquiry(string WebServiceUrl, string Department, string GroupName)
        {
            SoapResult result = new SoapResult();

            XmlDocument xmlDocRequest = null, xmlDocResponse = null;

            string soap_result = string.Empty;

            try
            {
                this.WriteLog(Log.Mode.LogMode.INFO, string.Format("[SOAP]AggregateInquiry::Department:{0},GroupName:{1}", Department, GroupName));

                string soap_request_path = Utility.WebConfig.LandBank_AggregateInquiryPath;

                string soap_request = File.ReadAllText(soap_request_path, Encoding.UTF8);

                soap_request = soap_request.Replace("[Department]", Department).Replace("[GroupName]", GroupName);

                this.WriteLog(Log.Mode.LogMode.DEBUG, string.Format("[SOAP]AggregateInquiry.Request::{0}", soap_request.EncryptDES()));

                xmlDocRequest = new XmlDocument();
                xmlDocRequest.LoadXml(soap_request);

                soap_result = GetSoapResponse(WebServiceUrl, xmlDocRequest.OuterXml);

                this.WriteLog(Log.Mode.LogMode.DEBUG, string.Format("[SOAP]AggregateInquiry.Response::{0}", soap_result.EncryptDES()));

                xmlDocResponse = new XmlDocument();
                xmlDocResponse.LoadXml(soap_result);

                result.Mgr = new XmlNamespaceManager(xmlDocResponse.NameTable);
                result.Mgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
                result.Mgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
                result.Mgr.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
                result.Mgr.AddNamespace("cg", "http://microsoft.com/taiwan/mcs");

                XmlNode xmlNodeResult = xmlDocResponse.SelectSingleNode(string.Format("./soap:Envelope/soap:Body/cg:AggregateInquiryResponse/cg:AggregateInquiryResult"), result.Mgr);

                XmlNode xmlNodeStatus = xmlNodeResult.SelectSingleNode("./cg:Status", result.Mgr);

                result.StatusCode = Convert.ToInt32(xmlNodeStatus.SelectSingleNode("./cg:StatusCode", result.Mgr).InnerText.Trim());
                result.Severity   = xmlNodeStatus.SelectSingleNode("./cg:Severity", result.Mgr).InnerText.Trim();
                result.Desciption = xmlNodeStatus.SelectSingleNode("./cg:Desciption", result.Mgr).InnerText.Trim();

                result.Info = xmlNodeResult.SelectNodes("./cg:Users/cg:UserInfo", result.Mgr);

                if (!result.StatusCode.Equals(0))
                {
                    this.WriteLog(Log.Mode.LogMode.ERROR, string.Format("[SOAP]AggregateInquiry.ERROR::{0},{1},{2}", result.StatusCode, result.Severity, result.Desciption));
                }
            }
            catch (System.Exception ex)
            {
                soap_result = ex.ToString();

                this.WriteLog(Log.Mode.LogMode.ERROR, string.Format("[SOAP]AggregateInquiry.Exception::\r\n{0}", ex.ToString()));
            }
            finally
            {
                if (xmlDocRequest != null)
                {
                    xmlDocRequest = null;
                }

                if (xmlDocResponse != null)
                {
                    xmlDocResponse = null;
                }
            }
            return(result);
        }