Exemple #1
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.FldName,
                logTable,
                logStudyMeasID,
                logMeasurePK,
                logMasterPK
                );
        }
        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);
        }
        /*
         * 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);
            }
        }
 /*
  * 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()));
     }
 }
 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);
     }
 }
 /*
  * 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);
     }
 }
        }         //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);
        }
        /*
         * 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
 /*
  * 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);
     }
 }
 /*
  * 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);
     }
 }
Exemple #11
0
        public static void BuildTables(DataTable dt, string str_measureID, UpdatePanel panelDEMainBody, string mode, Panel panelDEInsert)         //, Panel popupPanel)
        {
            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)
                {
                    //Add ID and indexnum
                    Literal litID = new Literal();
                    litID.Text = "<br/>";

                    DataFieldControl dfcID = new DataFieldControl();
                    dfcID.FldName        = "ID"; dfcID.IsInsertField = true; dfcID.FieldLabelWidth = 100; dfcID.FieldTextBoxWidth = 100; dfcID.FieldTextBoxMaxLength = 15;
                    dfcID.FieldLabelText = "ID"; dfcID.ID = "ID";
                    DataFieldControl dfcIndexnum = new DataFieldControl();
                    dfcIndexnum.FldName        = "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.";

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



                    //Build the body
                    // start at 1 for now
                    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();
                        LinkButton t_linkbtn           = new LinkButton();
                        string     section_header_text = "";
                        DataTable  dt_rowheader        = null;
                        DataTable  dt_colheader        = null;

                        if (dt_sections != null)
                        {
                            if (dt_sections.Rows.Count > 0)
                            {
                                try
                                {
                                    section_header_text = dt_sections.AsEnumerable().Where(r => r.Field <int>("layout_section") == 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 row header data
                                    dt_rowheader = sql.DataTable_from_SQLstring("select * from def.Tbl_SectionRow where tblpk=(select tblpk from def.Tbl where measureID=" + str_measureID + ") and layout_section=" + t.ToString());

                                    //Get the column header data
                                    dt_colheader = sql.DataTable_from_SQLstring("select * from def.Tbl_SectionCol where tblpk=(select tblpk from def.Tbl where measureID=" + str_measureID + ") and layout_section=" + t.ToString());
                                }
                                catch (Exception ex)
                                {
                                    string x = ex.Message;
                                    //no section with this number yet
                                }
                            }
                        }
                        else                          // No section text yet
                        {
                            //section_header_text = "[Section " + t.ToString();
                        }



                        Table tbl = BuildTable(view_tbl, dt_rowheader, dt_colheader, mode, t);


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

                        if (mode == "Layout")
                        {
                            // This LinkButton is given an onclick event so that it can trigger a modal popup to edit the contents of the section header

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

                            t_linkbtn.Text           = "<br/>" + section_header_text + " <span style=\"color: grey; background-color: #eeeeee;\">[sect " + t.ToString() + "]</span>";
                            t_linkbtn.Font.Underline = false;
                            t_linkbtn.ID             = "section" + t.ToString();
                            t_linkbtn.ClientIDMode   = ClientIDMode.Static;
                            t_linkbtn.ForeColor      = Color.Black;
                            t_linkbtn.Attributes.Add("runat", "server");



                            //t_linkbtn.ValidateRequestMode = ValidateRequestMode.Disabled;

                            panelDEMainBody.ContentTemplateContainer.Controls.Add(t_linkbtn);
                            //panelDEMainBody.Controls.Add(t_linkbtn);
                            t_linkbtn.OnClientClick = "return ShowModalPopup('" + section_header_text + "'," + t.ToString() + ", -1, 'section')";
                        }
                        else
                        {
                            t_label.Text = "<br/>" + section_header_text;
                            panelDEMainBody.ContentTemplateContainer.Controls.Add(t_label);
                            //panelDEMainBody.Controls.Add(t_label);
                        }


                        panelDEMainBody.ContentTemplateContainer.Controls.Add(tbl);
                        //panelDEMainBody.Controls.Add(tbl);
                    }
                }
            }
        }
Exemple #12
0
        public static TableCell BuildCell(DataView dv, string mode)
        {
            TableCell cell = new TableCell();

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

            DataTable dt = dv.ToTable();

            foreach (DataRow row in dt.Rows)
            {
                if (!string.IsNullOrEmpty(row["fldname"].ToString()))
                {
                    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["fldname"].ToString();
                    dfc.FieldDataType     = fdt;
                    dfc.FldName           = row["fldname"].ToString();
                    dfc.FieldLabelText    = row["aspxfieldlabeltext"].ToString();
                    dfc.FieldLabelWidth   = Unit.Pixel(width_label);
                    dfc.FieldTextBoxWidth = Unit.Pixel(width_box);



                    if (fdt == FieldDataType.DATE)
                    {
                        dfc.FormatString = "{0:d}";
                    }

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

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


                    dfc.FieldTextBoxText = row["fldname"].ToString();
                    //dfc.ToolTip = row["fieldnameandlabel"].ToString();

                    if (mode == "DataEntry")
                    {
                        TextBox txtbox = (TextBox)dfc.Controls[1];
                        txtbox.Enabled = true;
                        txtbox.ToolTip = row["fieldnameandlabel"].ToString();
                    }

                    else if (mode == "Layout")
                    {
                        TextBox txtbox = (TextBox)dfc.Controls[1];

                        //Read-only textboxes are Enabled=false; so that users cannot make changes to them when entering data.
                        // However, here we need to enable all fields so that the click event can be processed since we are in editing mode.
                        txtbox.Enabled = true;

                        txtbox.BackColor = Color.FromName(row["fldtype_backcolor"].ToString());

                        txtbox.ToolTip = row["fieldnameandlabel"].ToString();

                        string javascript_text = "javascript:ShowModalPopup2(" + row["fldpk"].ToString() + ",'" + row["fldname"].ToString() +
                                                 "','" + row["fieldlabel"].ToString() + "','" + row["aspxfieldlabeltext"].ToString() +
                                                 "'," + row["layout_section"].ToString() + "," + row["layout_row"].ToString() + "," + row["layout_col"].ToString() +
                                                 "," + row["fldtypepk"].ToString() + ",'" + row["missval"].ToString() + "'" + "," + row["width_label"] + "," + row["width_box"] +
                                                 " );return false;";

                        txtbox.Attributes.Add("onclick", javascript_text);

                        //dfc.BackColor = Color.FromName(row["fldtype_backcolor"].ToString());
                    }



                    cell.Controls.Add(dfc);

                    if (row["showValueLabels"].ToString() == "1")
                    {
                        ValueSetLabel vs = new ValueSetLabel();
                        vs.FldName       = row["fldname"].ToString();
                        vs.DatabaseTable = row["tblname"].ToString();
                        cell.Controls.Add(vs);
                    }
                }


                else
                {
                    if (mode == "Layout")
                    {
                        Literal blankcell = new Literal();
                        blankcell.Text = "**empty_cell**";
                        cell.Controls.Add(blankcell);
                    }
                }
            }


            return(cell);
        }