Exemplo n.º 1
0
        protected bool CheckMax(DataFieldControl dfc)
        {
            bool   valid    = false;
            string sUserVal = dfc.FieldTextBoxText;
            string sMaxVal  = dfc.MaxVal;

            switch (dfc.FieldDataType)
            {
            case FieldDataType.INT:

                valid = (int.Parse(sUserVal) <= int.Parse(sMaxVal));
                break;

            case FieldDataType.FLOAT:
                valid = (float.Parse(sUserVal) <= float.Parse(sMaxVal));
                break;

            case FieldDataType.DATE:
                valid = (DateTime.Parse(sUserVal) <= DateTime.Parse(sMaxVal));

                break;

            case FieldDataType.TEXT:
                valid = (string.Compare(sUserVal, sMaxVal) <= 0);
                break;

            default:
                throw new Exception("FieldDataType invalid.");
            }             // end switch

            return(valid);
        }
Exemplo n.º 2
0
        /*
         * Validate user supplied value against a regular expression.
         *
         * Only validate if regex is supplied and user supplies a value.
         *
         * Return false if validation fails for any field.
         *
         */
        protected bool ValidateRegEx2(DataFieldControl dfc, ArrayList notifications)
        {
            if ((dfc.RegEx != string.Empty) && dfc.FieldTextBoxText.Trim() != string.Empty)
            {
                if (Regex.IsMatch(dfc.FieldTextBoxText, dfc.RegEx) == false)
                {
                    string err = dfc.RegExDescription;

                    // set a default value for error text if none specified
                    if (err == string.Empty)
                    {
                        err = "Invalid value.";
                    }

                    dfc.AddError(err);
                    notifications.Add(string.Format("Error in field {0}. ", Shorten(dfc.FieldLabelText)) + err);
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 3
0
        public static void LogField(
            SqlCommand cmd,
            DataFieldControl dfc,
            string logDateTime,
            string logTable,
            int logStudyMeasID,
            int logMeasurePK,
            int logMasterPK
            )
        {
            string logEntryType = (dfc.VerifyError)?LogEntryType.FIELD_ERROR_VERIFY:LogEntryType.FIELD_ERROR_VALIDATE;
            string logText      = dfc.GetErrorText();

            WriteLog(
                cmd,
                string.Empty,
                logEntryType,
                logDateTime,
                logText,
                dfc.DatabaseField,
                logTable,
                logStudyMeasID,
                logMeasurePK,
                logMasterPK
                );
        }
Exemplo n.º 4
0
 /*
  * Check if the user supplied value in dataEntryFields matches any
  * values in it's specified MissVal list.  MissVal is a comma delimited string of values of
  * type fieldDataType. Items in list might be in form x thru y.  See RangeList class
  * for details.
  *
  * Validate user entered values against fielddatatype before calling this function.
  *
  * Return TRUE only if both a value and MissVal are supplied and value is in MissVal.
  *
  */
 protected bool ValidateMissVal2(DataFieldControl dfc)
 {
     if (dfc.MissVal.Trim() == string.Empty || dfc.FieldTextBoxText.Trim() == string.Empty)
     {
         return(false);
     }
     else
     {
         return(dfc.MissValRangeList.InList(dfc.FieldTextBoxText.Trim()));
     }
 }
Exemplo n.º 5
0
 protected bool ValidateInsertRequired2(DataFieldControl dfc, ArrayList notifications)
 {
     if (dfc.IsInsertValueRequired && (dfc.FieldTextBoxText.Trim() == string.Empty))
     {
         dfc.AddError(string.Format("{0} is required.", Shorten(dfc.FieldLabelText)));
         notifications.Add(string.Format("{0} is required.", Shorten(dfc.FieldLabelText)));
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 6
0
 /*
  * Verify that any user supplied value in dataEntryFields matches its
  * specified fielddatatype.  All fields must specify a fieldDataType.
  *
  * Only validate if user supplies a value.
  *
  * Put any errors in notifications.
  *
  * Return FALSE if any validation errors occur.
  *
  */
 protected bool ValidateFieldType2(DataFieldControl dfc, ArrayList notifications)
 {
     if (dfc.FieldTextBoxText.Trim() != string.Empty &&
         FieldTypeUtil.CheckType(dfc.FieldTextBoxText.Trim(), dfc.FieldDataType) == false)
     {
         dfc.AddError(string.Format("{0} is not a valid {1} value.", Shorten(dfc.FieldLabelText), dfc.FieldDataType));
         notifications.Add(string.Format("{0} is not a valid {1} value.", Shorten(dfc.FieldLabelText), dfc.FieldDataType));
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 7
0
        protected void AddParameter(SqlParameterCollection pcol, DataFieldControl dfc)
        {
            object val = null;

            if (dfc.FieldTextBoxText.Trim() == string.Empty)
            {
                val = DBNull.Value;
            }
            else
            {
                switch (dfc.FieldDataType)
                {
                case FieldDataType.INT:
                    val = int.Parse(dfc.FieldTextBoxText);
                    break;

                case FieldDataType.FLOAT:
                    val = double.Parse(dfc.FieldTextBoxText);

                    break;

                case FieldDataType.TEXT:

                    // limit input to maxlength, if necessary.
                    // This is needed because maxLength doesn't apply to
                    // multiline text boxes
                    string sval = dfc.FieldTextBoxText.Trim();
                    if (sval.Length > dfc.FieldTextBoxMaxLength)
                    {
                        sval = sval.Substring(0, dfc.FieldTextBoxMaxLength);
                    }

                    val = sval;
                    break;

                case FieldDataType.DATE:
                    val = DateTime.Parse(dfc.FieldTextBoxText);
                    break;

                default:
                    throw new Exception("FieldDataType invalid.");
                }
            }

            pcol.AddWithValue("@" + dfc.DatabaseField, val);
        }
Exemplo n.º 8
0
        }         //function

        /*
         * Return true if the user supplied value is within the range
         * specified by minVal and maxVal.
         *
         */
        protected bool CheckMinMaxBetween(DataFieldControl dfc)
        {
            bool valid = false;

            if (dfc.MaxVal != string.Empty && dfc.MinVal != string.Empty)
            {            //between
                valid = CheckBetween(dfc);
            }
            else if (dfc.MinVal != string.Empty)
            {             //check min
                valid = CheckMin(dfc);
            }
            else
            {             // check max
                valid = CheckMax(dfc);
            }
            return(valid);
        }
Exemplo n.º 9
0
        /*
         * Compare the user entered value to the entries in validList.
         * Return FALSE if no match is found.
         *
         */
        protected bool CheckValidList(DataFieldControl dfc)
        {
            // loop over values in validlist and perform a type
            // specific comparision
            string [] split = dfc.ValidList.Split(new Char [] { ',' });
            bool      match = false;

            foreach (string sCheckVal in split)
            {
                match = false;
                string sUserVal = dfc.FieldTextBoxText;
                switch (dfc.FieldDataType)
                {
                case FieldDataType.INT:

                    match = (int.Parse(sUserVal) == int.Parse(sCheckVal));
                    break;

                case FieldDataType.FLOAT:
                    match = (float.Parse(sUserVal) == float.Parse(sCheckVal));
                    break;

                case FieldDataType.DATE:
                    match = (DateTime.Parse(sUserVal) == DateTime.Parse(sCheckVal));
                    break;

                case FieldDataType.TEXT:
                    match = (sUserVal.Trim() == sCheckVal.Trim());
                    break;

                default:
                    throw new Exception("FieldDataType invalid.");
                }                 // end switch

                // leave loop of match found
                if (match)
                {
                    break;
                }
            }             // for loop

            return(match);
        }         // function
Exemplo n.º 10
0
 /*
  * Verify that the user supplied value in dataEntryFields matches its
  * specified validList.  validLIst is a comma delimited string of values of
  * type fieldDataType. Items in list might be in form x thru y.  See RangeList class
  * for details.
  *
  * Only validate fields that supply a value for validList
  * AND where the user has supplied a value.
  *
  * Validate user entered values against fielddatatype before calling this function.
  *
  * Put any errors in notifications.
  *
  * Return FALSE if any validation errors occur.
  *
  */
 protected bool ValidateValidList2(DataFieldControl dfc, ArrayList notifications)
 {
     if (dfc.ValidList != string.Empty && dfc.FieldTextBoxText.Trim() != string.Empty)
     {
         if (dfc.ValidListRangeList.InList(dfc.FieldTextBoxText.Trim()) == false)
         {
             dfc.AddError(string.Format("{0} must be in {1}.", Shorten(dfc.FieldLabelText), dfc.ValidList));
             notifications.Add(string.Format("{0} must be in {1}.", Shorten(dfc.FieldLabelText), dfc.ValidList));
             return(false);
         }
         else
         {
             return(true);
         }
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 11
0
 /*
  * Verify that user supplied value is within the range specified by minVal and maxVal.
  *
  * Only validate fields that have a user supplied value AND have a specified min or max val.
  *
  * Validate the user supplied value against the fieldtype before calling.
  *
  * Return FALSE if errors occur.
  *
  */
 protected bool ValidateMinMaxBetween2(DataFieldControl dfc, ArrayList notifications)
 {
     // only check if minval or maxval exist AND user supplied a value
     if ((dfc.MaxVal != string.Empty || dfc.MinVal != string.Empty) &&
         dfc.FieldTextBoxText.Trim() != string.Empty)
     {
         if (CheckMinMaxBetween(dfc) == false)
         {
             // construct the appropriate message
             string msg;
             if (dfc.MaxVal != string.Empty && dfc.MinVal != string.Empty)
             {
                 msg = string.Format("{0} value must between {1} and {2}.", Shorten(dfc.FieldLabelText), dfc.MinVal, dfc.MaxVal);
             }
             else if (dfc.MinVal != string.Empty)
             {
                 msg = string.Format("{0} value must be greater than or equal to {1}.", Shorten(dfc.FieldLabelText), dfc.MinVal);
             }
             else
             {
                 msg = string.Format("{0} value must be less than or equal to {1}.", Shorten(dfc.FieldLabelText), dfc.MaxVal);
             }
             dfc.AddError(msg);
             notifications.Add(msg);
             return(false);
         }
         else
         {
             return(true);
         }
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 12
0
        public static void BuildTables(DataTable dt, string str_measureID, Panel panel1)
        {
            string display_the = "Layout";

            var var_numtables = dt.AsEnumerable().Max(row => row.Field <int?>("layout_section"));

            if (var_numtables != null)
            {
                int?numtables = Convert.ToInt16(var_numtables.ToString());


                SQL_utils sql         = new SQL_utils();
                DataTable dt_sections = GetSectionText(str_measureID);

                //var numtables = dt.AsEnumerable().Max(row => row["layout_tbl"]); int
                //numtables = 3;

                if (numtables > 0)
                {
                    //string code_header = ""; string code_body = ""; string
                    //code_footer = ""; string deformname = ""; string tblname =
                    //""; string measname = ""; string pkname = "";

                    //if (display_the == "Code")   //Add the header
                    //{
                    //    DataTable dt_forminfo = sql.DataTable_from_SQLstring("exec spDEF__GetFormInfo " + str_measureID);

                    //    measname = dt_forminfo.AsEnumerable().Select(f => f.Field<string>("measname")).First();
                    //    tblname = dt_forminfo.AsEnumerable().Select(f => f.Field<string>("tblname")).First();
                    //    deformname = dt_forminfo.AsEnumerable().Select(f => f.Field<string>("deformname")).First();
                    //    pkname = dt_forminfo.AsEnumerable().Select(f => f.Field<string>("pkname")).First();

                    //    if (string.IsNullOrEmpty(deformname))
                    //    {
                    //        deformname = tblname.Replace("ALL_", "");
                    //    }

                    //    code_header =
                    //        "<%@ Register TagPrefix=\"def\" Namespace=\"DataEntryFramework3\" %> " + Environment.NewLine +
                    //        "<%@ Page language=\"c#\" MasterPageFile=\"~/UWAutism.master\"  Title=\"" + deformname + " Data Entry\" " + Environment.NewLine +
                    //        "CodeFile=\"" + measname + ".aspx.cs\" Inherits=\"DataEntryForms_Common_" + deformname + "_" + deformname + "\" Debug=\"true\"%>" + Environment.NewLine +
                    //        "<asp:Content ID=\"Content1\" ContentPlaceHolderID=\"oBodyPlaceHolder\" runat=\"server\">" + Environment.NewLine +
                    //        "<link rel=\"stylesheet\" type=\"text/css\" href=\"~/css/dataentryforms.css\" />" + Environment.NewLine +
                    //        "<def:dataentrycontroller id=\"DataEntryController1\" runat=\"server\" DatabaseTable=\"" + tblname + "\" PrimaryKeyField=\"" + pkname + "\" ></def:dataentrycontroller>" + Environment.NewLine +
                    //        "<def:datafieldcontrol runat=\"server\" id=\"id\" DatabaseField=\"id\" IsInsertField=\"true\"  IsEntryField=\"true\" IsDoubleEntryField=\"true\" FieldLabelWidth=\"100px\" FieldTextBoxWidth=\"80px\" FieldTextBoxMaxLength=\"15\"></def:datafieldcontrol>" + Environment.NewLine +
                    //        "<def:datafieldcontrol runat=\"server\" id=\"indexnum\" DatabaseField=\"indexnum\" IsInsertField=\"true\" FieldTextBoxTextDefault=\"1\"  IsEntryField=\"true\" IsDoubleEntryField=\"true\" FieldLabelWidth=\"100px\" FieldTextBoxWidth=\"40px\"></def:datafieldcontrol>" + Environment.NewLine +
                    //        "<br/><br/>" + Environment.NewLine;

                    //    Label lbl_header_code = new Label();
                    //    lbl_header_code.Text = code_header;

                    //    panel1.Controls.Add(lbl_header_code);

                    //}

                    //Add ID and indexnum
                    Literal litID = new Literal();
                    litID.Text = "<br/>";

                    DataFieldControl dfcID = new DataFieldControl();
                    dfcID.DatabaseField  = "ID"; dfcID.IsInsertField = true; dfcID.FieldLabelWidth = 100; dfcID.FieldTextBoxWidth = 100; dfcID.FieldTextBoxMaxLength = 15;
                    dfcID.FieldLabelText = "ID"; dfcID.ID = "ID";
                    DataFieldControl dfcIndexnum = new DataFieldControl();
                    dfcIndexnum.DatabaseField  = "indexnum"; dfcIndexnum.IsInsertField = true; dfcIndexnum.FieldLabelWidth = 100; dfcIndexnum.FieldTextBoxWidth = 100; dfcIndexnum.FieldTextBoxMaxLength = 15;
                    dfcIndexnum.FieldLabelText = "indexnum"; dfcIndexnum.ID = "indexnum";

                    dfcID.FieldDataType       = FieldDataType.TEXT;
                    dfcIndexnum.FieldDataType = FieldDataType.INT;


                    dfcID.ToolTip       = "This is the ID field.";
                    dfcIndexnum.ToolTip = "This is the indexnum field.";

                    panel1.Controls.Add(litID);
                    panel1.Controls.Add(dfcID);
                    panel1.Controls.Add(dfcIndexnum);



                    //Build the body
                    for (int t = 1; t <= numtables; t++)
                    {
                        // Now create a DataView based on the DataTable.
                        // Sort and filter the data.
                        DataView view_tbl = dt.DefaultView;
                        view_tbl.Sort      = "layout_section, layout_row, layout_col";
                        view_tbl.RowFilter = "layout_section=" + t.ToString();


                        Label     t_label             = new Label();
                        string    section_header_text = "";
                        DataTable dt_colheader        = null;

                        if (dt_sections != null)
                        {
                            if (dt_sections.Rows.Count > 0)
                            {
                                section_header_text = dt_sections.AsEnumerable().Where(r => r.Field <int>("sectionnum") == t).Select(r => r.Field <string>("sectionheadertext")).First();
                                int sectionID = dt_sections.AsEnumerable().Where(r => r.Field <int>("sectionnum") == t).Select(r => r.Field <int>("sectionID")).First();


                                //Get the column header data
                                dt_colheader = sql.DataTable_from_SQLstring("select * from datTable_Section_Column where sectionID=" + sectionID.ToString());
                            }
                        }
                        else  // No section text yet
                        {
                            //section_header_text = "[Section " + t.ToString();
                        }



                        Table tbl = BuildTable(view_tbl, dt_colheader, display_the);


                        tbl.BorderWidth = 2;
                        //tbl.BorderColor =
                        //System.Drawing.ColorTranslator.FromHtml("#9EC0E0"); ;
                        tbl.BorderColor = Color.White;


                        //if (display_the == "Layout") {
                        //    //Add the section and column
                        //    //numbers to the header text
                        //    t_label.Text = "<br/>" + section_header_text + " <span style=\"background-color: #dddddd\">[section " + t.ToString() + "]</span>";

                        //}

                        //Add the section header label
                        panel1.Controls.Add(t_label);

                        panel1.Controls.Add(tbl);
                    }
                }
            }
        }
Exemplo n.º 13
0
        public static TableCell BuildCell(DataView dv, string display_the)
        {
            TableCell cell = new TableCell();
            DataTable dt   = dv.ToTable();

            foreach (DataRow row in dt.Rows)
            {
                int width_label = (row["width_label"].ToString() == "") ? 300 : Convert.ToInt16(row["width_label"].ToString());
                int width_box   = (row["width_box"].ToString() == "") ? 50 : Convert.ToInt16(row["width_box"].ToString());


                ////HERE!!!! check to see if mode is necessary anymore
                //if (mode == "DE Form")
                //{
                //    if (display_the == "Layout")
                //    {

                FieldDataType fdt = new FieldDataType();

                switch (row["fielddatatype"].ToString())
                {
                case "int":
                    fdt = FieldDataType.INT;
                    break;

                case "float":
                    fdt = FieldDataType.FLOAT;
                    break;

                case "nvarchar":
                    fdt = FieldDataType.TEXT;
                    break;

                case "varchar":
                    fdt = FieldDataType.TEXT;
                    break;

                case "char":
                    fdt = FieldDataType.TEXT;
                    break;

                case "date":
                    fdt = FieldDataType.DATE;
                    break;

                case "datetime":
                    fdt = FieldDataType.DATE;
                    break;
                }



                DataFieldControl dfc = new DataFieldControl();
                dfc.ID                = row["databasefield"].ToString();
                dfc.FieldDataType     = fdt;
                dfc.DatabaseField     = row["databasefield"].ToString();
                dfc.FieldLabelText    = row["aspxfieldlabeltext"].ToString();
                dfc.FieldLabelWidth   = Unit.Pixel(width_label);
                dfc.FieldTextBoxWidth = Unit.Pixel(width_box);
                dfc.ToolTip           = row["databasefield"].ToString();


                if (row["isReadOnly"].ToString() == "0" | string.IsNullOrEmpty(row["isReadOnly"].ToString()))
                {
                    dfc.IsEntryField = true;
                }
                else
                {
                    dfc.IsReadOnly = true;
                }

                if (row["DoubleEntryRequired"].ToString() == "0" | string.IsNullOrEmpty(row["isReadOnly"].ToString()))
                {
                    dfc.IsDoubleEntryField = false;
                }
                else
                {
                    dfc.IsDoubleEntryField = true;
                }


                dfc.FieldTextBoxText = row["databasefield"].ToString();
                dfc.ToolTip          = row["databasefield"].ToString();

                cell.Controls.Add(dfc);

                if (row["showValueLabels"].ToString() == "1")
                {
                    ValueSetLabel vs = new ValueSetLabel();
                    vs.DatabaseField = row["databasefield"].ToString();
                    vs.DatabaseTable = row["databasetable"].ToString();
                    cell.Controls.Add(vs);
                }
                //    }

                //}
                //else if (mode == "Text")
                //{
                //    if (row["aspxfieldlabeltext"] != "" & row["aspxfieldlabeltext"] != " ")
                //    {
                //        Label l = new Label();
                //        l.Text = row["aspxfieldlabeltext"].ToString();
                //        l.Width = width_label;
                //        cell.Controls.Add(l);
                //    }
                //    TextBox t = new TextBox();
                //    t.Text = row["databasefield"].ToString();
                //    t.Font.Size = 8;
                //    t.Width = width_box;
                //    t.ToolTip = row["databasefield"].ToString();

                //    if (row["isReadOnly"].ToString() == "1")
                //    {
                //        t.BackColor = Color.SkyBlue;
                //    }
                //    else
                //    {
                //        t.BackColor = Color.LightYellow;
                //    }


                //    if (row["DoubleEntryRequired"].ToString() == "1" | row["DoubleEntryRequired"].ToString() == "")
                //    {
                //        t.ForeColor = Color.Black;
                //    }
                //    else
                //    {
                //        t.ForeColor = Color.Red;
                //    }



                //    Literal lit = new Literal();
                //    lit.Text += "<br/>";

                //    cell.Controls.Add(t);
                //    cell.Controls.Add(lit);

                //    if (row["showValueLabels"].ToString() == "1")
                //    {
                //        ValueSetLabel vs = new ValueSetLabel();
                //        vs.DatabaseField = row["databasefield"].ToString();
                //        vs.DatabaseTable = row["databasetable"].ToString();
                //        cell.Controls.Add(vs);
                //    }


                //    //string lbl = row["aspxfieldlabeltext"].ToString(); string var
                //    //= row["databasefield"].ToString(); cell.Text += lbl.ToString()
                //    //+ "....<i><b>" + var + "</b></i><br/>";

                //}
            }

            cell.VerticalAlign = VerticalAlign.Top;
            cell.BorderColor   = Color.White;
            cell.BorderWidth   = 1;

            return(cell);
        }