Beispiel #1
0
        private void SetDdlsColors(System.Web.UI.HtmlControls.HtmlSelect ddl)
        {
            using (DatabaseContext _DatabaseContext = new DatabaseContext())
            {
                List <ActionProposed> acts = _DatabaseContext.ActionProposeds.ToList();
                foreach (ListItem item in ddl.Items)
                {
                    if (item.Value == "0")
                    {
                        item.Attributes.Add("style", "background-color:#FFF");
                    }
                    else
                    {
                        item.Attributes.Add("style", "background-color:#" + acts.Where(i => i.ActionProposedID.ToString() == item.Value).First().Color.Code);
                    }
                }

                if (ddlActionProposed.SelectedIndex == 0)
                {
                    ddlActionProposed.Attributes.Add("style", "background-color:#FFF");
                }
                else
                {
                    ddlActionProposed.Attributes.Add("style", "background-color:#" + acts.Where(i => i.ActionProposedID.ToString() == ddlActionProposed.Items[ddlActionProposed.SelectedIndex].Value).First().Color.Code);
                }
            }
        }
Beispiel #2
0
        protected void InitialStatus()
        {
            if (Session["UserName"] == null || Session["UserPassWord"] == null)
            {
                Response.Redirect("../admin.aspx");
            }
            if (Session["Priority"] == "normal")
            {
            }
            if (Session["Priority"] == "low")
            {
                for (int i = 0; i < GridView1.Rows.Count; i++)
                {
                    System.Web.UI.HtmlControls.HtmlSelect selectOption = (System.Web.UI.HtmlControls.HtmlSelect)GridView1.Rows[i].FindControl("selectError");
                    CheckBox   selectcheck  = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
                    Button     PrintButton  = (Button)GridView1.Rows[i].FindControl("PrintButton");
                    LinkButton DeleteChoose = (LinkButton)GridView1.Rows[i].FindControl("LinkButton1");

                    selectOption.Disabled = true;
                    selectcheck.Enabled   = false;
                    PrintButton.Enabled   = false;
                    DeleteChoose.Enabled  = false;
                }
            }
        }
Beispiel #3
0
 public void Fill_Select(DataSet ds, System.Web.UI.HtmlControls.HtmlSelect select, string Llave, string Descripcion)
 {
     select.DataSource     = ds;
     select.DataTextField  = Descripcion;
     select.DataValueField = Llave;
     select.DataBind();
     ds.Tables.Remove("DATOS");
 }
 /// <summary>
 /// 将list集合作为数据源绑定到HtmlSelect,_Momo默认下拉选项(可为空)
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="select"></param>
 /// <param name="list"></param>
 /// <param name="_Name"></param>
 /// <param name="_ID"></param>
 /// <param name="_Memo"></param>
 public static void SetListHtmlSelect <T>(this System.Web.UI.HtmlControls.HtmlSelect select, IList <T> list, string _Name, string _ID, string _Memo)
 {
     select.DataSource     = list;
     select.DataTextField  = _Name;
     select.DataValueField = _ID;
     select.DataBind();
     if (!string.IsNullOrEmpty(_Memo.Trim()))
     {
         select.Items.Insert(0, new ListItem(_Memo, ""));
     }
 }
 /// <summary>
 /// 将指定枚举类的描述与值绑定到HtmlSelect下拉选择框
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="o"></param>
 /// <param name="defaulText"></param>
 public static void SetEnumHtmlSelect <T>(this System.Web.UI.HtmlControls.HtmlSelect o, string defaulText)
 {
     GetEnumList(typeof(T), defaulText).ForEach(m =>
     {
         o.Items.Add(new ListItem
         {
             Value    = m.Value,
             Text     = m.Text,
             Selected = m.Selected
         });
     });
 }
        /// <summary>
        /// 绑定“直接上级联系”下拉框
        /// </summary>
        internal static void BindParentContactToSelectEle(System.Web.UI.HtmlControls.HtmlSelect select, string tid, int contactId)
        {
            select.Items.Clear();
            select.Items.Add(new System.Web.UI.WebControls.ListItem("请选择", "-1"));
            DataTable dt = BLL.ProjectTask_Cust_Contact.Instance.GetContactInfoExcept(tid, contactId);

            if (dt == null || dt.Rows.Count == 0)
            {
                return;
            }

            foreach (DataRow dr in dt.Rows)
            {
                select.Items.Add(new System.Web.UI.WebControls.ListItem(dr["CName"].ToString(), dr["ID"].ToString()));
            }
        }
