Beispiel #1
0
        public static WebUser getCurrentUser(string strDeptCode)
        {
            WebUser user    = new WebUser();
            string  strConn = System.Configuration.ConfigurationManager.ConnectionStrings["strEBMS_Snapshot_Conn"].ConnectionString;

            SqlConnection conn = new SqlConnection(strConn);

            try
            {
                conn.Open();

                string strSQL = "select Noti_Dep_Desc, Dep_User_Id, Noti_Method, EmailAddress, WindowsLoginManager from Noti_Dept where Noti_Dep_Code=@deptcode";

                SqlCommand comm = new SqlCommand(strSQL, conn);
                comm.Parameters.Add("@deptcode", SqlDbType.VarChar, 20).Value = strDeptCode;
                SqlDataReader dr = comm.ExecuteReader();

                if (dr.Read())
                {
                    if (dr.HasRows)
                    {
                        user.departmentname       = dr["Noti_Dep_Desc"].ToString();
                        user.notify_method        = dr["Noti_Method"].ToString();
                        user.dep_userid           = dr["Dep_User_Id"].ToString();
                        user.emailaddress         = dr["EmailAddress"].ToString();
                        user.windows_login_userid = dr["WindowsLoginManager"].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                conn.Close();
            }
            return(user);
        }
Beispiel #2
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            string strDeptCode    = txtdeptid.Value.ToString();
            string strDeptDesc    = txtdeptname.Value.ToString();
            string strNotiMethod  = selmethod.Value.ToString();
            string strUserId      = txtUserId.Value.ToString();
            string strWindowsUser = txtwindowsuser.Value.ToString();

            bool isExist = UserInfo.CheckDepartmentExist(strDeptCode);

            if (!isExist)
            {
                bool isSuccess = UserInfo.createdepartment(strDeptCode, strDeptDesc, strUserId, strNotiMethod, strWindowsUser, "");

                if (isSuccess)
                {
                    WebUser user = new WebUser();
                    user.username             = strLoginUser;
                    user.departmentid         = strDeptCode;
                    user.departmentname       = strDeptDesc;
                    user.dep_userid           = strUserId;
                    user.notify_method        = strNotiMethod;
                    user.emailaddress         = "";
                    user.isSuperUser          = true;
                    user.windows_login_userid = strWindowsUser;

                    UserInfo.currentUser = user;

                    Response.Redirect("default.aspx");
                }
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('the department/user is already exist')", true);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            user0 = UserInfo.currentUser;
            WebUser user1 = UserInfo.currentUser;

            if (user0 != null)
            {
                user0 = UserInfo.getCurrentUser(user0.departmentid);
                user0.departmentid   = user1.departmentid;
                user0.isSuperUser    = user1.isSuperUser;
                user0.username       = user1.username;
                username.Value       = user0.username;
                departmentid.Value   = user0.departmentid;
                departmentname.Value = user0.departmentname;
                dep_userid.Value     = user0.dep_userid;
                txtdeptid.Value      = user0.departmentid;
                notify_method.Value  = user0.notify_method;
                emailaddress.Value   = user0.emailaddress;
                isSuperUser.Value    = user0.isSuperUser ? "true" : "false";
                txtwindowsuser.Value = user0.windows_login_userid;
                if (isSuperUser.Value == "true")
                {
                    liupdate.Visible = true;
                }
                else
                {
                    liupdate.Visible = false;
                }

                lbDepartmentName.Text = departmentname.Value;
                txtdeptname.Value     = departmentname.Value;
                if (!string.IsNullOrEmpty(notify_method.Value))
                {
                    lbNotifyMethod.Text = notify_method.Value;
                    selmethod.Value     = notify_method.Value;
                }

                if (notify_method.Value == "Activity")
                {
                    lbNotifyUser.Text        = dep_userid.Value;
                    selmethod.SelectedIndex  = 0;
                    lbNotifyUserId.InnerText = "Notify User Id: ";
                    txtUserId.Value          = dep_userid.Value;
                }
                else if (notify_method.Value == "Email")
                {
                    lbNotifyUser.Text        = emailaddress.Value;
                    selmethod.SelectedIndex  = 1;
                    lbNotifyUserId.InnerText = "Email Address: ";
                    txtUserId.Value          = emailaddress.Value;
                }
                else if (notify_method.Value == "Both")
                {
                    lbNotifyUser.Text = dep_userid.Value + " & " + emailaddress.Value;
                    txtUserId.Value   = dep_userid.Value;
                }
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }
Beispiel #4
0
        public static List <WebUser> getDepartments(string strUserName, bool isSuperUser)
        {
            List <WebUser> lstuser = new List <WebUser>();

            DataTable dt = new DataTable();

            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["strEBMS_Snapshot_Conn"].ConnectionString;

            SqlConnection conn = new SqlConnection(strConn);


            try
            {
                conn.Open();

                string strSQL = "";

                if (isSuperUser)
                {
                    strSQL = "select Noti_Dep_Code,Noti_Dep_Desc,Dep_User_Id,Noti_Method,EmailAddress, WindowsLoginManager from Noti_Dept where status='1' ";
                }
                else
                {
                    strSQL = "select Noti_Dep_Code,Noti_Dep_Desc,Dep_User_Id,Noti_Method,EmailAddress, WindowsLoginManager from Noti_Dept where status='1' and WindowsLoginManager like '%" + strUserName + "%'";
                }

                SqlCommand     comm = new SqlCommand(strSQL, conn);
                SqlDataAdapter da   = new SqlDataAdapter(comm);
                da.Fill(dt);
                da.FillSchema(dt, SchemaType.Source);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                conn.Close();
            }


            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr["Noti_Dep_Code"] != DBNull.Value && dr["Noti_Dep_Desc"] != DBNull.Value)
                    {
                        WebUser user = new WebUser();
                        user.username             = strUserName;
                        user.departmentid         = dr["Noti_Dep_Code"].ToString();
                        user.departmentname       = dr["Noti_Dep_Desc"].ToString();
                        user.notify_method        = dr["Noti_Method"].ToString();
                        user.dep_userid           = dr["Dep_User_Id"].ToString();
                        user.emailaddress         = dr["EmailAddress"].ToString();
                        user.windows_login_userid = dr["WindowsLoginManager"].ToString();
                        lstuser.Add(user);
                    }
                }
            }

            return(lstuser);
        }