Ejemplo n.º 1
0
        public void DynamicGirdDeleteMaster(int DHeaderID, FormCollection frm, DataTable DtTbl)
        {
            TfatDesignHeader DHead = ctx.TfatDesignHeaders.First(h => h.HeaderRecordKey == DHeaderID);

            string TableIDKey = DHead.IDKey.Split('^').LastOrDefault();

            DataRow[] DtRow = DtTbl.Select(TableIDKey + "='" + frm[TableIDKey].ToString() + "'");

            DtTbl.Rows.Remove(DtRow[0]);
        }
Ejemplo n.º 2
0
        public FormCollection GetDBFormCollection(TfatDesignHeader DHead, FormCollection fc)
        {
            FormCollection fcoll = new FormCollection();

            foreach (string Name in fc.AllKeys)
            {
                string n = DHead.TfatDesignForms.Where(f => f.LabelCaption == Name).Select(f => f.Fld).ToList()[0].ToString();
                string v = fc[Name].ToString();
                fc.Add(n, v);
            }
            return(fcoll);
        }
Ejemplo n.º 3
0
        public void DynamicAddMaster(int DHeaderID, FormCollection frm)
        {
            TfatDesignHeader DHead = ctx.TfatDesignHeaders.First(h => h.HeaderRecordKey == DHeaderID);

            try
            {
                object[] Param    = new object[frm.Count + 8 - 1];
                string   SpString = string.Empty;
                SpString = "Tfat_Insert_" + DHead.TableName + " ";
                int i = 0;
                foreach (var fldname in frm)
                {
                    //if (!(DHead.IDKey).Equals(fldname))
                    //{
                    SpString += "@" + fldname.ToString() + " = " + "@" + fldname.ToString() + "1,";
                    Param[i]  = new SqlParameter(fldname.ToString() + "1", frm[fldname.ToString()]);
                    i++;
                    //}
                }

                SpString += "@EnteredBy = @EnteredBy1,";
                Param[i]  = new SqlParameter("EnteredBy1", "Admin");
                i++;
                SpString += "@AUTHORISE = @AUTHORISE1,";
                Param[i]  = new SqlParameter("AUTHORISE1", "Adm");
                i++;
                SpString += "@AUTHIDS = @AUTHIDS1,";
                Param[i]  = new SqlParameter("AUTHIDS1", "Admin");
                i++;
                SpString += "@HWSERIAL = @HWSERIAL1,";
                Param[i]  = new SqlParameter("HWSERIAL1", "WEB001");
                i++;
                SpString += "@HWSERIAL2 = @HWSERIAL21,";
                Param[i]  = new SqlParameter("HWSERIAL21", "WEB001");
                i++;
                SpString += "@LastUpdateDate = @LastUpdateDate1,";
                Param[i]  = new SqlParameter("LastUpdateDate1", DateTime.Now);
                i++;
                SpString += "@TOUCHVALUE = @TOUCHVALUE1,";
                Param[i]  = new SqlParameter("TOUCHVALUE1", DateTime.Now.ToString("ddmmyyyyHHMM"));

                i++;


                int result = ctx.Database.ExecuteSqlCommand(SpString.Substring(0, SpString.Length - 1), Param);
                ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message.ToString());
            }
        }