Beispiel #7
0
 protected string GetMultiselectListItems(System.Web.UI.HtmlControls.HtmlSelect control, string controlName) {
   const string row = "<tr><td><input id='{CONTROL.ID}' name='{CONTROL.NAME}' type='checkbox' value='{ITEM.VALUE}' /></td>" +
                      "<td id='{ITEM.NAME.ID}' style='white-space:normal;width:98%'>{ITEM.NAME}</td></tr>";
   string html = String.Empty;
   foreach (ListItem item in control.Items) {
     if (EmpiriaString.IsInteger(item.Value) && (int.Parse(item.Value) > 0)) {
       string temp = row.Replace("{ITEM.VALUE}", item.Value);
       temp = temp.Replace("{ITEM.NAME}", item.Text);
       temp = temp.Replace("{ITEM.NAME.ID}", controlName + "_text_" + item.Value);
       temp = temp.Replace("{CONTROL.ID}", controlName + "_" + item.Value);
       temp = temp.Replace("{CONTROL.NAME}", controlName);
       html += temp;
     }
   }
   return html;
 }
Beispiel #8
0
        /// <summary>
        /// Процедура заполнения любого списочного контрола.
        /// </summary>
        /// <param name="list">Название списочного контрола</param>
        /// <param name="cmd">SQL-команда заполнения списка</param>
        /// <param name="parameters">Набор SQL-параметров</param>
        public static void BindList(Control list, SqlCommand cmd, params SqlParameter[] parameters)
        {
            if (cmd.Connection == null)
            {
                cmd.Connection = CreateConnection();
            }

            cmd.Parameters.AddRange(parameters);

            using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
            {
                DataTable table = new DataTable();
                sda.Fill(table);

                if (list is ListControl)
                {
                    ListControl listControl = list as ListControl;
                    listControl.DataSource     = table;
                    listControl.DataValueField = "OptionValue";
                    listControl.DataTextField  = "OptionText";
                    listControl.DataBind();
                }
                else if (list is BaseDataList)
                {
                    BaseDataList baseDataList = list as BaseDataList;
                    baseDataList.DataSource = table;
                    baseDataList.DataBind();
                }
                else if (list is Repeater)
                {
                    Repeater repeater = list as Repeater;
                    repeater.DataSource = table;
                    repeater.DataBind();
                }
                else if (list is System.Web.UI.HtmlControls.HtmlSelect)
                {
                    System.Web.UI.HtmlControls.HtmlSelect listControl = list as System.Web.UI.HtmlControls.HtmlSelect;
                    listControl.DataSource     = table;
                    listControl.DataValueField = "OptionValue";
                    listControl.DataTextField  = "OptionText";
                    listControl.DataBind();
                }
            }
        }
Beispiel #9
0
 /// <summary>
 /// 输出时的代码
 /// </summary>
 /// <remarks>设计时输出一个Select,运行时未进行处理</remarks>
 /// <param name="writer">HtmlTextWriter</param>
 protected override void Render(System.Web.UI.HtmlTextWriter writer)
 {
     if (this.DesignMode)
     {
         System.Web.UI.HtmlControls.HtmlSelect ddl = new System.Web.UI.HtmlControls.HtmlSelect();
         ddl.ID = "ddl_Generic_Design";
         for (int i = 0; i < Controls.Count; i++)
         {
             if (Controls[i].ID == "ddl_Generic_Design")
             {
                 Controls.RemoveAt(i);
                 break;
             }
         }
         ddl.Attributes.Add("style", "width:" + this.Width.ToString());
         Controls.Add(ddl);
     }
     base.Render(writer);
 }
