コード例 #1
0
        /// <summary>
        /// 获取数据地址
        /// </summary>
        /// <param name="columnId">数据所属栏目</param>
        /// <returns></returns>
        void ReplaceUrl(double columnId, double dataId)
        {
            MWMS.DAL.TableHandle        column       = new MWMS.DAL.TableHandle("Class");
            Dictionary <string, object> columnModel  = column.GetModel(columnId, "dirPath,dirName,rootId");
            Dictionary <string, object> channelModel = column.GetModel(columnModel["rootId"].ToDouble(), "dirName");
            StringBuilder url = new StringBuilder(BaseConfig.contentUrlTemplate);

            url.Replace("$id", "'+convert(varchar(20),convert(decimal(18,0),id))+'");
            url.Replace("$create.year", "'+convert(varchar(4),year(createdate))+'");
            url.Replace("$create.month", "'+right('00'+cast(month(createdate) as varchar),2)+'");
            url.Replace("$create.day", "'+right('00'+cast(day(createdate) as varchar),2)+'");
            url.Replace("$column.dirPath", columnModel["dirPath"].ToStr());
            url.Replace("$column.dirName", columnModel["dirName"].ToStr());
            url.Replace("$channel.dirName", channelModel["dirName"].ToStr());
            url.Replace(".$extension", "");
            string sql = "update mainTable set url='" + url + "' where id=@id";

            Helper.Sql.ExecuteNonQuery(sql, new SqlParameter[] { new SqlParameter("id", dataId) });
        }
コード例 #2
0
ファイル: TableHandle.cs プロジェクト: 316729240/M5
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="model">数据模型</param>
        /// <returns></returns>
        public double Save(Dictionary <string, object> model)
        {
            if (TableName == "")
            {
                throw new Exception("表名不能为空");
            }
            Dictionary <string, object> mainFields = new Dictionary <string, object>();
            Dictionary <string, object> dataFields = new Dictionary <string, object>();
            ColumnConfig config = null;

            if (model.ContainsKey("classId"))
            {
                config = GetConfig(model["classId"].ToDouble());
            }
            foreach (var field in model)
            {
                try {
                    Field  f     = Fields[field.Key];
                    object value = null;
                    if (f.type == "Pictures")
                    {
                        DAL.Datatype.FieldType.Pictures files = DAL.Datatype.FieldType.Pictures.Parse(field.Value.ToStr());
                        for (int i = 0; i < files.Count; i++)
                        {
                            string kzm = "";
                            if (files[i].path.LastIndexOf(".") > -1)
                            {
                                kzm = files[i].path.Substring(files[i].path.LastIndexOf(".") + 1);
                            }
                            string newfile = API.PictureSize(files[i].path, files[i].path.Replace("." + kzm, "_min." + kzm), config.picWidth, config.picHeight, 100, config.picForce);
                            if (newfile == "")
                            {
                                files[i].minPath = files[i].path;
                            }
                            else
                            {
                                files[i].minPath = newfile;
                            }
                        }
                        value = files.ToJson();
                    }
                    else
                    {
                        value = f.Convert(field.Value, Field.ConvertType.SqlData);
                    }
                    if (value != null)
                    {
                        if (f.isPublicField)
                        {
                            mainFields[field.Key] = value;
                        }
                        else
                        {
                            dataFields[field.Key] = value;
                        }
                    }
                }catch
                {
                }
            }
            if (mainFields.ContainsKey("id"))
            {
                dataFields["id"] = mainFields["id"];
            }

            StringBuilder fieldstr = new StringBuilder();

            MWMS.DAL.TableHandle t  = new MWMS.DAL.TableHandle("maintable");
            MWMS.DAL.TableHandle t1 = new MWMS.DAL.TableHandle(TableName);
            double id = 0;

            MWMS.DAL.TableHandle column = new MWMS.DAL.TableHandle("class");
            if (mainFields.ContainsKey("classId"))
            {
                Dictionary <string, object> columnModel = column.GetModel((double)mainFields["classId"], "rootId,moduleId");
                mainFields["rootId"]   = columnModel["rootId"];
                mainFields["moduleId"] = columnModel["moduleId"];
            }
            mainFields["datatypeId"] = DatatypeId;
            if (mainFields.ContainsKey("id") && mainFields["id"].ToDouble() > 0)
            {
                mainFields["updateDate"] = DateTime.Now;
                t.Update(mainFields);
                id = t1.Update(dataFields);
            }
            else
            {
                id = double.Parse(Helper.Tools.GetId());
                mainFields["id"]         = id;
                mainFields["auditorid"]  = 0;
                mainFields["updateDate"] = DateTime.Now;
                mainFields["createDate"] = DateTime.Now;
                dataFields["id"]         = id;
                t.Append(mainFields);
                id = t1.Append(dataFields);
            }
            if (mainFields.ContainsKey("classId"))
            {
                ReplaceUrl(mainFields["classId"].ToDouble(), mainFields["id"].ToDouble());
            }
            return(id);
        }