Ejemplo n.º 4
0
        private static void Tfat_CRUD_PanelStructure(HtmlTextWriter htw, TfatDesignHeader DHead, string viewType)
        {
            htw.RenderBeginTag(HtmlTextWriterTag.Div);
            // htw.AddStyleAttribute(HtmlTextWriterStyle.MarginLeft, "350px");
            //Begin Table (CRUD Panel)

            htw.AddAttribute("width", "100%");
            //  htw.AddAttribute(HtmlTextWriterAttribute.Width, "180px");
            htw.RenderBeginTag(HtmlTextWriterTag.Table);
            short?max    = DHead.TfatDesignForms.Max(f => f.Columns);
            int   maxcol = Convert.ToInt32(max) * 2;

            htw.RenderBeginTag(HtmlTextWriterTag.Tr);

            htw.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "center");
            htw.AddStyleAttribute(HtmlTextWriterStyle.FontSize, "10px");
            htw.AddStyleAttribute(HtmlTextWriterStyle.FontWeight, "Bold");
            htw.AddStyleAttribute(HtmlTextWriterStyle.VerticalAlign, "middle");
            htw.AddAttribute("colspan", maxcol.ToString());
            htw.RenderBeginTag(HtmlTextWriterTag.Td);
            htw.AddAttribute("type", "Submit");
            if (DHead.xAdd == true && "ADD".Equals(viewType) == true)
            {
                htw.AddAttribute("value", DHead.AddName);
            }
            else if (DHead.xEdit == true && "EDIT".Equals(viewType) == true)
            {
                htw.AddAttribute("value", DHead.EditName);
            }
            else if (DHead.xDelete == true && "DELETE".Equals(viewType) == true)
            {
                htw.AddAttribute("value", DHead.DeleteName);
            }
            htw.RenderBeginTag(HtmlTextWriterTag.Input);
            htw.RenderEndTag();

            htw.AddAttribute("type", "reset");
            htw.AddAttribute("value", "Cancel");
            htw.RenderBeginTag(HtmlTextWriterTag.Input);
            htw.RenderEndTag();
            htw.AddAttribute("type", "button");
            htw.AddAttribute("value", "Back");
            htw.AddAttribute("onclick", "parent.history.back(); return false;");
            htw.RenderBeginTag(HtmlTextWriterTag.Input);
            htw.RenderEndTag();
            htw.WriteEndTag("td");

            //End Table (CRUD Panel);
            htw.WriteEndTag("tr");
            htw.WriteEndTag("table");
            htw.WriteEndTag("div");
        }
Ejemplo n.º 5
0
        public void DynamicGirdAddMaster(int DHeaderID, FormCollection frm, DataTable DtTbl)
        {
            TfatDesignHeader DHead = ctx.TfatDesignHeaders.First(h => h.HeaderRecordKey == DHeaderID);

            string  TableIDKey = DHead.IDKey.Split('^').LastOrDefault();
            DataRow Drow       = DtTbl.NewRow();

            foreach (var fldname in frm)
            {
                Drow[DHead.TfatDesignForms.Where(f => f.TabName.ToUpper() == "GRID" && f.Section == 2 && f.LabelCaption.Equals(fldname.ToString())).First().Fld] = frm[fldname.ToString()];
            }

            DtTbl.Rows.Add(Drow);
        }
