Ejemplo n.º 1
0
    public void ClearControls(Control.ControlCollection Controls)
    {
        Hashtable ht = new Hashtable();

        foreach (Control c in Controls)
        {
            if (c is RyanTextBox)
            {
                RyanTextBox txt0 = (RyanTextBox)c;
                txt0.Text = "";
            }

            if (c is MaskedTextBox)
            {
                MaskedTextBox txt1 = (MaskedTextBox)c;
                txt1.Text = "";
            }
            if (c is TextBox)
            {
                TextBox txt2 = (TextBox)c;
                txt2.Text = "";
            }

            if (c is CheckBox)
            {
                CheckBox txt3 = (CheckBox)c;
                txt3.Checked = false;
            }
        }
    }
        /*
         * /// <summary>
         * /// 分页获取数据列表
         * /// </summary>
         * public DataSet GetList(int PageSize,int PageIndex,string strWhere)
         * {
         *  SqlParameter[] parameters = {
         *          new SqlParameter("@tblName", SqlDbType.VarChar, 255),
         *          new SqlParameter("@fldName", SqlDbType.VarChar, 255),
         *          new SqlParameter("@PageSize", SqlDbType.Int),
         *          new SqlParameter("@PageIndex", SqlDbType.Int),
         *          new SqlParameter("@IsReCount", SqlDbType.Bit),
         *          new SqlParameter("@OrderType", SqlDbType.Bit),
         *          new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
         *          };
         *  parameters[0].Value = "Meter";
         *  parameters[1].Value = "MeterID";
         *  parameters[2].Value = PageSize;
         *  parameters[3].Value = PageIndex;
         *  parameters[4].Value = 0;
         *  parameters[5].Value = 0;
         *  parameters[6].Value = strWhere;
         *  return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
         * }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        public Meter_Model GetModelByControl(Control.ControlCollection Controls)
        {
            Meter_Model model = new Meter_Model();

            foreach (Control c in Controls)
            {
                try
                {
                    if (c is RyanTextBox)
                    {
                        RyanTextBox txt0 = (RyanTextBox)c;
                        model.GetType().GetProperty(txt0.Name).SetValue(model, CommonHelper.ChanageType(txt0.Text, model.GetType().GetProperty(txt0.Name).PropertyType), null);
                    }
                    if (c is MaskedTextBox)
                    {
                        MaskedTextBox txt1 = (MaskedTextBox)c;
                        model.GetType().GetProperty(txt1.Name).SetValue(model, CommonHelper.ChanageType(txt1.Text, model.GetType().GetProperty(txt1.Name).PropertyType), null);
                    }
                    if (c is TextBox)
                    {
                        TextBox txt2 = (TextBox)c;
                        model.GetType().GetProperty(txt2.Name).SetValue(model, CommonHelper.ChanageType(txt2.Text, model.GetType().GetProperty(txt2.Name).PropertyType), null);
                    }
                    if (c is CheckBox)
                    {
                        CheckBox txt3 = (CheckBox)c;
                        int      val  = txt3.Checked ? 1 : 0;
                        model.GetType().GetProperty(txt3.Name).SetValue(model, val, null);
                    }
                    if (c is ComboBox)
                    {
                        ComboBox txt4 = (ComboBox)c;
                        model.GetType().GetProperty(txt4.Name).SetValue(model, CommonHelper.ChanageType(txt4.SelectedValue, model.GetType().GetProperty(txt4.Name).PropertyType), null);
                    }
                    if (c is DateTimePicker)
                    {
                        DateTimePicker txt5 = (DateTimePicker)c;
                        DateTime       dtDate;
                        if (DateTime.TryParse(txt5.Value.ToString(), out dtDate))
                        {
                            model.GetType().GetProperty(txt5.Name).SetValue(model, dtDate, null);
                        }
                    }
                }
                catch (Exception)
                {
                }
            }

            return(model);
        }
Ejemplo n.º 3
0
    public Hashtable GetHashTableByControl(Control.ControlCollection Controls)
    {
        Hashtable ht = new Hashtable();

        foreach (Control c in Controls)
        {
            if (c is RyanTextBox)
            {
                RyanTextBox txt0 = (RyanTextBox)c;
                ht[txt0.Name.ToUpper()] = txt0.Text.Trim();
            }
            if (c is MaskedTextBox)
            {
                MaskedTextBox txt1 = (MaskedTextBox)c;
                ht[txt1.Name.ToUpper()] = txt1.Text.Trim();
            }
            if (c is TextBox)
            {
                TextBox txt2 = (TextBox)c;
                ht[txt2.Name.ToUpper()] = txt2.Text.Trim();
            }

            if (c is CheckBox)
            {
                CheckBox txt3 = (CheckBox)c;
                ht[txt3.Name.ToUpper()] = txt3.Checked ? 1 : 0;
            }

            if (c is ComboBox)
            {
                ComboBox txt4 = (ComboBox)c;
                ht[txt4.Name.ToUpper()] = txt4.SelectedValue;
            }
            if (c is DateTimePicker)
            {
                DateTimePicker txt5 = (DateTimePicker)c;

                DateTime dtDate;
                if (DateTime.TryParse(txt5.Value.ToString(), out dtDate))
                {
                    ht[txt5.Name.ToUpper()] = txt5.Value;
                }
            }
        }

        return(ht);
    }
Ejemplo n.º 4
0
    public void BindHashTableToForm(Hashtable ht, Control.ControlCollection Controls)
    {
        if (ht.Count > 0)
        {
            foreach (string htName in ht.Keys)
            {
                foreach (Control c in Controls)
                {
                    if (c.Name.ToUpper().Equals(htName))
                    {
                        if (c is RyanTextBox)
                        {
                            RyanTextBox txt0 = (RyanTextBox)c;
                            txt0.Text = ht[htName].ToString();
                        }
                        if (c is MaskedTextBox)
                        {
                            MaskedTextBox txt1 = (MaskedTextBox)c;
                            txt1.Text = ht[htName].ToString();
                        }

                        if (c is TextBox)
                        {
                            TextBox txt2 = (TextBox)c;
                            txt2.Text = ht[htName].ToString();
                        }

                        if (c is CheckBox)
                        {
                            CheckBox txt3 = (CheckBox)c;
                            if (!string.IsNullOrEmpty(ht[htName].ToString()))
                            {
                                bool isCheck = false;
                                if (bool.TryParse(ht[htName].ToString(), out isCheck))
                                {
                                    txt3.Checked = isCheck;
                                }
                                else
                                {
                                    txt3.Checked = ht[htName].ToString().Equals("1") ? true : false;
                                }
                            }
                            else
                            {
                                txt3.Checked = false;
                            }
                        }

                        if (c is ComboBox)
                        {
                            ComboBox txt4 = (ComboBox)c;
                            foreach (System.Data.DataRowView dr in txt4.Items)
                            {
                                if (ht[htName].ToString().Equals(dr[txt4.ValueMember].ToString()) || ht[htName].ToString().Replace("True", "1").Equals(dr[txt4.ValueMember].ToString()))
                                {
                                    txt4.Text = dr[txt4.DisplayMember].ToString();
                                    // continue;
                                }
                                //else
                                //{
                                //    txt4.Text = "";
                                //}
                            }
                        }
                        if (c is DateTimePicker)
                        {
                            DateTimePicker txt5 = (DateTimePicker)c;
                            DateTime       dtDate;
                            if (DateTime.TryParse(ht[htName].ToString(), out dtDate))
                            {
                                txt5.Value = dtDate;
                            }
                        }
                    }
                }
            }
        }
    }