Пример #1
0
        /// <summary>
        /// RenderControl using Control Type which is set in TfatDesignForm
        /// </summary>
        /// <param name="form">TfatDesignForm object for generate HTML control script</param>
        /// <param name="Data">Data is use for Edit & Delete view to set value to appropriate control</param>
        /// <param name="htw">Using HtmlTextWriter collect HTML Control script which is usefull for View</param>
        /// <param name="VType">VTYpe use to generate HTML Control & Set data to control</param>
        private static void RenderControl(TfatDesignForm form, object Data, HtmlTextWriter htw, string VType)
        {
            switch ((string.IsNullOrEmpty(form.fType) ? form.ControlType : form.fType))
            {
            case "T":     //Textbox
                if (VType == "EDIT" || VType == "DELETE")
                {
                    htw.AddAttribute("value", Convert.ToString(Data.GetType().GetProperty(form.Fld).GetValue(Data)));
                }
                if (VType == "DELETE" || form.TfatDesignHeader.IDKey.Equals(form.Fld))
                {
                    htw.AddAttribute("readonly", "readonly");
                }
                if (form.AllowBlank == true)
                {
                    htw.AddAttribute("required", "true");
                }
                htw.RenderBeginTag(HtmlTextWriterTag.Input);
                break;

            case "C":     //Calender
                if (VType == "EDIT" || VType == "DELETE")
                {
                    htw.AddAttribute("value", Convert.ToString(Data.GetType().GetProperty(form.Fld).GetValue(Data)));
                }
                if (VType == "DELETE" || form.TfatDesignHeader.IDKey.Equals(form.Fld))
                {
                    htw.AddAttribute("readonly", "readonly");
                }
                htw.AddAttribute("type", "date");
                if (form.AllowBlank == true)
                {
                    htw.AddAttribute("required", "true");
                }
                htw.RenderBeginTag(HtmlTextWriterTag.Input);
                break;

            case "P":     //Telephone
                if (VType == "EDIT" || VType == "DELETE")
                {
                    htw.AddAttribute("value", Convert.ToString(Data.GetType().GetProperty(form.Fld).GetValue(Data)));
                }
                if (VType == "DELETE" || form.TfatDesignHeader.IDKey.Equals(form.Fld))
                {
                    htw.AddAttribute("readonly", "readonly");
                }
                htw.AddAttribute("type", "tel");
                if (form.AllowBlank == true)
                {
                    htw.AddAttribute("required", "true");
                }
                htw.RenderBeginTag(HtmlTextWriterTag.Input);
                break;

            case "N":     //Number
                if (VType == "EDIT" || VType == "DELETE")
                {
                    htw.AddAttribute("value", Convert.ToString(Data.GetType().GetProperty(form.Fld).GetValue(Data)));
                }
                if (VType == "DELETE" || form.TfatDesignHeader.IDKey.Equals(form.Fld))
                {
                    //htw.AddAttribute("readonly", "readonly"); //comented by dipti
                    htw.AddAttribute("type", "number");
                }
                if (form.AllowBlank == true)
                {
                    htw.AddAttribute("required", "true");
                }
                htw.RenderBeginTag(HtmlTextWriterTag.Input);
                break;

            case "M":     //Month
                if (VType == "EDIT" || VType == "DELETE")
                {
                    htw.AddAttribute("value", Convert.ToString(Data.GetType().GetProperty(form.Fld).GetValue(Data)));
                }
                if (VType == "DELETE" || form.TfatDesignHeader.IDKey.Equals(form.Fld))
                {
                    htw.AddAttribute("readonly", "readonly");
                }
                htw.AddAttribute("type", "month");
                if (form.AllowBlank == true)
                {
                    htw.AddAttribute("required", "true");
                }
                htw.RenderBeginTag(HtmlTextWriterTag.Input);
                break;

            case "E":     //Email
                if (VType == "EDIT" || VType == "DELETE")
                {
                    htw.AddAttribute("value", Convert.ToString(Data.GetType().GetProperty(form.Fld).GetValue(Data)));
                }
                if (VType == "DELETE" || form.TfatDesignHeader.IDKey.Equals(form.Fld))
                {
                    htw.AddAttribute("readonly", "readonly");
                }
                htw.AddAttribute("type", "email");
                if (form.AllowBlank == true)
                {
                    htw.AddAttribute("required", "true");
                }
                htw.RenderBeginTag(HtmlTextWriterTag.Input);
                break;

            case "U":     //URL
                if (VType == "EDIT" || VType == "DELETE")
                {
                    htw.AddAttribute("value", Convert.ToString(Data.GetType().GetProperty(form.Fld).GetValue(Data)));
                }
                if (VType == "DELETE" || form.TfatDesignHeader.IDKey.Equals(form.Fld))
                {
                    htw.AddAttribute("readonly", "readonly");
                }
                htw.AddAttribute("type", "url");
                if (form.AllowBlank == true)
                {
                    htw.AddAttribute("required", "true");
                }
                htw.RenderBeginTag(HtmlTextWriterTag.Input);
                break;

            case "A":     //TextArea
                if (VType == "DELETE")
                {
                    htw.AddAttribute("readonly", "readonly");
                }
                if (form.AllowBlank == true)
                {
                    htw.AddAttribute("required", "true");
                }
                htw.RenderBeginTag(HtmlTextWriterTag.Textarea);
                if (VType == "EDIT" || VType == "DELETE")
                {
                    htw.WriteEncodedText(Convert.ToString(Data.GetType().GetProperty(form.Fld).GetValue(Data)));
                }
                htw.WriteEndTag("textarea");
                break;

            case "D":     //Dropdown
                if (form.AllowBlank == true)
                {
                    htw.AddAttribute("required", "true");
                }

                htw.RenderBeginTag(HtmlTextWriterTag.Select);

                if (!string.IsNullOrEmpty(form.FldValues.Trim()))
                {
                    if (form.FldValues.IndexOf("#") > 0)
                    {
                        string[] FldValues = form.FldValues.Split(new char[] { '#' });

                        DbSet TableData  = CoreCommon.GetTableData(FldValues.First());
                        var   SelectData = TableData.AsQueryable().ToListAsync().Result.ToList();
                        //
                        htw.AddAttribute("value", "0");
                        if (VType == "ADD")
                        {
                            htw.AddAttribute("selected", "0");
                        }
                        if (VType == "DELETE")
                        {
                            htw.AddAttribute("disabled", "ture");
                        }
                        htw.RenderBeginTag(HtmlTextWriterTag.Option);
                        htw.WriteEncodedText("");
                        htw.RenderEndTag();

                        foreach (var SData in SelectData)
                        {
                            htw.AddAttribute("value", SData.GetType().GetProperty(FldValues.Last().Split(new char[] { ',' }).First()).GetValue(SData).ToString());
                            if ((VType == "EDIT" || VType == "DELETE") && SData.GetType().GetProperty(FldValues.Last().Split(new char[] { ',' }).First()).GetValue(SData).ToString() == Convert.ToString(Data.GetType().GetProperty(form.Fld).GetValue(Data)))
                            {
                                htw.AddAttribute("selected", Convert.ToString(Data.GetType().GetProperty(form.Fld).GetValue(Data)));
                            }
                            if (VType == "DELETE")
                            {
                                htw.AddAttribute("disabled", "ture");
                            }
                            htw.AddStyleAttribute("width", "200px");     //set width for dropdown
                            htw.RenderBeginTag(HtmlTextWriterTag.Option);
                            htw.WriteEncodedText(Convert.ToString(SData.GetType().GetProperty(FldValues.Last().Split(new char[] { ',' }).Last()).GetValue(SData)));
                            htw.RenderEndTag();
                        }
                    }
                    else
                    {
                        string[] FldValues1 = form.FldValues.Split(new char[] { '^' });
                        htw.RenderBeginTag(HtmlTextWriterTag.Option);
                        htw.WriteEncodedText("");
                        htw.RenderEndTag();

                        foreach (var SData in FldValues1)
                        {
                            htw.AddAttribute("value", SData);
                            if ((VType == "EDIT" || VType == "DELETE") && SData.ToString() == Convert.ToString(Data.GetType().GetProperty(form.Fld).GetValue(Data)))
                            {
                                htw.AddAttribute("selected", Convert.ToString(Data.GetType().GetProperty(form.Fld).GetValue(Data)));
                            }
                            if (VType == "DELETE")
                            {
                                htw.AddAttribute("disabled", "ture");
                            }
                            htw.AddStyleAttribute("width", "200px");     //set width for dropdown
                            htw.RenderBeginTag(HtmlTextWriterTag.Option);
                            htw.WriteEncodedText(Convert.ToString(SData));
                            htw.RenderEndTag();
                        }
                    }
                }

                htw.RenderEndTag();
                break;

            case "L":     //Checkbox
                if (VType == "EDIT" || VType == "DELETE")
                {
                    htw.AddAttribute("value", Convert.ToString(Data.GetType().GetProperty(form.Fld).GetValue(Data)));
                }
                if (VType == "DELETE")
                {
                    htw.AddAttribute("readonly", "readonly");
                }
                htw.AddAttribute("type", "checkbox");
                if (form.AllowBlank == true)
                {
                    htw.AddAttribute("required", "true");
                }
                htw.RenderBeginTag(HtmlTextWriterTag.Input);
                break;

            default:
                htw.RenderBeginTag(HtmlTextWriterTag.Unknown);
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// Generate Detail View of selected ViewName & OptionId
        /// </summary>
        /// <param name="DHead">TfatDesignHeader class object</param>
        /// <returns></returns>
        internal static string DetailView(TfatDesignHeader DHead)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter  sw = new StringWriter(sb);

            using (HtmlTextWriter htw = new HtmlTextWriter(sw))
            {
                htw.AddAttribute("href", DHead.AddUrl);
                htw.RenderBeginTag(HtmlTextWriterTag.A);
                htw.WriteEncodedText("Create New");
                htw.RenderEndTag();

                htw.RenderBeginTag(HtmlTextWriterTag.Br);

                //Begin Table
                htw.RenderBeginTag(HtmlTextWriterTag.Table);
                int i = 0;

                string   col    = "TOUCHVALUE EnteredBy LastUpdateDate AUTHORISE AUTHIDS HWSERIAL HWSERIAL2";
                string[] Tables = DHead.TableName.Split(new char[] { '^' });
                foreach (var DtTr in CoreCommon.GetTableData(Tables.FirstOrDefault()))
                {
                    htw.RenderBeginTag(HtmlTextWriterTag.Tr);
                    if (i == 0)
                    {
                        htw.RenderBeginTag(HtmlTextWriterTag.Td);
                        htw.WriteEncodedText("Edit Action");
                        htw.RenderEndTag();
                        htw.RenderBeginTag(HtmlTextWriterTag.Td);
                        htw.WriteEncodedText("Delete Action");
                        htw.RenderEndTag();

                        foreach (var prop in DtTr.GetType().GetProperties())
                        {
                            if (!prop.PropertyType.IsGenericType && !prop.PropertyType.IsInterface && !col.ToUpper().Contains(prop.Name.ToUpper()))
                            {
                                htw.RenderBeginTag(HtmlTextWriterTag.Td);
                                htw.WriteEncodedText(prop.Name.ToString());
                                htw.RenderEndTag();
                            }
                        }
                        htw.RenderEndTag();
                        htw.RenderBeginTag(HtmlTextWriterTag.Tr);
                        i = 1;
                    }
                    string[] IDs = DHead.IDKey.Split(new char[] { '^' });
                    if (DHead.xEdit)
                    {
                        htw.RenderBeginTag(HtmlTextWriterTag.Td);
                        htw.AddAttribute("href", DHead.EditUrl + DtTr.GetType().GetProperty(IDs.FirstOrDefault()).GetValue(DtTr));
                        htw.RenderBeginTag(HtmlTextWriterTag.A);
                        htw.WriteEncodedText("Edit");
                        htw.RenderEndTag();
                        htw.RenderEndTag();
                    }

                    if (DHead.xDelete)
                    {
                        htw.RenderBeginTag(HtmlTextWriterTag.Td);
                        htw.AddAttribute("href", DHead.DeleteUrl + DtTr.GetType().GetProperty(IDs.FirstOrDefault()).GetValue(DtTr));
                        htw.RenderBeginTag(HtmlTextWriterTag.A);
                        htw.WriteEncodedText("Delete");
                        htw.RenderEndTag();
                        htw.RenderEndTag();
                    }

                    foreach (var prop in DtTr.GetType().GetProperties())
                    {
                        if (!prop.PropertyType.IsGenericType && !prop.PropertyType.IsInterface && !col.ToUpper().Contains(prop.Name.ToUpper()))
                        {
                            htw.RenderBeginTag(HtmlTextWriterTag.Td);
                            htw.WriteEncodedText(Convert.ToString(prop.GetValue(DtTr)));
                            htw.RenderEndTag();
                        }
                    }
                    htw.RenderEndTag();
                }

                //End Table
                htw.RenderEndTag();
            }

            return(ctx.TfatDesigns.ToList().First().TfatDesignContent.Replace("@DataHeader", DHead.OptionName).Replace("@DataFields", sb.ToString()));
        }
Пример #3
0
        /// <summary>
        /// GenerateView method use to create View from Data Driven View Engine.
        /// GenerateView method take parameter to generate View.
        /// </summary>
        /// <param name="DHead">TfatDesignHeader class object</param>
        /// <param name="TableNM">Optional Parameter Table NM asper Entity Framework</param>
        /// <param name="recordkey">Optional Parameter recordkey to fatch record from Table By defualt recordkey is "0"</param>
        /// <param name="viewType">Optional Parameter viewType to generate view using viewType parameter. By default viewType="ADD"</param>
        /// <returns>Return HTML string to render view</returns>
        internal static string GenerateView(TfatDesignHeader DHead, string TableNM = "", int recordkey = 0, string viewType = "ADD")
        {
            StringBuilder       sb        = new StringBuilder();
            StringWriter        sw        = new StringWriter(sb);
            int                 distCount = 0;
            IEnumerable <byte?> Section;

            using (HtmlTextWriter htw = new HtmlTextWriter(sw))
            {
                if (!string.IsNullOrEmpty(DHead.AddSubmitUrl) && viewType == "ADD")
                {
                    htw.AddAttribute("action", DHead.AddSubmitUrl);
                }
                else if (!string.IsNullOrEmpty(DHead.EditSubmitUrl) && viewType == "EDIT")
                {
                    htw.AddAttribute("action", DHead.EditSubmitUrl);
                }
                else if (!string.IsNullOrEmpty(DHead.DeleteSubmitUrl) && viewType == "DELETE")
                {
                    htw.AddAttribute("action", DHead.DeleteSubmitUrl);
                }

                htw.AddAttribute("method", "post");
                htw.RenderBeginTag(HtmlTextWriterTag.Form);
                //
                htw.RenderBeginTag(HtmlTextWriterTag.Div);
                object Data = null;
                if (viewType == "EDIT" || viewType == "DELETE")
                {
                    string[] IDs       = DHead.IDKey.Split(new char[] { '^' });
                    DbSet    TableData = CoreCommon.GetTableData(TableNM);
                    string   Query     = "SELECT * FROM [" + TableNM + "] WHERE " + IDs.FirstOrDefault() + " = @p0";
                    var      TempData  = TableData.SqlQuery(Query, recordkey).ToListAsync().Result.ToList();
                    Data = TempData.Last();
                }
                Section   = DHead.TfatDesignForms.OrderBy(s => Math.Abs(Convert.ToByte(s.Section))).Select(s => s.Section).Distinct();
                distCount = Section.Count();

                //Header Control
                if (Section.First() == 1)
                {
                    TfatCreateStructure(htw, Data, DHead, viewType, 1);
                }
                //Grid Control
                else if (Section.First() == 2)
                {
                    TfatGridStructure(htw);
                }
                //Footer Control
                else if (Section.First() == 3)
                {
                    TfatCreateStructure(htw, Data, DHead, viewType, 3);
                }
                //Grid Control
                if (distCount > 1)
                {
                    if (Section.Skip(1).First() == 2)
                    {
                        TfatGridStructure(htw);
                    }
                }
                //Footer Control
                if (distCount > 2)
                {
                    if (Section.Last() == 3)
                    {
                        TfatCreateStructure(htw, Data, DHead, viewType, 3);
                    }
                }
                //ADD, EDIT & DELETE Control
                if (Section.First() != 2)
                {
                    Tfat_CRUD_PanelStructure(htw, DHead, viewType);
                }
                htw.WriteEndTag("div");
            }
            string designContent = string.Empty;

            if (distCount > 1)
            {
                designContent = ctx.TfatDesigns.ToList().Last().TfatDesignContent.Replace("@DataHeader", DHead.OptionName).Replace("@DataFields", sb.ToString());
            }
            else
            {
                if (distCount == 1 && Section.First() == 2)
                {
                    designContent = ctx.TfatDesigns.ToList().Last().TfatDesignContent.Replace("@DataHeader", DHead.OptionName).Replace("@DataFields", sb.ToString());
                }
                else
                {
                    designContent = ctx.TfatDesigns.ToList().First().TfatDesignContent.Replace("@DataHeader", DHead.OptionName).Replace("@DataFields", sb.ToString());
                }
            }
            return(designContent);
        }