Example #1
0
        public ActionResult AddAutoTable()
        {
            DataTable table = new SqlTableRenderAutoDao().GetDataTable(new object[0], "cofTableRenderAuto_GetAllTableNotAdd");

            return(View(table));
        }
        public ActionResult LRender(string tableName = "", string titleForm = "", string targetArea = "", bool allowAU = false)
        {
            #region 'Init'
            List <object> dataParams = new List <object>();
            ListInfo      model      = new ListInfo();
            model.ActiveController = tableName.Replace("tbl", "");
            model.ActiveArea       = targetArea;
            model.Title            = titleForm;
            int currentPage = Request["currentPage"] != null?Convert.ToInt32(Request["currentPage"].ToString()) : 1;

            #endregion
            #region 'Load Field & Data Source'
            object[] parms = new object[] { "@tableName", tableName.Trim() };

            TableRenderAuto dataSource = new SqlTableRenderAutoDao().GetTableRenderAuto(tableName);
            #endregion

            dataParams.Add("@pageSize");
            dataParams.Add(dataSource != null ? dataSource.PageSize : 10);
            dataParams.Add("@pageNum");
            dataParams.Add(currentPage);
            DataTable fTable = new SqlFieldFilterAutoDao().GetDataTable(parms, "cofTableRenderAuto_GetAllColumnForFilter");
            if (fTable != null && fTable.Rows.Count > 0)
            {
                foreach (DataRow r in fTable.Rows)
                {
                    if (r["FieldType"] != null)
                    {
                        if (r["FieldType"].ToString() != "")
                        {
                            dataParams.Add(r["COLUMN_NAME"].ToString());
                            dataParams.Add(Request[r["COLUMN_NAME"].ToString()] != null ? Request[r["COLUMN_NAME"].ToString()] : "");
                        }
                    }
                }
            }
            #region 'Load List Data'
            if (dataSource != null && dataSource.ExtentionProperty["DataSource"] != null)
            {
                if (dataSource.ExtentionProperty["DataSource"].ToString() != "")
                {
                    model.DataInfo = new SqlFieldListAutoDao().GetDataTable(dataParams.ToArray(), dataSource.ExtentionProperty["DataSource"].ToString());
                    if (model.DataInfo != null)
                    {
                        model.DataInfo.Columns.Add("StatusDisplay", typeof(System.String));
                        if (model.DataInfo.Rows.Count > 0)
                        {
                            foreach (DataRow r in model.DataInfo.Rows)
                            {
                                for (int c = 0; c < model.DataInfo.Columns.Count; c++)
                                {
                                    if (model.DataInfo.Columns[c].ToString() == "Status" || model.DataInfo.Columns[c].ToString() == "status" || model.DataInfo.Columns[c].ToString() == "STATUS")
                                    {
                                        r["StatusDisplay"] = StatusMapping(Convert.ToInt32(r[c].ToString()), tableName);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            #region 'Paging'
            model.PagingInfo.CurrentPage = currentPage;
            if (model.DataInfo != null && model.DataInfo.Rows.Count > 0)
            {
                model.PagingInfo.TotalRecords = Convert.ToInt32(model.DataInfo.Rows[0]["TotalRec"]);
            }
            #endregion

            #region 'Load Resource'
            model.Resources = new SqlResourceListAutoDao().GetFilter(tableName);
            #endregion

            ViewBag.AllowAU = allowAU;
            return(View(model));
        }