roycms_tp.aspx.cs

来自「ROYcms 是国内CMS市场的新秀、也是国内少有的采用微软的ASP.NET 2」· CS 代码 · 共 702 行 · 第 1/3 页

CS
702
字号
            string SQL = "INSERT INTO [ROYcms_TP_date] ([img_path], [names],[link_url],[characterization],[y]) VALUES ('" + img_path.Trim() + "','" + names.Text.Trim() + "','" + link_url.Text.Trim() + "','" + characterization.Text.Trim() + "','1')";
            if (Session["group"] != null)
            {
                SQL = "INSERT INTO [ROYcms_TP_date] ([img_path], [names],[link_url],[characterization],[z_id],[y]) VALUES ('" + img_path.Trim() + "','" + names.Text.Trim() + "','" + link_url.Text.Trim() + "','" + characterization.Text.Trim() + "','" + Session["group"] + "','1')";
            }
            SqlHelper.ExecuteNonQuery(SqlHelper.Conn, CommandType.Text, SQL, null);
        }

        public void small_adddate()
        {
            string SQL = "INSERT INTO [ROYcms_TP_date] ([img_path], [names],[link_url],[characterization],[y]) VALUES ('null','" + small_names.Text.Trim() + "','null','null','1')";
            if (Session["group"] != null)
            {
                SQL = "INSERT INTO [ROYcms_TP_date] ([img_path], [names],[link_url],[characterization],[z_id],[y]) VALUES ('null','" + small_names.Text.Trim() + "','null','null','" + Session["group"] + "','1')";
            }
            SqlHelper.ExecuteNonQuery(SqlHelper.Conn, CommandType.Text, SQL, null);
        }


        //添加项目事件
        protected void Button1_Click(object sender, EventArgs e)
        {
            XmlControl Config = new XmlControl(Server.MapPath(ConfigPath));

            string times = DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss_");

            HttpFileCollection files = HttpContext.Current.Request.Files;
            try
            {
                for (int iFile = 0; iFile < files.Count; iFile++)
                {
                    HttpPostedFile postedFile = files[iFile];
                    string fileName, fileExtension;
                    fileName = System.IO.Path.GetFileName(postedFile.FileName);
                    if (fileName != null)
                    {
                        string dataName = times + iFile;
                        fileExtension = System.IO.Path.GetExtension(fileName);
                        postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath(Config.GetText("//TP_upfile")) + dataName + fileExtension);
                        String IMG_URL = dataName + fileExtension;
                        //生成缩略图
                        System.Drawing.Image.GetThumbnailImageAbort callb = null;
                        System.Drawing.Image image = System.Drawing.Image.FromFile(System.Web.HttpContext.Current.Request.MapPath(Config.GetText("//TP_upfile")) + dataName + fileExtension);
                        string[] w_h = Config.GetText("//TP_upfile_w_h").Split(',');
                        System.Drawing.Image newimage = image.GetThumbnailImage(Convert.ToInt32(w_h[0]), Convert.ToInt32(w_h[1]), callb, new System.IntPtr());
                        newimage.Save(System.Web.HttpContext.Current.Request.MapPath(Config.GetText("//TP_upfile") + "small_") + dataName + fileExtension);
                        adddate(IMG_URL);
                        BIND();
                        MessageBox.ResponseScript(this, "TabbedPanels1.showPanel(1);alert('项目添加成功!');");
                    }
                    else
                    {
                        MessageBox.ResponseScript(this, "alert('你选的文件类型不符!');");
                    }

                }
            }
            catch { MessageBox.ResponseScript(this, "alert('出现错误!');"); }
        }

        //管理项目绑定数据

        public void del()
        {
            //string SQL = "select img_path from [ROYcms_TP_date] where id= '" + Request["id"] + "'";
            //string path = Convert.ToString(SqlHelper.ExecuteScalar(SqlHelper.Conn, CommandType.Text, SQL, null));
            // File.Delete(Server.MapPath(ConfigurationManager.AppSettings["TP_upfile"]+path));
            string SQL1 = "delete [ROYcms_TP_date] where id= '" + Request["id"] + "'";
            SqlHelper.ExecuteNonQuery(SqlHelper.Conn, CommandType.Text, SQL1, null);


        }
        public void update()
        {
            string SQL = "update [ROYcms_TP_date] set y='1' where id= '" + Request["id"] + "'";
            SqlHelper.ExecuteNonQuery(SqlHelper.Conn, CommandType.Text, SQL, null);
        }
        public void BIND()
        {
            //管理列表
            string SQL = "select * from [ROYcms_TP_date] order by id DESC ";
            if (Session["group"] != null) { SQL = "select * from [ROYcms_TP_date] where z_id='" + Session["group"] + "' and y='1' order by id DESC "; }
            string SQL2 = "select * from [ROYcms_TP_group] order by id DESC ";
            Repeater_xmlist.DataSource = SqlHelper.ExecuteReader(SqlHelper.Conn, CommandType.Text, SQL, null);
            Repeater_xmlist.DataBind();
            //示意图数据绑定
            Repeater_tu.DataSource = SqlHelper.ExecuteReader(SqlHelper.Conn, CommandType.Text, SQL, null);
            Repeater_tu.DataBind();

            //Repeater_tu_s.DataSource = SqlHelper.ExecuteReader(SqlHelper.Conn, CommandType.Text, SQL, null);
            //Repeater_tu_s.DataBind();

            Repeater_group.DataSource = SqlHelper.ExecuteReader(SqlHelper.Conn, CommandType.Text, SQL2, null);
            Repeater_group.DataBind();

            DropDownList_group.DataSource = SqlHelper.ExecuteReader(SqlHelper.Conn, CommandType.Text, SQL2, null);
            DropDownList_group.DataTextField = "group_name";
            DropDownList_group.DataValueField = "id";
            try
            {
                DropDownList_group.DataBind();
            }
            catch { }
            DropDownList_group.Items.Insert(0, new ListItem("◆请选择要管理初始化的投票组◆", ""));//插入空项,此举必须放到数据绑定之后
            if (Session["group"] != null)
            {
                try
                {
                    DropDownList_group.SelectedValue = Session["group"].ToString();
                }
                catch { }
            }
            else { DropDownList_group.SelectedValue = ""; }

            XmlControl Config = new XmlControl(Server.MapPath(ConfigPath));

            config_time.Text = Config.GetText("//TP_time");
            TP_upfile.Text = Config.GetText("//TP_upfile");
            TP_upfile_w_h.Text = Config.GetText("//TP_upfile_w_h");
            admin_password.Text = Config.GetText("//TP_password");
            TP_Redirect.Text = Config.GetText("//TP_Redirect");
            if (Config.GetText("TP_IP_Y") == "true")
            {
                CheckBox_IP_Y.Checked = true;
            }

            //前台示意图绑定
            string SQL3 = "select * from [ROYcms_TP_date] where z_id='" + Request["group"] + "' order by id DESC ";
            if (Request["group"] != null)
            {
                Repeater_user_tu.DataSource = SqlHelper.ExecuteReader(SqlHelper.Conn, CommandType.Text, SQL3, null);
                Repeater_user_tu.DataBind();
            }

            //根据ID返回组数据
            string SQL4 = "select * from [ROYcms_TP_group] where id= '" + Request["group"] + "'";
            Repeater_user_z.DataSource = SqlHelper.ExecuteReader(SqlHelper.Conn, CommandType.Text, SQL4, null);
            Repeater_user_z.DataBind();

            if (Session["group_type"] != null && Convert.ToInt32(Session["group_type"]) == 1)
            {
                Panel_small.Visible = true;
                Panel_big.Visible = false;
            }
        }
        //配置文件设置事件
        protected void Button2_Click(object sender, EventArgs e)
        {
            XmlControl Config = new XmlControl(Server.MapPath(ConfigPath));
            Config.Replace("//TP_time", config_time.Text.Trim());
            Config.Replace("//TP_upfile", TP_upfile.Text.Trim());
            Config.Replace("//TP_upfile_w_h", TP_upfile_w_h.Text.Trim());
            Config.Replace("//TP_password", admin_password.Text.Trim());
            Config.Replace("//TP_Redirect", TP_Redirect.Text.Trim());

            if (CheckBox_IP_Y.Checked)
            {
                Config.Replace("//TP_IP_Y", "true");
            }
            else { Config.Replace("//TP_IP_Y", "false"); }

            Config.Save();

            MessageBox.ResponseScript(this, "TabbedPanels1.showPanel(3);alert('配置文件设置成功!');");
        }
        //small项目添加;
        protected void Button4_Click(object sender, EventArgs e)
        {
            small_adddate();
            BIND();
            MessageBox.ResponseScript(this, "TabbedPanels1.showPanel(1);alert('项目添加成功!');");
        }

        //项目组添加事件
        protected void Button3_Click(object sender, EventArgs e)
        {
            string CK = "";
            if (CheckBoxA.Checked) { CK = "0"; }
            else { CK = "1"; }
            string SQL = "INSERT INTO [ROYcms_TP_group] ([group_name], [group_content], [group_type], [group_x]) VALUES ('" + group_name.Text.Trim() + "','" + group_content.Text.Trim() + "','" + CK + "','" + RadioButtonListX.SelectedValue + "')";
            SqlHelper.ExecuteNonQuery(SqlHelper.Conn, CommandType.Text, SQL, null);
            BIND();
            MessageBox.ResponseScript(this, "TabbedPanels1.showPanel(4);alert('项目组添加成功!');");
        }
        protected void DropDownList_group_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DropDownList_group.SelectedValue != "")
            {
                Page.Session["group"] = DropDownList_group.SelectedValue.Trim();

                string SQL = "select * from [ROYcms_TP_group] where id='" + DropDownList_group.SelectedValue.Trim() + "' ";
                DataSet dt = ROYcms.DB.SqlHelper.ExecuteDataSet(ROYcms.DB.SqlHelper.Conn, SQL);
                if (dt.Tables[0].Rows.Count > 0)
                {
                    Page.Session["group_type"] = dt.Tables[0].Rows[0]["group_type"].ToString().Trim();
                    Page.Session["group_name"] = dt.Tables[0].Rows[0]["group_name"].ToString().Trim();
                }
                BIND();
            }
            else
            {
                Page.Session["group"] = null;
                Page.Session["group_name"] = null;
                Page.Session["group_type"] = null;
            }
            Response.Redirect("ROYcms_TP.aspx");

        }
        protected void LinkButton_password_Click(object sender, EventArgs e)
        {
            XmlControl Config = new XmlControl(Server.MapPath(ConfigPath));

            if (password.Text.Trim() == Config.GetText("//TP_password"))
            {
                Page.Session["TP_admin"] = password.Text.Trim();
                new ROYcms.Common.cooks().SaveCookie("TP_admin", password.Text.Trim(), 100000);
                Response.Redirect("ROYcms_TP.aspx");
            }
            else
            {
                Page.Session["TP_admin"] = null;
                MessageBox.Show(this, "密码错误!");
            }
        }

        ///
        ///
        //下面的方法属于 投票方法集合
        ///
        ///
        ///定义一个用于从数据库中检索投票者的IP
        private bool checkVoterIP()
        {
            //获取投票者IP

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?