Exemplo n.º 1
0
        public ActionResult Viewer(int ID = 0)
        {
            using (Models.Planner2Entities db = new Models.Planner2Entities())
            {
                var item = db.DataViewers.Where(v => v.ID == ID).FirstOrDefault();
                var nd   = (Planner2.Models.User)Session[Planner2.Controllers.LoginAuth.NameSession];

                if (item != null && item.UserView != null && (item.UserView.Contains("*") || item.UserView.Contains(nd.StaffID)))
                {
                    string tableName = item.TableEdit;

                    const string listUrl   = "/TableEdittor/List?tablename={0}";
                    const string addUrl    = "/TableEdittor/add?tablename={0}";
                    const string updateUrl = "/TableEdittor/update?tablename={0}";
                    const string deleteUrl = "/TableEdittor/delete?tablename={0}";

                    ViewBag.title         += item.Name;
                    ViewBag.primaryKeyName = MasterTableDAL.GetPrimaryKey(tableName);
                    ViewBag.FieldData      = MasterTableDAL.GetJsonFields(item.QueryData, item.TableEdit);
                    ViewBag.ListUrl        = String.Format(listUrl, tableName);
                    ViewBag.AddUrl         = String.Format(addUrl, tableName);
                    ViewBag.UpdateUrl      = String.Format(updateUrl, tableName);
                    ViewBag.DeleteUrl      = String.Format(deleteUrl, tableName);
                    return(View());
                }
                return(View("KHONG CO QUYEN"));
            }
        }
Exemplo n.º 2
0
        public ActionResult Add(string tableName)
        {
            Dictionary <string, string> ColumnList           = MasterTableDAL.GetColumns(tableName);
            List <ColumnFieldValue>     columnFieldValueList = new List <ColumnFieldValue>();

            foreach (var item in ColumnList)
            {
                if (item.Key == ColumnList.FirstOrDefault().Key)
                {
                    continue;
                }
                foreach (string key in Request.Form.AllKeys)
                {
                    var newkey = key.Replace("values", "").Replace("[", "").Replace("]", "").ToLower();
                    if (newkey == item.Key.ToLower())
                    {
                        var columnFieldValue = new ColumnFieldValue();
                        columnFieldValue.ColumnName  = item.Key;
                        columnFieldValue.ColumnValue = Request.Form[key];
                        columnFieldValue.ColumnType  = item.Value;
                        columnFieldValueList.Add(columnFieldValue);
                    }
                }
            }

            //create column string
            string strColumns = String.Join(",", columnFieldValueList.Select(x => x.ColumnName));
            string strValues  = "N'" + String.Join("',N'", columnFieldValueList.Select(V => V.ColumnValue)) + "'";

            string jsonResult = MasterTableDAL.AddRecord(tableName, strColumns, strValues);

            return(JsonMax("OK"));
        }
Exemplo n.º 3
0
        public ActionResult List(string tableName)
        {
            var records = MasterTableDAL.GetListOfRecords(tableName);
            var json    = ToJson(records);

            return(JsonMax(json));
        }
Exemplo n.º 4
0
        public ActionResult Delete(string tableName)
        {
            string primaryKey = MasterTableDAL.GetPrimaryKey(tableName);

            MasterTableDAL.DeleteRecord(tableName, primaryKey, Request.Form["key"]);

            return(Content("{\"Result\":\"OK\"}", "application/json"));
        }
Exemplo n.º 5
0
 public ActionResult List(string tableName)
 {
     using (Models.Planner2Entities db = new Models.Planner2Entities())
     {
         var item    = db.DataViewers.Where(v => v.TableEdit == tableName).FirstOrDefault();
         var records = MasterTableDAL.GetListOfRecords(item.QueryData);
         var json    = ToJson(records);
         return(JsonMax(json));
     }
 }