Beispiel #10
0
        protected void Page_Init()
        {
            this.EnsureChildControls();
            // Full page things
            if (this.AddressBookDataGrid == null && this.SharpUI != null)
            {
                this.addressbookselect   = (System.Web.UI.HtmlControls.HtmlSelect) this.SharpUI.FindControl("addressbookselect");
                this.AddressBookDataGrid = (System.Web.UI.WebControls.DataGrid) this.SharpUI.FindControl("AddressBookDataGrid");
                this.addressbooklabel    = (System.Web.UI.WebControls.Label) this.SharpUI.FindControl("addressbookLabel");
                this.SharpUI.nextPageImageButton.Click          += new System.Web.UI.ImageClickEventHandler(AddressBookNextPageButton_Click);
                this.SharpUI.prevPageImageButton.Click          += new System.Web.UI.ImageClickEventHandler(AddressBookPrevPageButton_Click);
                this.SharpUI.refreshPageImageButton.Enabled      = false;
                this.AddressBookDataGrid.PagerStyle.NextPageText = this.SharpUI.LocalizedRS.GetString("inboxNextPage");
                this.AddressBookDataGrid.PagerStyle.PrevPageText = this.SharpUI.LocalizedRS.GetString("inboxPrevPage");
            }

            if (Application["sharpwebmail/send/addressbook"] != null)
            {
                System.Collections.SortedList addressbooks = (System.Collections.SortedList)Application["sharpwebmail/send/addressbook"];
                if (addressbooks.Count > 1)
                {
                    addressbookselect.Visible = true;
                    if (this.addressbooklabel != null)
                    {
                        this.addressbooklabel.Visible = true;
                    }
                }
                addressbookselect.DataSource     = addressbooks;
                addressbookselect.DataTextField  = "Key";
                addressbookselect.DataValueField = "Key";
                addressbookselect.DataBind();
                if (!this.IsPostBack)
                {
                    System.String book = Request.QueryString["book"];
                    if (book != null && book.Length > 0)
                    {
                        addressbookselect.Value = book;
                    }
                }
            }
        }
        /// <summary>
        /// 设置html <select>元素的下拉选项
        /// </summary>
        /// <param name="o"></param>
        /// <param name="d">数据源datatable</param>
        /// <param name="key">datatable里对应listitem控件key的列</param>
        /// <param name="val">datatable里对应listitem控件value的列</param>
        /// <param name="defaulText">添加默认下拉选项</param>
        public static void SetDataTableHtmlSelect(this System.Web.UI.HtmlControls.HtmlSelect o, System.Data.DataTable d, string key, string val, string defaulText)
        {
            if (!string.IsNullOrEmpty(defaulText))
            {
                o.Items.Add(new ListItem
                {
                    Value = "",
                    Text  = defaulText
                });
            }

            if (d != null && d.Rows.Count > 0)
            {
                foreach (System.Data.DataRow item in d.Rows)
                {
                    o.Items.Add(new System.Web.UI.WebControls.ListItem()
                    {
                        Text  = item[val].ToString(),
                        Value = item[key].ToString()
                    });
                }
            }
            d.Dispose();
        }
