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

        try
        {
            List <string> _Userinfo = new List <string>();
            _Userinfo = (List <string>)Session["Userinfo"];

            string group = "";
            if (Session["Userinfo"] != null)
            {
                group          = _Userinfo[2].ToString();
                HdnGroup.Value = group;
            }

            db.Open();

            StringBuilder sb = new StringBuilder();
            sb.AppendLine(" SELECT DIR_Title, ");
            sb.AppendLine(" DIR_UploadImage, ");
            sb.AppendLine(" DIR_ID ");
            sb.AppendLine(" FROM HR_Announcement as an ");
            sb.AppendLine(" LEFT JOIN HR_Group as gr on an.DIR_Group = gr.GP_ID ");
            sb.AppendLine(" WHERE 1=1 ");
            sb.AppendLine(" and (gr.GP_Name = '" + group + "' or an.DIR_Group = 0) ");
            sb.AppendLine(" and an.DIR_Deleted is null ");
            sb.AppendLine(" and an.DIR_Status = 1 ");
            sb.AppendLine(" and an.DIR_Type = 2 ");
            sb.AppendLine(" and CONVERT(date, an.DIR_StartDate) <= CONVERT(date, GETDATE()) ");
            sb.AppendLine(" and (CONVERT(date, an.DIR_EndDate) > CONVERT(date, GETDATE()) or an.DIR_EndDate is null) ");
            sb.AppendLine(" ORDER BY DIR_SlideOrder, DIR_StartDate DESC ");

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

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

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

            RptSlideNumber.DataBind();
            RptSlide.DataBind();

            sb = new StringBuilder();
            sb.AppendLine(" SELECT TOP 8 DIR_Title, ");
            sb.AppendLine(" DIR_UploadImage, ");
            sb.AppendLine(" DIR_ID, ");
            sb.AppendLine(" DIR_Detail, ");
            sb.AppendLine(" DIR_UploadDoc, ");
            sb.AppendLine(" DIR_UploadImage, ");
            sb.AppendLine(" DIR_StartDate, ");
            sb.AppendLine(" DIR_Type ");
            sb.AppendLine(" FROM HR_Announcement as an ");
            sb.AppendLine(" WHERE 1=1 ");
            sb.AppendLine(" and an.DIR_Deleted is null ");
            sb.AppendLine(" and an.DIR_Status = 1 ");
            sb.AppendLine(" and an.DIR_Type in (1,3) ");
            sb.AppendLine(" and CONVERT(date, an.DIR_StartDate) <= CONVERT(date, GETDATE()) ");
            sb.AppendLine(" and (CONVERT(date, an.DIR_EndDate) > CONVERT(date, GETDATE()) or an.DIR_EndDate is null) ");
            sb.AppendLine(" ORDER BY DIR_SlideOrder, DIR_StartDate DESC ");

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

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

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

            RptAnnouncement.DataBind();

            if (table.Rows.Count < 8)
            {
                PnMore.Visible = false;
            }
        }
        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();

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

            if (!Page.IsPostBack)
            {
                sb = new StringBuilder();
                sb.AppendLine(" SELECT AN_AnnouncementTypeID, ");
                sb.AppendLine(" AN_TypeName ");
                sb.AppendLine(" FROM HR_AnnouncementType ");
                sb.AppendLine(" WHERE 1=1 ");
                sb.AppendLine(" and AN_Deleted is null ");

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

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

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

                ddlType.DataBind();
                DdlType_.DataBind();
                DdlType_.Items.Insert(0, new ListItem("ALL", ""));

                sb = new StringBuilder();
                sb.AppendLine(" SELECT GP_ID, ");
                sb.AppendLine(" GP_DisplayName ");
                sb.AppendLine(" FROM HR_Group ");
                sb.AppendLine(" WHERE 1=1 ");
                sb.AppendLine(" and GP_Deleted is null ");

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

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

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

                ddlGroup.DataBind();
                DdlGroup_.DataBind();

                ddlGroup.Items.Insert(0, new ListItem("ALL", "0"));
                DdlGroup_.Items.Insert(0, new ListItem("ALL", "0"));
            }
            else
            {
                string Action = HdnAction.Value;
                string AnID   = HdnAnID.Value;

                if (Action.Equals("confirm"))
                {
                    string DIR_ID = AnID;
                    string Type   = ddlType.SelectedValue;
                    string Group  = ddlGroup.SelectedValue;
                    string Title  = txtTitle.Text;

                    string Detail = "";
                    if (Type.Equals("1"))
                    {
                        Detail = editorDetailEN.Value.ToString();
                    }
                    else
                    {
                        Detail = txtDetail.Text;
                    }

                    string StartDate = txtStartDate.Text;

                    string[] startdateSplit = StartDate.Split('/');

                    StartDate = startdateSplit[2].ToString() + "-" + startdateSplit[1] + "-" + startdateSplit[0].ToString();

                    string EndDate = txtEndDate.Text;

                    if (!EndDate.Equals(""))
                    {
                        string[] enddateSplit = EndDate.Split('/');

                        EndDate = enddateSplit[2].ToString() + "-" + enddateSplit[1] + "-" + enddateSplit[0].ToString();
                    }

                    bool   check   = gridCheck.Checked;
                    string OrderBy = TxtOrderBy.Text;

                    if (OrderBy.Equals(""))
                    {
                        OrderBy = "999";
                    }

                    string Status = DdlStatus.Text;

                    if (DIR_ID.Equals(""))
                    {
                        sb = new StringBuilder();
                        sb.AppendLine(" INSERT INTO HR_Announcement ");
                        sb.AppendLine(" ( ");
                        sb.AppendLine(" 	DIR_Type, ");
                        sb.AppendLine(" 	DIR_Group, ");
                        sb.AppendLine(" 	DIR_Title, ");
                        sb.AppendLine(" 	DIR_Detail, ");
                        sb.AppendLine(" 	DIR_StartDate, ");
                        sb.AppendLine(" 	DIR_EndDate, ");
                        sb.AppendLine(" 	DIR_SlideOrder, ");
                        sb.AppendLine(" 	DIR_Status, ");
                        sb.AppendLine(" 	DIR_Highlight ");
                        sb.AppendLine(" ) ");
                        sb.AppendLine(" VALUES ");
                        sb.AppendLine(" ( ");
                        sb.AppendLine(" 	@DIR_Type, ");
                        sb.AppendLine(" 	@DIR_Group, ");
                        sb.AppendLine(" 	@DIR_Title, ");
                        sb.AppendLine(" 	@DIR_Detail, ");
                        sb.AppendLine(" 	@DIR_StartDate, ");
                        sb.AppendLine(" 	@DIR_EndDate, ");
                        sb.AppendLine(" 	@DIR_SlideOrder, ");
                        sb.AppendLine(" 	@DIR_Status, ");
                        sb.AppendLine(" 	@DIR_Highlight ");
                        sb.AppendLine(" ) ");
                        sb.AppendLine("  ");
                        sb.AppendLine(" SELECT SCOPE_IDENTITY() ");

                        sql = new SqlCommand(sb.ToString(), db);
                        sql.Parameters.AddWithValue("DIR_Type", Type);
                        sql.Parameters.AddWithValue("DIR_Group", Group);
                        sql.Parameters.AddWithValue("DIR_Title", Title);
                        sql.Parameters.AddWithValue("DIR_Detail", Detail);
                        sql.Parameters.AddWithValue("DIR_StartDate", StartDate);

                        if (EndDate.Equals(""))
                        {
                            sql.Parameters.AddWithValue("DIR_EndDate", DBNull.Value);
                        }
                        else
                        {
                            sql.Parameters.AddWithValue("DIR_EndDate", EndDate);
                        }

                        sql.Parameters.AddWithValue("DIR_SlideOrder", OrderBy);
                        sql.Parameters.AddWithValue("DIR_Status", Status);
                        sql.Parameters.AddWithValue("DIR_Highlight", check);

                        DIR_ID = sql.ExecuteScalar().ToString();
                    }
                    else
                    {
                        sb = new StringBuilder();
                        sb.AppendLine(" UPDATE HR_Announcement ");
                        sb.AppendLine(" SET DIR_Type = @DIR_Type ");
                        sb.AppendLine(" , DIR_Group = @DIR_Group ");
                        sb.AppendLine(" , DIR_Title = @DIR_Title ");
                        sb.AppendLine(" , DIR_Detail = @DIR_Detail ");
                        sb.AppendLine(" , DIR_StartDate = @DIR_StartDate ");
                        sb.AppendLine(" , DIR_EndDate = @DIR_EndDate ");
                        sb.AppendLine(" , DIR_SlideOrder = @DIR_SlideOrder ");
                        sb.AppendLine(" , DIR_Status = @DIR_Status ");
                        sb.AppendLine(" , DIR_Highlight = @DIR_Highlight ");
                        sb.AppendLine(" WHERE 1=1 ");
                        sb.AppendLine(" and DIR_ID = @DIR_ID ");

                        sql = new SqlCommand(sb.ToString(), db);
                        sql.Parameters.AddWithValue("DIR_Type", Type);
                        sql.Parameters.AddWithValue("DIR_Group", Group);
                        sql.Parameters.AddWithValue("DIR_Title", Title);
                        sql.Parameters.AddWithValue("DIR_Detail", Detail);
                        sql.Parameters.AddWithValue("DIR_StartDate", StartDate);

                        if (EndDate.Equals(""))
                        {
                            sql.Parameters.AddWithValue("DIR_EndDate", DBNull.Value);
                        }
                        else
                        {
                            sql.Parameters.AddWithValue("DIR_EndDate", EndDate);
                        }

                        sql.Parameters.AddWithValue("DIR_SlideOrder", OrderBy);
                        sql.Parameters.AddWithValue("DIR_Status", Status);
                        sql.Parameters.AddWithValue("DIR_Highlight", check);
                        sql.Parameters.AddWithValue("DIR_ID", DIR_ID);

                        sql.ExecuteNonQuery();
                    }

                    if (Type.Equals("3") || Type.Equals("4") || Type.Equals("1"))
                    {
                        if (postedFile.HasFile)
                        {
                            string PathDocument = Server.MapPath("~/") + "images/Announcement/" + DIR_ID + "/document/";
                            if (!Directory.Exists(PathDocument))
                            {
                                Directory.CreateDirectory(PathDocument);
                            }

                            string filename = Path.GetFileName(postedFile.FileName);
                            postedFile.SaveAs(PathDocument + filename);

                            sb = new StringBuilder();
                            sb.AppendLine(" UPDATE HR_Announcement ");
                            sb.AppendLine(" SET DIR_UploadDoc = '" + filename + "' ");
                            sb.AppendLine(" WHERE 1=1 ");
                            sb.AppendLine(" and DIR_ID = '" + DIR_ID + "' ");

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

                    if (Type.Equals("1") || Type.Equals("2"))
                    {
                        if (postedImageFile.HasFile)
                        {
                            string PathImage = Server.MapPath("~/") + "images/Announcement/" + DIR_ID + "/images/";
                            if (!Directory.Exists(PathImage))
                            {
                                Directory.CreateDirectory(PathImage);
                            }

                            string filename = Path.GetFileName(postedImageFile.FileName);
                            postedImageFile.SaveAs(PathImage + filename);

                            sb = new StringBuilder();
                            sb.AppendLine(" UPDATE HR_Announcement ");
                            sb.AppendLine(" SET DIR_UploadImage = '" + filename + "' ");
                            sb.AppendLine(" WHERE 1=1 ");
                            sb.AppendLine(" and DIR_ID = '" + DIR_ID + "' ");

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

                    ScriptManager.RegisterStartupScript(this, this.GetType(), "submit", "sweetsuccess();", true);
                }
            }

            string page       = HdnPage.Value;
            int    Maxperpage = 20;

            int paging   = page == "" ? 1 : Convert.ToInt32(page);
            int startrow = (Maxperpage * (paging - 1)) + 1;
            int endrow   = (Maxperpage * paging);

            string Status_ = DdlStatus_.SelectedValue;
            string Type_   = DdlType_.SelectedValue;
            string Group_  = DdlGroup_.SelectedValue;

            sb = new StringBuilder();
            sb.AppendLine(" SELECT DIR_Title, ");
            sb.AppendLine(" DIR_ID, ");
            sb.AppendLine(" DIR_StartDate, ");
            sb.AppendLine(" DIR_EndDate, ");
            sb.AppendLine(" DIR_UploadDoc, ");
            sb.AppendLine(" DIR_UploadImage, ");
            sb.AppendLine(" case when DIR_Status = 1 then 'Active' else 'In-Active' end as [Status], ");
            sb.AppendLine(" AN_TypeName, ");
            sb.AppendLine(" case when an.DIR_Group = 0 or an.DIR_Group is null then 'ALL' else GP_DisplayName end as GP_DisplayName, ");
            sb.AppendLine(" DIR_Highlight, ");
            sb.AppendLine(" DIR_SlideOrder, ");
            sb.AppendLine(" ROW_NUMBER() OVER(ORDER BY isnull(DIR_StartDate, 0) DESC) AS row ");
            sb.AppendLine(" FROM HR_Announcement as an ");
            sb.AppendLine(" LEFT JOIN HR_AnnouncementType as at on an.DIR_Type = AN_AnnouncementTypeID ");
            sb.AppendLine(" LEFT JOIN HR_Group as gr on an.DIR_Group = gr.GP_ID ");
            sb.AppendLine(" WHERE 1=1 ");
            sb.AppendLine(" and an.DIR_Deleted is null ");

            if (!Status_.Equals(""))
            {
                sb.AppendLine(" and DIR_Status = '" + Status_ + "' ");
            }

            if (!Type_.Equals(""))
            {
                sb.AppendLine(" and an.DIR_Type = '" + Type_ + "' ");
            }

            if (!Group_.Equals("0"))
            {
                sb.AppendLine(" and an.DIR_Group = '" + Group_ + "' ");
            }

            sb.AppendLine(" ORDER BY DIR_ID DESC ");

            //Response.Write(sb.ToString());

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

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

            double p = Math.Ceiling(Convert.ToDouble(table.Rows.Count) / Convert.ToDouble(Maxperpage));

            string showpage = "";

            #region
            if (p > 1)
            {
                if (p < 6)
                {
                    for (int i = 0; i < p; i++)
                    {
                        if (paging == (i + 1))
                        {
                            showpage += "<span page=\"" + (i + 1) + "\" class=\"page_active\" >" + (i + 1) + "</span>";
                        }
                        else
                        {
                            showpage += "<span page=\"" + (i + 1) + "\" class=\"page_inactive\" >" + (i + 1) + "</span>";
                        }
                    }
                }
                else
                {
                    double maxpage = (paging + 4) >= p ? p : (paging + 4);
                    if (paging == 1 || paging == 2 || paging == 3)
                    {
                        switch (paging)
                        {
                        case 2:
                            maxpage = maxpage - 1;
                            break;

                        case 3:
                            maxpage = maxpage - 2;
                            break;
                        }

                        for (int i = 0; i < maxpage; i++)
                        {
                            if (paging == (i + 1))
                            {
                                showpage += "<span page=\"" + (i + 1) + "\" class=\"page_active\" >" + (i + 1) + "</span>";
                            }
                            else
                            {
                                showpage += "<span page=\"" + (i + 1) + "\" class=\"page_inactive\" >" + (i + 1) + "</span>";
                            }
                        }

                        if (p > (paging + 4))
                        {
                            showpage += "<span page=\"" + p + "\" class=\"page_inactive\">&raquo;</span>";
                        }
                    }
                    else if (paging == (p - 2) || paging == (p - 1) || paging == p)
                    {
                        int _maxpage = paging;
                        if (paging == (p - 2))
                        {
                            maxpage = (paging - 2) >= 1 ? (paging - 2) : 1; _maxpage = paging + 2;
                        }
                        else if (paging == (p - 1))
                        {
                            maxpage = (paging - 3) >= 1 ? (paging - 3) : 1; _maxpage = paging + 1;
                        }
                        else
                        {
                            maxpage = (paging - 4) >= 1 ? (paging - 4) : 1;
                        }

                        //maxpage = (paging - 4) >= 1 ? (paging - 4) : 1;

                        if ((paging - 4) > 1)
                        {
                            showpage += "<span page=\"1\" class=\"page_inactive\">&laquo;</span>";
                        }

                        for (int i = Convert.ToInt32(maxpage - 1); i < _maxpage; i++)
                        {
                            if (paging == (i + 1))
                            {
                                showpage += "<span page=\"" + (i + 1) + "\" class=\"page_active\" >" + (i + 1) + "</span>";
                            }
                            else
                            {
                                showpage += "<span page=\"" + (i + 1) + "\" class=\"page_inactive\" >" + (i + 1) + "</span>";
                            }
                        }
                    }
                    else
                    {
                        showpage += "<span page=\"1\" class=\"page_inactive\">&laquo;</span>";

                        showpage += "<span page=\"" + (paging - 2) + "\" class=\"page_inactive\" >" + (paging - 2) + "</span>";
                        showpage += "<span page=\"" + (paging - 1) + "\" class=\"page_inactive\" >" + (paging - 1) + "</span>";
                        showpage += "<span page=\"" + paging + "\" class=\"page_active\" >" + paging + "</span>";
                        showpage += "<span page=\"" + (paging + 1) + "\" class=\"page_inactive\" >" + (paging + 1) + "</span>";
                        showpage += "<span page=\"" + (paging + 2) + "\" class=\"page_inactive\" >" + (paging + 2) + "</span>";

                        showpage += "<span page=\"" + p + "\" class=\"page_inactive\">&raquo;</span>";
                    }
                }

                LitPage.Text       = showpage;
                LitPageButton.Text = showpage;
            }
            else
            {
                LitPage.Text       = "";
                LitPageButton.Text = "";
            }
            #endregion

            DataView Dvtable = table.DefaultView;

            if (table.Rows.Count > 0)
            {
                Dvtable.RowFilter = "row >= " + startrow + " and row <= " + endrow;
            }

            table = Dvtable.ToTable();

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

            RptAnnouncement.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message + "<br/>");
            Response.Write(ex.StackTrace + "<br/>");
        }
        finally
        {
            db.Close();
        }
    }