Exemplo n.º 6
0
        public ActionResult Update(string tableName)
        {
            Dictionary <string, string> ColumnList           = MasterTableDAL.GetColumns(tableName);
            List <ColumnFieldValue>     columnFieldValueList = new List <ColumnFieldValue>();
            var primaryKeyName = MasterTableDAL.GetPrimaryKey(tableName);

            foreach (var item in ColumnList)
            {
                foreach (string key in Request.Form.AllKeys)
                {
                    var newkey = key.Replace("values", "").Replace("[", "").Replace("]", "").ToLower();
                    if (newkey == item.Key.ToLower() && newkey != primaryKeyName.ToLower())
                    {
                        var columnFieldValue = new ColumnFieldValue();
                        columnFieldValue.ColumnName  = item.Key;
                        columnFieldValue.ColumnValue = Request.Form[key];
                        columnFieldValue.ColumnType  = item.Value;
                        columnFieldValueList.Add(columnFieldValue);
                    }
                }
            }

            //create column string
            string strColumnUpdate = "";

            foreach (var column in columnFieldValueList)
            {
                switch (column.ColumnType)
                {
                case "System.Int64":
                case "System.Int32":
                case "System.Boolean":
                    strColumnUpdate = strColumnUpdate + column.ColumnName + "=" + column.ColumnValue + ",";
                    break;

                case "System.String":
                case "System.DateTime":
                    strColumnUpdate = strColumnUpdate + column.ColumnName + "='" + column.ColumnValue + "',";
                    break;
                }
            }
            strColumnUpdate = strColumnUpdate.TrimEnd(',');

            //audit fields
            strColumnUpdate = strColumnUpdate + " WHERE " + primaryKeyName + " = " + Request.Form["key"];
            MasterTableDAL.UpdateRecord(tableName, strColumnUpdate);
            return(Content("{\"Result\":\"OK\"}", "application/json"));
        }
Exemplo n.º 7
0
        // GET: Default
        public ActionResult Index()
        {
            const string listUrl   = "/default/List?tablename={0}";
            const string addUrl    = "/default/add?tablename={0}";
            const string updateUrl = "/default/update?tablename={0}";
            const string deleteUrl = "/default/delete?tablename={0}";
            string       tableName = "mstr_Country";

            ViewBag.primaryKeyName = MasterTableDAL.GetPrimaryKey(tableName);
            ViewBag.FieldData      = MasterTableDAL.GetJsonFields(tableName);
            ViewBag.ListUrl        = String.Format(listUrl, tableName);
            ViewBag.AddUrl         = String.Format(addUrl, tableName);
            ViewBag.UpdateUrl      = String.Format(updateUrl, tableName);
            ViewBag.DeleteUrl      = String.Format(deleteUrl, tableName);
            //
            return(View());
        }
Exemplo n.º 8
0
        public ActionResult Add()
        {
            string tableName = "";

            if (!String.IsNullOrEmpty(Request.QueryString["tableName"]))
            {
                tableName = Request.QueryString["tableName"];
            }
            //we will be receiving all values in form variables.
            Dictionary <string, string> ColumnList           = MasterTableDAL.GetColumns(tableName);
            List <ColumnFieldValue>     columnFieldValueList = new List <ColumnFieldValue>();

            foreach (var item in ColumnList)
            {
                if (item.Key == ColumnList.FirstOrDefault().Key)
                {
                    continue;
                }
                foreach (string key in Request.Form.AllKeys)
                {
                    if (key.Replace("values", "").Replace("[", "").Replace("]", "").ToLower() == item.Key.ToLower())
                    {
                        var columnFieldValue = new ColumnFieldValue();
                        columnFieldValue.ColumnName  = item.Key;
                        columnFieldValue.ColumnValue = Request.Form[key];
                        columnFieldValue.ColumnType  = item.Value;
                        columnFieldValueList.Add(columnFieldValue);
                    }
                }
            }

            //create column string
            string strColumns = String.Join(",", columnFieldValueList.Select(x => x.ColumnName));
            string strValues  = "'" + String.Join("',N'", columnFieldValueList.Select(V => V.ColumnValue)) + "'";

            string jsonResult = MasterTableDAL.AddRecord(tableName, strColumns, strValues);

            return(JsonMax("OK"));
        }