Ejemplo n.º 1
0
        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="saveForm"></param>
        /// <returns></returns>
        public JsonResult DeleFiles(FormCollection saveForm)
        {
            string fileRelIds = saveForm["delFileRelIds"] != null ? saveForm["delFileRelIds"] : "";

            InvokeResult        result   = new InvokeResult();
            FileOperationHelper opHelper = new FileOperationHelper();

            try
            {
                string[] fileRelArray;
                if (fileRelIds.Length > 0)
                {
                    fileRelArray = fileRelIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                    List <BsonValue> fileRelIdList = new List <BsonValue>();
                    foreach (var tempId in fileRelArray)
                    {
                        fileRelIdList.Add(tempId.Trim());
                    }

                    if (fileRelArray.Length > 0)
                    {
                        result = opHelper.DeleteFileByRelIdList(fileRelIdList);
                        if (result.Status == Status.Failed)
                        {
                            throw new Exception(result.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Status  = Status.Failed;
                result.Message = ex.Message;
            }

            return(Json(TypeConvert.InvokeResultToPageJson(result), JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public ActionResult SavePostInfo(FormCollection saveForm)
        {
            NLog.Logger  logger = NLog.LogManager.GetCurrentClassLogger();
            InvokeResult result = new InvokeResult();

            #region 构建数据
            var          formKeys = saveForm.AllKeys;
            string       tbName   = formKeys.Contains("tbName") ? saveForm["tbName"] : PageReq.GetForm("tbName");
            string       queryStr = formKeys.Contains("queryStr") ? saveForm["queryStr"] : PageReq.GetForm("queryStr");
            string       dataStr  = formKeys.Contains("dataStr") ? saveForm["dataStr"] : PageReq.GetForm("dataStr");
            TableRule    rule     = new TableRule(tbName);
            BsonDocument dataBson = new BsonDocument();

            bool columnNeedConvert = false;
            if (dataStr.Trim() == "")
            {
                if (saveForm.AllKeys.Contains("fileObjId"))
                {
                    columnNeedConvert = true;
                }
                foreach (var tempKey in saveForm.AllKeys)
                {
                    if (tempKey == "tbName" || tempKey == "queryStr" || tempKey.Contains("fileList[") || tempKey.Contains("param."))
                    {
                        continue;
                    }
                    //2016.1.25添加数据转换过滤,
                    //由于前端通用TableManage需要上传可能会内置tableName字段,如果表中页游tableName字段可能会冲突保存不了
                    //目前做法前段替换,后端转化COLUMNNEEDCONVERT_
                    var curFormValue  = saveForm[tempKey];
                    var curColumnName = tempKey;
                    if (columnNeedConvert && tempKey.Contains("COLUMNNEEDCONVERT_"))
                    {
                        curColumnName = curColumnName.Replace("COLUMNNEEDCONVERT_", string.Empty);
                    }
                    dataBson.Set(curColumnName, curFormValue);
                }
            }
            else
            {
                dataBson = TypeConvert.ParamStrToBsonDocument(dataStr);
            }
            #endregion

            #region 保存数据
            result = dataOp.Save(tbName, queryStr != "" ? TypeConvert.NativeQueryToQuery(queryStr) : Query.Null, dataBson);
            #endregion

            #region 文件上传
            int        primaryKey = 0;
            ColumnRule columnRule = rule.ColumnRules.Where(t => t.IsPrimary == true).FirstOrDefault();
            string     keyName    = columnRule != null ? columnRule.Name : "";
            if (!string.IsNullOrEmpty(queryStr))
            {
                var query     = TypeConvert.NativeQueryToQuery(queryStr);
                var recordDoc = dataOp.FindOneByQuery(tbName, query);
                saveForm["keyValue"] = result.BsonInfo.Text(keyName);
                if (recordDoc != null)
                {
                    primaryKey = recordDoc.Int(keyName);
                }
            }

            if (primaryKey == 0)//新建
            {
                if (saveForm["tableName"] != null)
                {
                    saveForm["keyValue"] = result.BsonInfo.Text(keyName);
                }
            }
            else//编辑
            {
                #region  除文件
                string delFileRelIds = saveForm["delFileRelIds"] != null ? saveForm["delFileRelIds"] : "";
                if (!string.IsNullOrEmpty(delFileRelIds))
                {
                    FileOperationHelper opHelper = new FileOperationHelper();
                    try
                    {
                        string[] fileArray;
                        if (delFileRelIds.Length > 0)
                        {
                            fileArray = delFileRelIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            if (fileArray.Length > 0)
                            {
                                var fileRelIdList = fileArray.Select(t => (BsonValue)t).ToList();
                                var result1       = opHelper.DeleteFileByRelIdList(fileRelIdList);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        result.Status  = Status.Failed;
                        result.Message = ex.Message;
                        return(Json(TypeConvert.InvokeResultToPageJson(result)));
                    }
                }
                #endregion

                saveForm["keyValue"] = primaryKey.ToString();
            }
            result.FileInfo = SaveMultipleUploadFiles(saveForm);
            #endregion

            return(Json(TypeConvert.InvokeResultToPageJson(result)));
        }