Ejemplo n.º 6
0
        public void DynamicEditMaster(int DHeaderID, FormCollection frm)
        {
            TfatDesignHeader DHead = ctx.TfatDesignHeaders.First(h => h.HeaderRecordKey == DHeaderID);

            object[] Param    = new object[frm.Count + 7];
            string   SpString = string.Empty;

            SpString = "Tfat_Update_" + DHead.TableName + " ";
            int i = 0;

            foreach (var fldname in frm)
            {
                SpString += "@" + fldname.ToString() + " = " + "@" + fldname.ToString() + "1,";
                Param[i]  = new SqlParameter(fldname.ToString() + "1", frm[fldname.ToString()]);
                i++;
            }

            SpString += "@RecordKey = @RecordKey+1,";
            Param[i]  = new SqlParameter("RecordKey", "1");
            i++;
            SpString += "@EnteredBy = @EnteredBy1,";
            Param[i]  = new SqlParameter("EnteredBy1", "Admin");
            i++;
            SpString += "@AUTHORISE = @AUTHORISE1,";
            Param[i]  = new SqlParameter("AUTHORISE1", "Adm");
            i++;
            SpString += "@AUTHIDS = @AUTHIDS1,";
            Param[i]  = new SqlParameter("AUTHIDS1", "Admin");
            i++;
            SpString += "@HWSERIAL = @HWSERIAL1,";
            Param[i]  = new SqlParameter("HWSERIAL1", "WEB001");
            i++;
            SpString += "@HWSERIAL2 = @HWSERIAL21,";
            Param[i]  = new SqlParameter("HWSERIAL21", "WEB001");
            i++;
            SpString += "@LastUpdateDate = @LastUpdateDate1,";
            Param[i]  = new SqlParameter("LastUpdateDate1", DateTime.Now);
            i++;
            SpString += "@TOUCHVALUE = @TOUCHVALUE1,";
            Param[i]  = new SqlParameter("TOUCHVALUE1", DateTime.Now.ToString("ddmmyyyyHHMM"));

            int result = ctx.Database.ExecuteSqlCommand(SpString.Substring(0, SpString.Length - 1), Param);

            ctx.SaveChanges();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// GridView method usefull for to generate direct CRUD functionality on View
        /// </summary>
        /// <param name="DHeader">TfatDesignHeader class object</param>
        /// <returns>Send HTML Scirpt string to render View</returns>
        internal static string GridView(TfatDesignHeader DHeader)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter  sw = new StringWriter(sb);

            using (HtmlTextWriter htw = new HtmlTextWriter(sw))
            {
                htw.AddAttribute(HtmlTextWriterAttribute.Class, "scroll");
                htw.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
                htw.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
                htw.AddAttribute(HtmlTextWriterAttribute.Id, "list");
                htw.RenderBeginTag(HtmlTextWriterTag.Table);
                htw.RenderEndTag();
                htw.AddAttribute(HtmlTextWriterAttribute.Class, "scroll");
                htw.AddAttribute(HtmlTextWriterAttribute.Style, "text-align: center;");
                htw.AddAttribute(HtmlTextWriterAttribute.Id, "pager");
                htw.RenderBeginTag(HtmlTextWriterTag.Div);
                htw.RenderEndTag();
            }
            return(ctx.TfatDesigns.ToList().Last().TfatDesignContent.Replace("@DataHeader", DHeader.OptionName).Replace("@DataFields", sb.ToString()));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Using Render method Data Driven View Engine generate our View from Database.
        /// In Controller last optional parameter is use here to generate view.
        /// e.g. If your URL like "/Dynamic/Master/City/City/Add" then using "Add" View generate.
        /// </summary>
        /// <param name="vc"></param>
        /// <param name="tw"></param>
        public void Render(ViewContext vc, TextWriter tw)
        {
            string[]         url     = vc.HttpContext.Request.Path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            TfatDesignHeader DHead   = ctx.TfatDesignHeaders.First(h => h.OptionCode == this.ID);
            string           content = string.Empty;

            string[] Tables = DHead.TableName.Split(new char[] { '^' });
            switch (url.Last().ToUpper())
            {
            case "LIST":
                content = BuildView.DetailView(DHead);
                break;

            case "ADD":
                content = BuildView.GenerateView(DHead, viewType: "ADD");
                break;

            case "EDIT":
                content = BuildView.GenerateView(DHead, Tables.FirstOrDefault(), Convert.ToInt32(vc.HttpContext.Request.QueryString.GetValues("id").LastOrDefault()), "EDIT");
                break;

            case "DELETE":
                content = BuildView.GenerateView(DHead, Tables.FirstOrDefault(), Convert.ToInt32(vc.HttpContext.Request.QueryString.GetValues("id").LastOrDefault()), "DELETE");
                break;

            case "GRID":
                content = BuildView.GridView(DHead);
                break;

            default:
                content = "Page under construction";
                break;
            }

            tw.Write(content);
        }
Ejemplo n.º 9
0
        public void DynamicDeleteMaster(int DHeaderID, FormCollection frm)
        {
            TfatDesignHeader DHead = ctx.TfatDesignHeaders.First(h => h.HeaderRecordKey == DHeaderID);

            object[] Param    = new object[1];
            string   SpString = string.Empty;

            SpString = "Tfat_Delete_" + DHead.TableName + " ";
            int i = 0;

            foreach (var fldname in frm)
            {
                if ((DHead.IDKey).Equals(fldname))
                {
                    SpString += "@" + fldname.ToString() + " = " + "@" + fldname.ToString() + "1,";
                    Param[i]  = new SqlParameter(fldname.ToString() + "1", frm[fldname.ToString()]);
                    break;
                }
            }

            int result = ctx.Database.ExecuteSqlCommand(SpString.Substring(0, SpString.Length - 1), Param);

            ctx.SaveChanges();
        }
Ejemplo n.º 10
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()));
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Create View using TfatCreateStructure
        /// </summary>
        /// <param name="htw">Using HtmlTextWriter collect all html script which is usefull for View</param>
        /// <param name="Data">Data is use for Edit & Delete view to set value to appropriate control</param>
        /// <param name="DHead">TfatDesignHeader class object</param>
        /// <param name="viewType">viewType use to generate View</param>
        /// <param name="section">section has 3 Type in number
        /// 1. Hedaer (Which Control populate in Header)
        /// 2. Grid (Which Data & Control populate in Grid)
        /// 3. Footer (Which Control populate in Footer)</param>
        ///
        private static void TfatCreateStructure(HtmlTextWriter htw, object Data, TfatDesignHeader DHead, string viewType, byte section = 1)
        {
            //Begin Tab(Div)
            htw.AddAttribute("id", "section" + section);
            htw.RenderBeginTag(HtmlTextWriterTag.Div);
            htw.RenderBeginTag(HtmlTextWriterTag.Ul);
            int _tab = 1;

            foreach (var tab in DHead.TfatDesignForms.Where(t => t.Section == section).Select(t => t.TabName).Distinct())
            {
                htw.RenderBeginTag(HtmlTextWriterTag.Li);
                htw.AddAttribute("href", "#section" + section + "-" + _tab.ToString());
                htw.RenderBeginTag(HtmlTextWriterTag.A);
                htw.WriteEncodedText(string.IsNullOrEmpty(tab) ? "Default" : tab.Trim().ToString());
                htw.RenderEndTag();
                htw.RenderEndTag();
                _tab++;
            }
            htw.WriteEndTag("ul");
            short?ColMaxCount = DHead.TfatDesignForms.Max(f => f.Columns);
            int?  ColCount    = ColMaxCount * 2;
            int?  TRPercent   = 100 / ColCount;

            _tab = 1;
            foreach (var tab in DHead.TfatDesignForms.Where(t => t.Section == section).Select(t => t.TabName).Distinct())
            {
                //Begin Sub Div (Tab)
                htw.AddAttribute("id", "section" + section + "-" + _tab.ToString());
                htw.RenderBeginTag(HtmlTextWriterTag.Div);
                foreach (var group in DHead.TfatDesignForms.Where(g => g.TabName == tab && g.Section == section).Select(g => g.NewGroup).Distinct())
                {
                    // if condiftion for => group of control
                    if (!string.IsNullOrEmpty(group))
                    {
                        htw.WriteBeginTag("section>");
                        htw.RenderBeginTag(HtmlTextWriterTag.B);
                        htw.WriteEncodedText(group.Trim().ToString());
                        htw.RenderEndTag();
                        htw.WriteEndTag("section");
                        htw.RenderBeginTag(HtmlTextWriterTag.Hr);
                        htw.RenderBeginTag(HtmlTextWriterTag.Colgroup);
                        htw.AddStyleAttribute("width", "620px");
                        htw.AddStyleAttribute("Font-Size", "12px");
                        htw.AddStyleAttribute("font-family", "Tahoma");
                        // htw.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, "Red");
                    }
                    //Begin Table (Control)
                    htw.RenderBeginTag(HtmlTextWriterTag.Table);
                    foreach (var form in DHead.TfatDesignForms.Where(f => f.TabName == tab && f.Section == section && f.NewGroup == group).OrderBy(f => Math.Abs(Convert.ToDecimal(f.DisplayOrder))))
                    {
                        //Begin Tr
                        if (form.Columns == 1)
                        {
                            htw.RenderBeginTag(HtmlTextWriterTag.Tr);
                        }
                        //LabelCaption TD
                        htw.AddAttribute("style", "width:" + Convert.ToString(TRPercent) + "%;");
                        if (form.Visible == false)
                        {
                            htw.AddAttribute("style", "display:none;");
                        }
                        htw.RenderBeginTag(HtmlTextWriterTag.Td);
                        htw.WriteEncodedText(form.LabelCaption.ToString());
                        htw.RenderEndTag();
                        //Control TD
                        htw.AddAttribute("style", "width:" + Convert.ToString(TRPercent) + "%;");
                        htw.RenderBeginTag(HtmlTextWriterTag.Td);
                        htw.AddAttribute(HtmlTextWriterAttribute.Id, form.Fld);
                        htw.AddAttribute(HtmlTextWriterAttribute.Name, form.Fld);
                        if (form.Visible == false)
                        {
                            htw.AddAttribute("style", "display:none;");
                        }
                        if (DHead.IDKey.Equals(form.Fld) && viewType.Equals("EDIT" ?? "ADD"))
                        {
                            htw.AddAttribute("readonly", "readonly");
                        }
                        //Create Input Control
                        RenderControl(form, Data, htw, viewType);
                        htw.WriteEndTag("td");
                    }
                    //End Tr
                    htw.WriteEndTag("tr");
                    //End Table (Control)
                    htw.WriteEndTag("table");
                    htw.RenderBeginTag(HtmlTextWriterTag.Br);
                }
                //End Sub Div (Tab)
                htw.WriteEndTag("div");
                _tab++;
            }
            //End Tab(Div)
            htw.WriteEndTag("div");
        }