Beispiel #12
0
 /// <summary>
 /// 填充表单
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="control"></param>
 public static void FillForm(WebUI.Control control, Object entity)
 {
     if (entity == null || control == null)
     {
         return;
     }
     PropertyInfo[] propertyList = entity.GetProperties();
     foreach (PropertyInfo pi in propertyList)
     {
         WebUI.Control ctl = control.FindControl(string.Format(IdFormat, pi.Name));
         if (ctl == null)
         {
             continue;
         }
         Type ctlType = ctl.GetType();
         #region 处理服务器控件
         if (ctlType == typeof(WebUI.WebControls.TextBox))//文本框
         {
             if (entity.GetPropertyValue(pi.Name) != null)
             {
                 ((WebUI.WebControls.TextBox)ctl).Text = entity.GetPropertyValue(pi.Name).ToString();
             }
         }
         else if (ctlType == typeof(WebUI.WebControls.Image))//图片
         {
             if (entity.GetPropertyValue(pi.Name) != null)
             {
                 string imageUrl = entity.GetPropertyValue(pi.Name).ToString();
                 if (!string.IsNullOrEmpty(imageUrl))
                 {
                     ((WebUI.WebControls.Image)ctl).ImageUrl = imageUrl;
                 }
             }
         }
         else if (ctlType == typeof(WebUI.WebControls.DropDownList))//选择框
         {
             if (entity.GetPropertyValue(pi.Name) != null)
             {
                 ((WebUI.WebControls.DropDownList)ctl).SelectedValue = entity.GetPropertyValue(pi.Name).ToString();
             }
         }
         else if (ctlType == typeof(WebUI.WebControls.HiddenField))//隐藏域
         {
             if (entity.GetPropertyValue(pi.Name) != null)
             {
                 ((WebUI.WebControls.HiddenField)ctl).Value = entity.GetPropertyValue(pi.Name).ToString();
             }
         }
         else if (ctlType == typeof(WebUI.WebControls.RadioButton))//单选框
         {
             WebUI.WebControls.RadioButton rb = (WebUI.WebControls.RadioButton)ctl;
             if (entity.GetPropertyValue(pi.Name) != null)
             {
                 rb.Checked = entity.GetPropertyValue(pi.Name).ToString() == rb.Text ? true : false;
             }
         }
         else if (ctlType == typeof(WebUI.WebControls.CheckBox))//复选框
         {
             WebUI.WebControls.CheckBox ck = (WebUI.WebControls.CheckBox)ctl;
             if (entity.GetPropertyValue(pi.Name) != null)
             {
                 ck.Checked = entity.GetPropertyValue(pi.Name).ToString() == ck.Text ? true : false;
             }
         }
         else if (ctlType == typeof(WebUI.WebControls.CheckBoxList))//复选框列表
         {
             WebUI.WebControls.CheckBoxList ck = (WebUI.WebControls.CheckBoxList)ctl;
             if (entity.GetPropertyValue(pi.Name) != null)
             {
                 string sel = entity.GetPropertyValue(pi.Name).ToString();
                 foreach (WebUI.WebControls.ListItem li in ck.Items)
                 {
                     if (sel.IndexOf(",") > -1 && (sel.IndexOf(li.Value + ",") > -1 || sel.IndexOf("," + li.Value) > -1))
                     {
                         li.Selected = true;
                     }
                     else if (sel.IndexOf(",") == -1 && sel == li.Value)
                     {
                         li.Selected = true;
                     }
                     else
                     {
                         li.Selected = false;
                     }
                 }
             }
         }
         else if (ctlType == typeof(WebUI.WebControls.RadioButtonList))//单框列表
         {
             WebUI.WebControls.RadioButtonList ck = (WebUI.WebControls.RadioButtonList)ctl;
             if (entity.GetPropertyValue(pi.Name) != null)
             {
                 ck.SelectedValue = entity.GetPropertyValue(pi.Name).ToString();
             }
         }
         else if (ctlType == typeof(WebUI.WebControls.ListBox))//列表框
         {
             WebUI.WebControls.ListBox ck = (WebUI.WebControls.ListBox)ctl;
             if (entity.GetPropertyValue(pi.Name) != null)
             {
                 string sel = entity.GetPropertyValue(pi.Name).ToString();
                 foreach (WebUI.WebControls.ListItem li in ck.Items)
                 {
                     if (sel.IndexOf(",") > -1 && (sel.IndexOf(li.Value + ",") > -1 || sel.IndexOf("," + li.Value) > -1))
                     {
                         li.Selected = true;
                     }
                     else if (sel.IndexOf(",") == -1 && sel == li.Value)
                     {
                         li.Selected = true;
                     }
                     else
                     {
                         li.Selected = false;
                     }
                 }
             }
         }
         #endregion
         #region 处理不同Html控件
         else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputText))//文本域
         {
             WebUI.HtmlControls.HtmlInputText ct = (WebUI.HtmlControls.HtmlInputText)ctl;
             if (entity.GetPropertyValue(pi.Name) != null)
             {
                 ct.Value = entity.GetPropertyValue(pi.Name).ToString();
             }
         }
         else if (ctlType == typeof(WebUI.HtmlControls.HtmlTextArea))//文本域
         {
             WebUI.HtmlControls.HtmlTextArea ct = (WebUI.HtmlControls.HtmlTextArea)ctl;
             if (entity.GetPropertyValue(pi.Name) != null)
             {
                 ct.Value = entity.GetPropertyValue(pi.Name).ToString();
             }
         }
         else if (ctlType == typeof(WebUI.HtmlControls.HtmlSelect))//选择域
         {
             WebUI.HtmlControls.HtmlSelect ct = (WebUI.HtmlControls.HtmlSelect)ctl;
             if (entity.GetPropertyValue(pi.Name) != null)
             {
                 for (int i = 0; i < ct.Items.Count; i++)
                 {
                     if (ct.Items[i].Value == entity.GetPropertyValue(pi.Name).ToString())
                     {
                         ct.SelectedIndex = i;
                     }
                 }
             }
         }
         else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputHidden))////隐藏域
         {
             WebUI.HtmlControls.HtmlInputHidden ct = (WebUI.HtmlControls.HtmlInputHidden)ctl;
             if (entity.GetPropertyValue(pi.Name) != null)
             {
                 ct.Value = entity.GetPropertyValue(pi.Name).ToString();
             }
         }
         else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputRadioButton))//单选域
         {
             WebUI.HtmlControls.HtmlInputRadioButton rb = (WebUI.HtmlControls.HtmlInputRadioButton)ctl;
             if (rb.Checked && entity.GetPropertyValue(pi.Name) != null)
             {
                 rb.Checked = entity.GetPropertyValue(pi.Name).ToString() == rb.Value ? true : false;
             }
         }
         else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputCheckBox))//复选域
         {
             WebUI.HtmlControls.HtmlInputCheckBox ck = (WebUI.HtmlControls.HtmlInputCheckBox)ctl;
             if (entity.GetPropertyValue(pi.Name) != null)
             {
                 if (entity.GetPropertyValue(pi.Name).ToString().IndexOf("," + ck.Value) != -1)
                 {
                     ck.Checked = true;
                 }
             }
         }
         else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputPassword))//密码域
         {
             WebUI.HtmlControls.HtmlInputPassword ck = (WebUI.HtmlControls.HtmlInputPassword)ctl;
             if (entity.GetPropertyValue(pi.Name) != null)
             {
                 ck.Value = entity.GetPropertyValue(pi.Name).ToString();
             }
         }
         #endregion
     }
 }
