예제 #1
0
파일: eCCDocx.cs 프로젝트: vparekh/SSP
        public string CreateeCCContent(Document doc, string templateckey, string version)
        {
            string saveckey     = string.Empty;
            string savetext     = string.Empty;
            string saverequired = string.Empty;
            string saveitemtype = string.Empty;
            string html         = "";


            ancestry = new Dictionary <string, CKeyHierarchy>();


            System.Data.DataTable dt = SSPWebUI.Data.ChecklistTemplateItems.GetAllChecklistItemsForoutput(decimal.Parse(templateckey), 0, decimal.Parse(version)); //data.GeteCCBuilderView(templateckey, version);

            int    dimensioncount = 0;
            string lastckey       = "";

            //build ancestry dictionary
            foreach (DataRow dr in dt.Rows)
            {
                if (!ancestry.ContainsKey(dr["ChecklistTemplateItemCkey"].ToString()))
                {
                    CKeyHierarchy itm = new CKeyHierarchy();
                    itm.CKey = dr["ChecklistTemplateItemCkey"].ToString();

                    itm.PreviousSibling = lastckey;

                    //make sure parentckey is not deprecated
                    if (dr["ParentItemCKey"] != System.DBNull.Value && dr["ParentItemCKey"].ToString() != "")
                    {
                        itm.ParentCKey = dr["ParentItemCKey"].ToString();
                    }
                    else
                    {
                        itm.ParentCKey = "";
                    }


                    itm.Depth    = 0;
                    itm.ItemType = int.Parse(dr["ItemTypeKey"].ToString());
                    itm.Required = bool.Parse(dr["AuthorityRequired"].ToString());
                    itm.ItemText = dr["visibletext"].ToString();
                    lastckey     = itm.CKey;
                    //find parent ckey in ancestry and set the depth value
                    foreach (KeyValuePair <string, CKeyHierarchy> kvp in ancestry)
                    {
                        if (kvp.Key == itm.ParentCKey)
                        {
                            itm.Depth = kvp.Value.Depth + 1;
                        }
                    }

                    ancestry.Add(itm.CKey, itm);
                }
            }

            foreach (DataRow dr in dt.Rows)
            {
                string retval = "";

                if (!(dr["visibletext"].ToString().ToLower().Contains("greatest dimension") || dr["visibletext"].ToString().ToLower().Contains("additional dimension")) || int.Parse(dr["ItemTypeKey"].ToString()) != 17)
                {
                    if (dimensioncount > 0)
                    {
                        retval = PrintItem(savetext, int.Parse(saveitemtype), bool.Parse(saverequired), dimensioncount, saveckey, doc);
                        if (retval.Length > 0)
                        {
                            html = html + retval;
                        }
                    }

                    dimensioncount = 0;
                    retval         = PrintItem(dr["visibletext"].ToString(),
                                               int.Parse(dr["ItemTypeKey"].ToString()),
                                               bool.Parse(dr["AuthorityRequired"].ToString()),
                                               0, dr["ChecklistTemplateItemCkey"].ToString(), doc);
                    if (retval.Length > 0)
                    {
                        html = html + retval;
                    }
                }
                else
                {
                    dimensioncount++;
                    if (dimensioncount == 1)
                    {
                        saveckey     = dr["ChecklistTemplateItemCkey"].ToString();
                        savetext     = dr["visibletext"].ToString();
                        saverequired = dr["AuthorityRequired"].ToString();
                        saveitemtype = dr["ItemTypeKey"].ToString();
                    }
                }
            }

            return(html);
        }
