コード例 #1
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"));
        }
コード例 #2
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 "float":
                case "int":
                case "bit":
                    strColumnUpdate = strColumnUpdate + column.ColumnName + "=" + column.ColumnValue + ",";
                    break;

                default:
                    strColumnUpdate = strColumnUpdate + column.ColumnName + "=N'" + 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"));
        }