Beispiel #13
0
        protected void dgvUsuario_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("AddNew"))
            {
                try
                {
                    System.Web.UI.HtmlControls.HtmlSelect ctrlSelect = this.dgvUsuario.FooterRow.FindControl("txtid_CursoFooter") as System.Web.UI.HtmlControls.HtmlSelect;

                    Conexao conn = new Conexao();
                    conn.ConnectionString = ConfigurationManager.ConnectionStrings["ProjetoIC"].ConnectionString;

                    if (conn.AbrirConexao())
                    {
                        string  newSenha = Guid.NewGuid().ToString().Substring(0, 8);
                        TextBox txtEmail = this.dgvUsuario.FooterRow.FindControl("txtds_EmailFooter") as TextBox;

                        var nmPath      = System.Web.HttpContext.Current.Server.MapPath("../email.txt");
                        var nmPathEmail = System.Web.HttpContext.Current.Server.MapPath("../template_email.html");

                        if (System.IO.File.Exists(nmPath))
                        {
                            string dsEmail  = System.IO.File.ReadAllText(nmPathEmail);
                            string arquivo  = System.IO.File.ReadAllText(nmPath);
                            string host     = Conexao.GetValor(arquivo, "host:");
                            string user     = Conexao.GetValor(arquivo, "user:"******"password:"******"nameUser:"******"port:"));
                            bool   ssl      = Conexao.GetValor(arquivo, "ssl:").ToLower().Equals("true");

                            Email email = new Email();
                            email.MailFrom  = new MailAddress(user, nameUser);
                            email.SmtpHost  = host;
                            email.SmtpLogin = user;
                            email.SmtpSenha = password;
                            email.SmtpSsl   = ssl;
                            email.SmtpPorta = port;
                            email.TimeOut   = 100000;

                            if (email.EnviarEmail(txtEmail.Text.Trim(),
                                                  "Registro para Login do 'Sistema de Avaliação de Pós-Graduação'",
                                                  dsEmail.Replace("#@SENHA@#", newSenha)))
                            {
                                string cmd = "insert into Usuario (ds_Email, ds_Senha, id_Curso) values (@dsEmail, @dsSenha, @idCurso)";

                                Dictionary <string, object> sqlParam = new Dictionary <string, object>();

                                sqlParam.Add("@dsEmail", txtEmail.Text.Trim());
                                sqlParam.Add("@dsSenha", newSenha);
                                if (int.Parse(ctrlSelect.Value) > 0)
                                {
                                    sqlParam.Add("@idCurso", int.Parse(ctrlSelect.Value));
                                }
                                else
                                {
                                    sqlParam.Add("@idCurso", DBNull.Value);
                                }
                                conn.ExecutaComando(cmd, sqlParam);
                                this.PopulateGridView();

                                conn.FechaConexao();
                            }
                            else
                            {
                            }
                        }



                        this.lbErro.Visible = false;

                        //this.c.dgvUsuario.EditIndex.SelectedIndex = -1;
                    }
                }
                catch (Exception ex)
                {
                    this.lbErro.Visible = true;
                    this.lbErro.Text    = "Falha na inserção de usuário: " + ex.Message;
                }
            }
        }
Beispiel #14
0
        protected void Page_Init()
        {
            this.EnsureChildControls();
            // Full page things
            if ( this.AddressBookDataGrid==null && this.SharpUI!=null ) {
                this.addressbookselect=(System.Web.UI.HtmlControls.HtmlSelect)this.SharpUI.FindControl("addressbookselect");
                this.AddressBookDataGrid=(System.Web.UI.WebControls.DataGrid)this.SharpUI.FindControl("AddressBookDataGrid");
                this.addressbooklabel=(System.Web.UI.WebControls.Label)this.SharpUI.FindControl("addressbookLabel");
                this.SharpUI.nextPageImageButton.Click += new System.Web.UI.ImageClickEventHandler(AddressBookNextPageButton_Click);
                this.SharpUI.prevPageImageButton.Click += new System.Web.UI.ImageClickEventHandler(AddressBookPrevPageButton_Click);
                this.SharpUI.refreshPageImageButton.Enabled = false;
                this.AddressBookDataGrid.PagerStyle.NextPageText = this.SharpUI.LocalizedRS.GetString("inboxNextPage");
                this.AddressBookDataGrid.PagerStyle.PrevPageText = this.SharpUI.LocalizedRS.GetString("inboxPrevPage");
            }

            if ( Application["sharpwebmail/send/addressbook"]!=null ) {
                System.Collections.SortedList addressbooks = (System.Collections.SortedList)Application["sharpwebmail/send/addressbook"];
                if ( addressbooks.Count>1 ) {
                    addressbookselect.Visible = true;
                    if ( this.addressbooklabel!=null )
                        this.addressbooklabel.Visible = true;
                }
                addressbookselect.DataSource = addressbooks;
                addressbookselect.DataTextField = "Key";
                addressbookselect.DataValueField = "Key";
                addressbookselect.DataBind();
                if ( !this.IsPostBack ) {
                    System.String book = Request.QueryString["book"];
                    if ( book!=null && book.Length>0 ) {
                        addressbookselect.Value = book;
                    }
                }
            }
        }