예제 #2
0
파일: eCCDocx.cs 프로젝트: vparekh/SSP
        public string PrintItem(string Text, int ItemType, bool Required, int dimension, string CKey, Document doc = null)
        {
            //hidden text has visibletext = "", do not print a blank line, just return
            if (Text.Trim().Length == 0) // && ItemType != 23)
            {
                return("");
            }

            //remove ? from the beginning
            if (Text.Trim().StartsWith("?"))
            {
                Text = Text.Replace("?", "");
            }

            bool VerticalSpacing = false;

            //identify a question fill-in that is a child of an answer fill-in

            if (Text == "Distance from Closest Margin" || Text == "Specify Margin, if possible")
            {
                int check = ancestry[ancestry[CKey].ParentCKey].ItemType;
            }

            if (ItemType == 26 && ancestry[CKey].ParentCKey == lastparent)
            {
                combotext.Add(Text);
                return("");
            }

            if (ancestry[CKey].ParentCKey != lastparent)
            {
                if (ancestry[CKey].PreviousSibling != "")
                {
                    CKeyHierarchy lastkey = ancestry[ancestry[CKey].PreviousSibling];
                    //reset
                    combotext = new List <string>();
                }
            }

            lastparent = ancestry[CKey].ParentCKey;

            //do not print this note
            if (Text.Contains("Additional dimensions (repeat section if more than one part)"))
            {
                return("");
            }



            string    html    = "";
            string    newhtml = "";
            bool      isBold  = false;
            Paragraph p       = null;

            //if parent is required the child is required too although if it is mnot flagged as required in the model
            if (ancestry[CKey].ParentCKey != "")
            {
                if (ancestry.ContainsKey(ancestry[CKey].ParentCKey))
                {
                    if (ancestry[ancestry[CKey].ParentCKey].Required == true)
                    {
                        Required = true;
                    }
                }
            }

            int depth = ancestry[CKey].Depth;
            //string padding = "";
            string separator = new string('-', 60);
            string fillin    = " " + new string('_', 15);
            //string htmlpadding = "";

            string        parent = ancestry[CKey].ParentCKey;
            CKeyHierarchy test   = null;

            if (parent != "" && ancestry.ContainsKey(parent))
            {
                test = ancestry[parent];
            }

            int margin = 0;

            for (int i = 0; i <= depth; i++)
            {
                margin = margin + 14;
            }


            //add additional padding for each answer in the hierarchy (to account for ___ in the front)
            while (test != null && test.ParentCKey != null && test.ParentCKey != "")
            {
                if (test.ItemType == 6)
                {
                    margin = margin + 50;
                }
                test = ancestry[test.ParentCKey];
            }

            //question - single select (40 and multi-select (23) and header sections are bold
            //but it looks like user may not want to make some questions bold but wait for more input
            if (ItemType == 4 || ItemType == 23 || ItemType == 24 || ItemType == 17)   //12/23/2015: making QF bold as well

            {
                VerticalSpacing = true;
                if (ancestry.ContainsKey(ancestry[CKey].ParentCKey))
                {
                    if (ancestry[CKey].ParentCKey != "" &&
                        (ItemType == 17 || ItemType == 4) &&
                        (ancestry[ancestry[CKey].ParentCKey].ItemType == 20 || ancestry[ancestry[CKey].ParentCKey].ItemType == 6))

                    {
                        VerticalSpacing = false;
                    }
                }

                isBold = true;
            }
            else
            {
                isBold = false;
            }


            //item type specific logic
            switch (ItemType)
            {
            case 24:
                //header

                if (Required)
                {
                    newhtml = newhtml + Text;
                }
                else
                {
                    newhtml = newhtml + "+ " + Text;
                }

                break;

            case 4:      //question - single select
                if (Required)
                {
                    newhtml = newhtml + Text;
                }
                else
                {
                    newhtml = newhtml + "+" + Text;
                }

                break;

            case 6:       //answer


                if (Required)
                {
                    newhtml = newhtml + "<div><span>___</span><span style='margin-left:20px'>" + Text + "</span></div>";
                }
                else
                {
                    newhtml = newhtml + "<div><span>+ ___</span><span style='margin-left:30px'>" + Text + "</span></div>";
                }

                break;

            case 23:      //question - multiselect
                if (Required)
                {
                    newhtml = newhtml + Text;
                }
                else
                {
                    newhtml = newhtml + "+ " + Text;
                }

                break;

            case 20:      //answer fillin
                //do not need fill-in space if Text does not contain () at the end
                if (!Text.EndsWith(")"))
                {
                    fillin = "";
                }
                else
                {
                    fillin = ": " + fillin;
                    if (Text.ToLower().Equals("not specified"))
                    {
                        fillin = "";
                    }
                    if (Text.Equals("Cannot be determined"))     // VP fixed the bug since this was stopping to create fill-in for Cannot be determined (explain)
                    {
                        fillin = "";
                    }
                    if (Text.ToLower().Contains("not identified"))
                    {
                        fillin = "";
                    }
                    if (Text.ToLower().Contains("not applicable"))
                    {
                        fillin = "";
                    }
                    if (Text.ToLower().Contains("indeterminate"))
                    {
                        fillin = "";
                    }
                }
                if (Required)
                {
                    //flattent greatest dimension and additional dimension
                    //System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"(\(.+\))");
                    System.Text.RegularExpressions.Regex           reg        = new System.Text.RegularExpressions.Regex(@"(\([mm]*[cm]*[g]*)\)");
                    System.Text.RegularExpressions.MatchCollection collection = reg.Matches(Text);
                    string unit = "";
                    if (collection.Count == 1)
                    {
                        unit = collection[0].Value.Replace("(", "").Replace(")", "");
                    }

                    //greatest dimension is sometimes answer fill-in
                    if ((Text.ToLower().Contains("greatest dimension") || Text.Contains("Specify")) && unit != "")
                    {
                        fillin = ": ___";
                        for (int i = 1; i < dimension; i++)
                        {
                            fillin = fillin + " x ___";
                        }
                        fillin = fillin + " " + unit;
                        if (unit != "")
                        {
                            Text = Text.Replace("(" + unit + ")", "");
                        }

                        //html = html + htmlpadding + "___ " + Text +  fillin;

                        newhtml = newhtml + "<div><span>___</span><span style='margin-left:20px'>" + Text + fillin + "</span></div>";
                    }
                    else
                    {
                        newhtml = newhtml + "<div><span>___</span><span style='margin-left:20px'>" + Text + fillin + "</span></div>";
                    }
                }



                else
                {
                    System.Text.RegularExpressions.Regex           reg1        = new System.Text.RegularExpressions.Regex(@"(\([mm]*[cm]*[g]*)\)");
                    System.Text.RegularExpressions.MatchCollection collection1 = reg1.Matches(Text);
                    string unit1 = "";
                    if (collection1.Count == 1)
                    {
                        unit1 = collection1[0].Value.Replace("(", "").Replace(")", "");
                    }

                    //greatest dimension is sometimes answer fill-in
                    if ((Text.ToLower().Contains("greatest dimension") || Text.Contains("Specify")) && unit1 != "")
                    {
                        fillin = ": ___";
                        for (int i = 1; i < dimension; i++)
                        {
                            fillin = fillin + " x ___";
                        }
                        fillin = fillin + " " + unit1;
                        if (unit1 != "")
                        {
                            Text = Text.Replace("(" + unit1 + ")", "");
                        }


                        newhtml = newhtml + "<div><span>+ ___</span><span style='margin-left:30px'>" + Text + fillin + "</span></div>";
                    }
                    else
                    {
                        newhtml = newhtml + "<div><span>+ ___</span><span style='margin-left:30px'>" + Text + fillin + "</span></div>";
                    }
                }

                break;

            case 17:       //question fillin
                //initialize fillin space
                fillin = ": " + fillin;

                //suppress fill-in space for these items
                if (Text.ToLower().Equals("not specified"))
                {
                    fillin = "";
                }
                if (Text.ToLower().Contains("cannot be determined"))
                {
                    fillin = "";
                }
                if (Text.ToLower().Contains("not identified"))
                {
                    fillin = "";
                }
                if (Text.ToLower().Contains("not applicable"))
                {
                    fillin = "";
                }
                if (Text.ToLower().Contains("indeterminate"))
                {
                    fillin = "";
                }
                if (Required)
                {
                    System.Text.RegularExpressions.Regex           reg        = new System.Text.RegularExpressions.Regex(@"(\(.+\))");
                    System.Text.RegularExpressions.MatchCollection collection = reg.Matches(Text);
                    string unit = "";
                    if (collection.Count == 1)
                    {
                        unit = collection[0].Value.Replace("(", "").Replace(")", "");
                    }

                    if ((Text.ToLower().Contains("greatest dimension") || Text.ToLower().Contains("additional dimension") || Text.ToLower().Contains("specify weight") || Text.ToLower().Contains("Specify")) && (dimension > 1 || unit != ""))
                    {
                        fillin = ": ___";
                        for (int i = 1; i < dimension; i++)
                        {
                            fillin = fillin + " x ___";
                        }
                        fillin = fillin + " " + unit;
                        if (unit != "")
                        {
                            Text = Text.Replace("(" + unit + ")", "");
                        }
                    }
                    else
                    {
                    }

                    newhtml = newhtml + Text + fillin;
                }
                else
                {
                    System.Text.RegularExpressions.Regex           reg        = new System.Text.RegularExpressions.Regex(@"(\(.+\))");
                    System.Text.RegularExpressions.MatchCollection collection = reg.Matches(Text);
                    string unit = "";
                    if (collection.Count == 1)
                    {
                        unit = collection[0].Value.Replace("(", "").Replace(")", "");
                    }
                    if ((Text.ToLower().Contains("greatest dimension") || Text.ToLower().Contains("additional dimension")) && dimension > 1)
                    {
                        fillin = ": ___";
                        for (int i = 1; i < dimension; i++)
                        {
                            fillin = fillin + " x ___";
                        }
                        fillin = fillin + " " + unit;

                        if (unit != "")
                        {
                            Text = Text.Replace("(" + unit + ")", "");
                        }

                        newhtml = newhtml + "+ " + Text + fillin;
                    }
                    else
                    {
                        if (!Text.ToLower().Contains("comment(s)"))
                        {
                            newhtml = newhtml + "+ " + Text + fillin;        //2/89/2018 - added left padding
                        }
                        else
                        {
                            newhtml = newhtml + "+ " + Text;        //2/89/2018 - added left padding
                        }
                    }
                }
                break;

            case 12:      //note

                if (combotext.Count > 0)
                {
                    foreach (string combo in combotext)
                    {
                        //html  = html + htmlpadding + combo + "<br/>";
                    }
                    //italic
                    html    = "<span style='Font-Style:Italic'>" + html + "</span>";
                    newhtml = newhtml + html;
                }

                newhtml = "<span style='Font-Style:Italic'>" + Text + "</span>";
                break;

            case 26:     //combo note

                //combo notes appear among answer choices, user has requested to concatenate combo notes with the note that appear at the end
                if (Required)
                {
                    newhtml = newhtml + Text;
                }
                else
                {
                    newhtml = newhtml + Text;
                }
                break;

            default:

                break;
            }
            if (isBold && VerticalSpacing)
            {
                newhtml = "<div style='margin-top:8px;margin-bottom:0px;margin-left:" + margin.ToString() + "px;" + "'><b>" + newhtml + "</b></div>";
            }
            else if (isBold)
            {
                newhtml = "<div style='margin-top:3px;margin-bottom:0px;margin-left:" + margin.ToString() + "px;" + "'><b>" + newhtml + "</b></div>";
            }
            else
            {
                newhtml = "<div style='margin-top:3px;margin-bottom:0px;margin-left:" + margin.ToString() + "px;" + "'>" + newhtml + "</div>";
            }
            return(newhtml);
        }