Ejemplo n.º 13
0
        public ActionResult Master(string id, FormCollection collection)
        {
            string[] DynamicMaster = id.Split('_');
            //int DHeaderID = int.Parse(DynamicMaster.First());
            string DHeaderID = DynamicMaster.First();
            string VType     = DynamicMaster.Last();
            List <FormCollection> frmcollecttion = new List <FormCollection>();

            //TfatDesignHeader DHead = ctx.TfatDesignHeaders.First(h => h.HeaderRecordKey == DHeaderID);
            TfatDesignHeader DHead = ctx.TfatDesignHeaders.First(h => h.OptionCode == DHeaderID);
            object           hdnData;

            try
            {
                if (collection.AllKeys.AsEnumerable().Single(k => k.Equals("hdn")).Equals("hdn"))
                {
                    hdnData = JsonConvert.DeserializeObject(collection["hdn"].ToString());
                    JArray a = JArray.Parse(hdnData.ToString());
                    collection.Remove("hdn");
                    foreach (JObject fld in a.Children <JObject>())
                    {
                        FormCollection fc = new FormCollection();
                        foreach (JProperty p in fld.Properties())
                        {
                            string n = DHead.TfatDesignForms.Where(f => f.LabelCaption == p.Name).Select(f => f.Fld).ToList()[0].ToString();
                            string v = (p.Value as JValue).Value.ToString();
                            fc.Add(n, v);
                        }
                        fc.Add(DHead.IDKey.Split('^').FirstOrDefault(), collection[DHead.IDKey.Split('^').FirstOrDefault()]);
                        frmcollecttion.Add(fc);
                    }
                }
            }
            catch { }
            string message = string.Empty;

            switch (VType.ToUpper())
            {
            case "ADD":
                foreach (string TableName in DHead.TableName.Split('^'))
                {
                    var discTab = DHead.TfatDesignForms.Where(f => f.Fle == TableName).Select(f => f.TabName).Distinct();

                    if (discTab.ToList().SequenceEqual(new string[] { "Grid" }))
                    {
                        foreach (FormCollection fc in frmcollecttion)
                        {
                            DynAdd.DynamicAddMaster(fc, TableName, DHead.IDKey.Split('^').LastOrDefault());
                        }
                    }
                    else
                    {
                        message = DynAdd.DynamicAddMaster(collection, TableName, DHead.IDKey.Split('^').FirstOrDefault());
                    }
                }
                break;

            case "EDIT":
                foreach (string TableName in DHead.TableName.Split('^'))
                {
                    var discTab = DHead.TfatDesignForms.Where(f => f.Fle == TableName).Select(f => f.TabName).Distinct();

                    if (discTab.ToList().SequenceEqual(new string[] { "Grid" }))
                    {
                        DbSet    Table       = CoreCommon.GetTableData(TableName);
                        string   RemoveID    = DHead.IDKey.Split('^').LastOrDefault();
                        string   IDKey       = DHead.IDKey.ToString();
                        string   Where       = IDKey.ToString().Replace("^", "=@p1").Replace(RemoveID, "");
                        var      QryResult   = Table.SqlQuery("SELECT * FROM [" + TableName + "] WHERE " + Where, new object[] { new SqlParameter("@p1", collection[DHead.IDKey.Split('^').FirstOrDefault()]) }).ToListAsync().Result;
                        string[] ExistedCode = new string[QryResult.Count];
                        int      i           = 0;
                        foreach (var CodeResult in QryResult)
                        {
                            dynamic IDValue = CodeResult.GetType().GetProperty(DHead.IDKey.Split('^').LastOrDefault().ToString()).GetValue(CodeResult);
                            ExistedCode[i] = IDValue.ToString();
                            i++;
                        }
                        string[] AddedCode = new string[frmcollecttion.Count];
                        i = 0;
                        foreach (FormCollection fc in frmcollecttion)
                        {
                            Where = DHead.IDKey.ToString().Replace("^", "=@p1 AND ") + "=@p2;";
                            var QryResult1 = Table.SqlQuery("SELECT * FROM [" + TableName + "] WHERE " + Where, new object[] { new SqlParameter("@p1", collection[DHead.IDKey.Split('^').FirstOrDefault()]), new SqlParameter("@p2", fc[DHead.IDKey.Split('^').LastOrDefault().ToString()]) }).ToListAsync().Result;
                            if (QryResult1.Count == 0)
                            {
                                DynAdd.DynamicAddMaster(fc, TableName, DHead.IDKey.Split('^').LastOrDefault());
                            }
                            else
                            {
                                DynEdit.DynamicEditMaster(fc, TableName);
                                AddedCode[i] = fc[DHead.IDKey.Split('^').LastOrDefault().ToString()].ToString();
                                i++;
                            }
                        }
                        var DeleteCode = ExistedCode.Except(AddedCode);
                        foreach (var DeleteingCode in DeleteCode)
                        {
                            FormCollection fc = new FormCollection();
                            fc.Add(DHead.IDKey.Split('^').LastOrDefault().ToString(), DeleteingCode.ToString());
                            DynDel.DynamicDeleteMaster(TableName, DHead.IDKey.Split('^').LastOrDefault().ToString(), fc);
                        }
                    }
                    else
                    {
                        DynEdit.DynamicEditMaster(collection, TableName);
                    }
                }
                //DynamicEdit.DynamicEditMaster(DHeaderID, collection);
                break;

            case "DELETE":
                foreach (string TableName in DHead.TableName.Split('^').Reverse())
                {
                    //DynamicDelete.DynamicDeleteMaster(DHeaderID, collection);
                    DynDel.DynamicDeleteMaster(TableName, DHead.IDKey.Split('^').FirstOrDefault().ToString(), collection);
                }
                break;
            }
            //ViewList/Index/City
            return(Redirect("/ViewList/Index/" + DHeaderID + "?msg=" + message));//+ "/" + DynamicMaster[1] + "/List");
        }