Beispiel #15
0
		/// <summary>
		/// 输出时的代码
		/// </summary>
		/// <remarks>设计时输出一个Select,运行时未进行处理</remarks>
		/// <param name="writer">HtmlTextWriter</param>
		protected override void Render(System.Web.UI.HtmlTextWriter writer)
		{
			if (this.DesignMode)
			{
				System.Web.UI.HtmlControls.HtmlSelect ddl = new System.Web.UI.HtmlControls.HtmlSelect();
				ddl.ID = "ddl_Generic_Design";
				for (int i = 0; i < Controls.Count; i++)
				{
					if (Controls[i].ID == "ddl_Generic_Design")
					{
						Controls.RemoveAt(i);
						break;
					}
				}
				ddl.Attributes.Add("style", "width:" + this.Width.ToString());
				Controls.Add(ddl);
			}
			base.Render(writer);
		}
Beispiel #16
0
        static public void SetPageControl(object page, string szName, string szValue)
        {
            System.Web.UI.ControlCollection cc = null;
            ArrayList ret = new ArrayList();

            if (page is System.Web.UI.Page)
            {
                cc = (page as System.Web.UI.Page).Controls;
            }
            else if (page is System.Web.UI.UserControl)
            {
                cc = (page as System.Web.UI.UserControl).Controls;
            }
            else
            {
                return;
            }
            GetPageAllControl(ref ret, cc);
            foreach (object ctrInObj in ret)
            {
                System.Web.UI.Control ctr = (System.Web.UI.Control)ctrInObj;
                Type controlType          = ctr.GetType();
                switch (controlType.ToString())
                {
                case "System.Web.UI.WebControls.TextBox":
                    System.Web.UI.WebControls.TextBox controlTextBoxObj = (System.Web.UI.WebControls.TextBox)ctr;
                    if (controlTextBoxObj.ID == szName)
                    {
                        controlTextBoxObj.Text = szValue;
                    }
                    break;

                case "System.Web.UI.WebControls.Label":
                    System.Web.UI.WebControls.Label controlLabelObj = (System.Web.UI.WebControls.Label)ctr;
                    if (controlLabelObj.ID == szName)
                    {
                        controlLabelObj.Text = szValue;
                    }
                    break;

                case "System.Web.UI.HtmlControls.HtmlInputText":
                    System.Web.UI.HtmlControls.HtmlInputText controlInputObj = (System.Web.UI.HtmlControls.HtmlInputText)ctr;
                    if (controlInputObj.Name == szName || controlInputObj.Name.EndsWith("$" + szName))
                    {
                        controlInputObj.Value = szValue;
                    }
                    break;

                case "System.Web.UI.HtmlControls.HtmlSelect":
                    System.Web.UI.HtmlControls.HtmlSelect controlSelectObj = (System.Web.UI.HtmlControls.HtmlSelect)ctr;
                    if (controlSelectObj.Name == szName || controlSelectObj.Name.EndsWith("$" + szName))
                    {
                        controlSelectObj.Value = szValue;
                    }
                    break;

                case "System.Web.UI.HtmlControls.HtmlInputRadioButton":
                    System.Web.UI.HtmlControls.HtmlInputRadioButton controlRadioButtonObj = (System.Web.UI.HtmlControls.HtmlInputRadioButton)ctr;
                    if (controlRadioButtonObj.Name == szName || controlRadioButtonObj.Name.EndsWith("$" + szName))
                    {
                        if (controlRadioButtonObj.Value == szValue)
                        {
                            controlRadioButtonObj.Checked = true;
                        }
                        else
                        {
                            controlRadioButtonObj.Checked = false;
                        }
                    }
                    break;

                default:
                    //TODO:其它控件
                    break;
                }
            }
        }
 public static string SelectedValue(this System.Web.UI.HtmlControls.HtmlSelect select)
 {
     return(select.Items[select.SelectedIndex].ToString());
 }
