示例#1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string        SrtConnString = WebConfigurationManager.ConnectionStrings["SageConnnetionString"].ConnectionString;
        SqlConnection db            = new SqlConnection(SrtConnString);

        try
        {
            db.Open();

            if (!Page.IsPostBack)
            {
                List <string> _Userinfo = new List <string>();
                _Userinfo = (List <string>)Session["Userinfo"];

                if (Session["Userinfo"] != null)
                {
                    string Username = _Userinfo[3].ToString();

                    HdnUser.Value = Username;
                }
                else
                {
                    Response.Redirect(ResolveClientUrl("~/"));
                }

                StringBuilder sb = new StringBuilder();
                sb.AppendLine(" SELECT rw.RW_ID, ");
                sb.AppendLine(" RewardName, ");
                sb.AppendLine(" RewardPicture, ");
                sb.AppendLine(" RewardPoint, ");
                sb.AppendLine(" RewardStore, ");
                sb.AppendLine(" rw.CreatedDate, ");
                sb.AppendLine(" CONVERT(date, rw.ExpiredDate) as ExpiredDate, ");
                sb.AppendLine(" case when RewardStatus = 1 then 'Active' else 'In-Active' end as [Status] ");
                sb.AppendLine(" FROM HR_Rewards as rw ");
                sb.AppendLine(" WHERE 1=1 ");

                SqlCommand sql = new SqlCommand(sb.ToString(), db);

                DataTable table = new DataTable();
                table.Load(sql.ExecuteReader());

                if (table.Rows.Count > 0)
                {
                    RptReward.DataSource = table;
                }

                RptReward.DataBind();
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message + "<br/>");
            Response.Write(ex.StackTrace + "<br/>");
        }
        finally
        {
            db.Close();
        }
    }
示例#2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string        SrtConnString = WebConfigurationManager.ConnectionStrings["SageConnnetionString"].ConnectionString;
        SqlConnection db            = new SqlConnection(SrtConnString);

        try
        {
            db.Open();

            if (!Page.IsPostBack)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(" SELECT TOP 8 RW_ID, ");
                sb.AppendLine(" RewardName, ");
                sb.AppendLine(" RewardStore, ");
                sb.AppendLine(" RewardPoint, ");
                sb.AppendLine(" RewardPicture, ");
                sb.AppendLine(" CONVERT(date, rw.ExpiredDate), ");
                sb.AppendLine(" ROW_NUMBER() OVER(ORDER BY CreatedDate DESC) AS row ");
                sb.AppendLine(" FROM HR_Rewards as rw ");
                sb.AppendLine(" WHERE 1=1 ");
                sb.AppendLine(" and rw.RewardStatus = '1' ");
                sb.AppendLine(" and CONVERT(date, rw.ExpiredDate) >= CONVERT(date, GETDATE()) ");
                sb.AppendLine(" ORDER BY CreatedDate DESC ");

                SqlCommand sql = new SqlCommand(sb.ToString(), db);

                DataTable table = new DataTable();
                table.Load(sql.ExecuteReader());

                if (table.Rows.Count > 0)
                {
                    RptReward.DataSource = table;
                }

                RptReward.DataBind();

                if (table.Rows.Count < 8)
                {
                    PnMore.Visible = false;
                }

                sb = new StringBuilder();
                sb.AppendLine(" SELECT TOP 5 em.Fname ");
                sb.AppendLine(" ,em.Lname ");
                sb.AppendLine(" ,em.Department ");
                sb.AppendLine(" ,em.Position ");
                sb.AppendLine(" ,pb.Point_Balance ");
                sb.AppendLine(" ,em.Email ");
                sb.AppendLine(" FROM Point_Balance as pb ");
                sb.AppendLine(" LEFT JOIN crm.dbo.vWSE_HR_EmployeeData as em on em.Email = pb.Email ");
                sb.AppendLine(" WHERE 1=1 ");
                sb.AppendLine(" and ResignStatus = 1 ");
                sb.AppendLine(" and EndDate is null ");
                sb.AppendLine(" ORDER BY Point_Balance DESC ");

                sql = new SqlCommand(sb.ToString(), db);

                table = new DataTable();
                table.Load(sql.ExecuteReader());

                if (table.Rows.Count > 0)
                {
                    table.Columns.Add("Img");

                    foreach (DataRow row in table.Rows)
                    {
                        try
                        {
                            var email = row["Email"].ToString();
                            if (email == null)
                            {
                                row["Img"] = ResolveClientUrl("~/images/iconperson.png");
                            }

                            HttpWebRequest request = WebRequest.Create("https://mail.wallstreetenglish.in.th/ews/Exchange.asmx/s/GetUserPhoto?email=" + email + "&size=HR240x240") as HttpWebRequest;
                            // Submit the request.
                            System.Net.NetworkCredential netCredential = new System.Net.NetworkCredential("it.report", "Report345!");
                            request.Credentials = netCredential;
                            using (HttpWebResponse resp = request.GetResponse() as HttpWebResponse)
                            {
                                // Take the response and save it as an image.
                                Bitmap image = new Bitmap(resp.GetResponseStream());
                                using (MemoryStream ms = new MemoryStream())
                                {
                                    image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                                    byte[] byteImage = ms.ToArray();
                                    var    ImgUrl    = "data:image/png;base64," + Convert.ToBase64String(byteImage);
                                    row["Img"] = ImgUrl;
                                }
                            }
                        }
                        catch
                        {
                            row["Img"] = ResolveClientUrl("~/images/iconperson.png");
                        }
                    }

                    RptTop.DataSource = table;
                }

                RptTop.DataBind();
            }
        }
        catch (Exception ex)
        {
        }
        finally
        {
            db.Close();
        }
    }