Beispiel #18
0
 /// <summary>
 /// 清理表单
 /// </summary>
 /// <param name="control"></param>
 public static void ClearForm(WebUI.Control control)
 {
     if (control == null)
     {
         return;
     }
     foreach (WebUI.Control ctl in control.Controls)
     {
         Type type = ctl.GetType();
         #region 处理服务器控件
         if (type == typeof(WebUI.WebControls.TextBox))//文本框
         {
             WebUI.WebControls.TextBox box = ((WebUI.WebControls.TextBox)ctl);
             box.Text = "";
             if (box.Attributes["isNumber"] != null)
             {
                 box.Text = "0";
             }
         }
         else if (type == typeof(WebUI.WebControls.DropDownList))//选择框
         {
             ((WebUI.WebControls.DropDownList)ctl).SelectedIndex = -1;
         }
         else if (type == typeof(WebUI.WebControls.HiddenField))//隐藏域
         {
             ((WebUI.WebControls.HiddenField)ctl).Value = "";
         }
         else if (type == typeof(WebUI.WebControls.RadioButton))//单选框
         {
             WebUI.WebControls.RadioButton rb = (WebUI.WebControls.RadioButton)ctl;
             rb.Checked = false;
         }
         else if (type == typeof(WebUI.WebControls.CheckBox))//复选框
         {
             WebUI.WebControls.CheckBox ck = (WebUI.WebControls.CheckBox)ctl;
             ck.Checked = false;
         }
         else if (type == typeof(WebUI.WebControls.CheckBoxList))//复选框列表
         {
             WebUI.WebControls.CheckBoxList ck = (WebUI.WebControls.CheckBoxList)ctl;
             foreach (WebUI.WebControls.ListItem li in ck.Items)
             {
                 li.Selected = false;
             }
         }
         else if (type == typeof(WebUI.WebControls.RadioButtonList))//单框列表
         {
             WebUI.WebControls.RadioButtonList ck = (WebUI.WebControls.RadioButtonList)ctl;
             foreach (WebUI.WebControls.ListItem li in ck.Items)
             {
                 li.Selected = false;
             }
         }
         else if (type == typeof(WebUI.WebControls.ListBox))//列表框
         {
             WebUI.WebControls.ListBox ck = (WebUI.WebControls.ListBox)ctl;
             foreach (WebUI.WebControls.ListItem li in ck.Items)
             {
                 li.Selected = false;
             }
         }
         #endregion
         #region 处理不同Html控件
         else if (type == typeof(WebUI.HtmlControls.HtmlInputText))//文本域
         {
             WebUI.HtmlControls.HtmlInputText ct = (WebUI.HtmlControls.HtmlInputText)ctl;
             ct.Value = "";
             if (ct.Attributes["isNumber"] != null)
             {
                 ct.Value = "0";
             }
         }
         else if (type == typeof(WebUI.HtmlControls.HtmlTextArea))//文本域
         {
             WebUI.HtmlControls.HtmlTextArea ct = (WebUI.HtmlControls.HtmlTextArea)ctl;
             ct.Value = "";
         }
         else if (type == typeof(WebUI.HtmlControls.HtmlSelect))//选择域
         {
             WebUI.HtmlControls.HtmlSelect ct = (WebUI.HtmlControls.HtmlSelect)ctl;
             ct.SelectedIndex = -1;
         }
         else if (type == typeof(WebUI.HtmlControls.HtmlInputHidden))////隐藏域
         {
             WebUI.HtmlControls.HtmlInputHidden ct = (WebUI.HtmlControls.HtmlInputHidden)ctl;
             ct.Value = "";
             if (ct.Attributes["isNumber"] != null)
             {
                 ct.Value = "0";
             }
         }
         else if (type == typeof(WebUI.HtmlControls.HtmlInputRadioButton))//单选域
         {
             WebUI.HtmlControls.HtmlInputRadioButton rb = (WebUI.HtmlControls.HtmlInputRadioButton)ctl;
             rb.Checked = false;
         }
         else if (type == typeof(WebUI.HtmlControls.HtmlInputCheckBox))//复选域
         {
             WebUI.HtmlControls.HtmlInputCheckBox ck = (WebUI.HtmlControls.HtmlInputCheckBox)ctl;
             ck.Checked = false;
         }
         else if (type == typeof(WebUI.HtmlControls.HtmlInputPassword))//密码域
         {
             WebUI.HtmlControls.HtmlInputPassword ck = (WebUI.HtmlControls.HtmlInputPassword)ctl;
             ck.Value = "";
         }
         #endregion
     }
 }
Beispiel #19
0
        /// <summary>
        /// 填充model
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="control"></param>
        public static void FillModel(Object entity, WebUI.Control control)
        {
            if (entity == null || control == null)
            {
                return;
            }
            NameValueCollection formData = HttpContext.Current.Request.Form;

            PropertyInfo[] propertyList = entity.GetProperties();
            foreach (PropertyInfo pi in propertyList)
            {
                string        ctlId = string.Format(IdFormat, pi.Name);
                WebUI.Control ctl   = control.FindControl(ctlId);
                if (ctl == null)
                {
                    #region 处理HMTL标签
                    if (formData[ctlId] != null)
                    {
                        entity.SetPropertyValue(pi.Name, formData[ctlId]);
                    }
                    #endregion
                    continue;
                }
                Type ctlType = ctl.GetType();

                #region 处理服务器控件
                if (ctlType == typeof(WebUI.WebControls.TextBox))//文本框
                {
                    entity.SetPropertyValue(pi.Name, ((WebUI.WebControls.TextBox)ctl).Text);
                }
                else if (ctlType == typeof(WebUI.WebControls.Image))//图片
                {
                    entity.SetPropertyValue(pi.Name, ((WebUI.WebControls.Image)ctl).ImageUrl);
                }
                else if (ctlType == typeof(WebUI.WebControls.DropDownList))//选择框
                {
                    entity.SetPropertyValue(pi.Name, ((WebUI.WebControls.DropDownList)ctl).SelectedValue);
                }
                else if (ctlType == typeof(WebUI.WebControls.HiddenField))//隐藏域
                {
                    entity.SetPropertyValue(pi.Name, ((WebUI.WebControls.HiddenField)ctl).Value);
                }
                else if (ctlType == typeof(WebUI.WebControls.RadioButton))//单选框
                {
                    WebUI.WebControls.RadioButton rb = (WebUI.WebControls.RadioButton)ctl;

                    if (rb.Checked)
                    {
                        entity.SetPropertyValue(pi.Name, rb.Text);
                    }
                    else
                    {
                        entity.SetPropertyValue(pi.Name, "");
                    }
                }
                else if (ctlType == typeof(WebUI.WebControls.CheckBox))//复选框
                {
                    WebUI.WebControls.CheckBox ck = (WebUI.WebControls.CheckBox)ctl;
                    if (ck.Checked)
                    {
                        entity.SetPropertyValue(pi.Name, ck.Text);
                    }
                    else
                    {
                        entity.SetPropertyValue(pi.Name, "");
                    }
                }
                else if (ctlType == typeof(WebUI.WebControls.CheckBoxList))//复选框列表
                {
                    WebUI.WebControls.CheckBoxList ck = (WebUI.WebControls.CheckBoxList)ctl;
                    string rs = "";
                    foreach (WebUI.WebControls.ListItem li in ck.Items)
                    {
                        if (li.Selected)
                        {
                            rs += "," + li.Value;
                        }
                    }
                    if (rs.Length > 1)
                    {
                        rs = rs.Substring(1);
                    }
                    entity.SetPropertyValue(pi.Name, rs);
                }
                else if (ctlType == typeof(WebUI.WebControls.RadioButtonList))//单框列表
                {
                    WebUI.WebControls.RadioButtonList ck = (WebUI.WebControls.RadioButtonList)ctl;
                    entity.SetPropertyValue(pi.Name, ck.SelectedValue);
                }
                else if (ctlType == typeof(WebUI.WebControls.ListBox))//列表框
                {
                    WebUI.WebControls.ListBox ck = (WebUI.WebControls.ListBox)ctl;
                    string rs = "";
                    foreach (WebUI.WebControls.ListItem li in ck.Items)
                    {
                        if (li.Selected)
                        {
                            rs += "," + li.Value;
                        }
                    }
                    if (rs.Length > 1)
                    {
                        rs = rs.Substring(1);
                    }
                    entity.SetPropertyValue(pi.Name, rs);
                }
                #endregion
                #region 处理不同Html控件
                else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputText))//文本域
                {
                    WebUI.HtmlControls.HtmlInputText ct = (WebUI.HtmlControls.HtmlInputText)ctl;
                    entity.SetPropertyValue(pi.Name, ct.Value);
                }
                else if (ctlType == typeof(WebUI.HtmlControls.HtmlTextArea))//文本域
                {
                    WebUI.HtmlControls.HtmlTextArea ct = (WebUI.HtmlControls.HtmlTextArea)ctl;
                    entity.SetPropertyValue(pi.Name, ct.Value);
                }
                else if (ctlType == typeof(WebUI.HtmlControls.HtmlSelect))//选择域
                {
                    WebUI.HtmlControls.HtmlSelect ct = (WebUI.HtmlControls.HtmlSelect)ctl;
                    entity.SetPropertyValue(pi.Name, ct.Items[ct.SelectedIndex].Value);
                }
                else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputHidden))////隐藏域
                {
                    WebUI.HtmlControls.HtmlInputHidden ct = (WebUI.HtmlControls.HtmlInputHidden)ctl;
                    entity.SetPropertyValue(pi.Name, ct.Value);
                }
                else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputRadioButton))//单选域
                {
                    WebUI.HtmlControls.HtmlInputRadioButton rb = (WebUI.HtmlControls.HtmlInputRadioButton)ctl;
                    if (rb.Checked)
                    {
                        entity.SetPropertyValue(pi.Name, rb.Value);
                    }
                }
                else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputCheckBox))//复选域
                {
                    WebUI.HtmlControls.HtmlInputCheckBox ck = (WebUI.HtmlControls.HtmlInputCheckBox)ctl;
                    if (ck.Checked)
                    {
                        entity.SetPropertyValue(pi.Name, ck.Value);
                    }
                }
                else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputPassword))//密码域
                {
                    WebUI.HtmlControls.HtmlInputPassword ck = (WebUI.HtmlControls.HtmlInputPassword)ctl;
                    entity.SetPropertyValue(pi.Name, ck.Value);
                }
                #endregion
            }
        }