Exemplo n.º 1
0
        /// <summary>
        /// 将字符串转换为Files字段数据类型
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static Pictures Parse(string data)
        {
            if (data == "")
            {
                return(null);
            }
            Pictures       files = new Pictures();
            List <Picture> list  = new List <Picture>();

            if (data.Substring(0, 1) == "[")
            {
                list = data.ParseJson <List <Picture> >();
            }
            else if (data.Substring(0, 1) == "{")
            {
                Picture pic = data.ParseJson <Picture>();
                if (list == null)
                {
                    return(null);
                }
            }
            if (list == null)
            {
                return(null);
            }
            if (list.Count == 0)
            {
                try
                {
                    list.Add(data.ParseJson <Picture>());
                }
                catch { }
            }
            //
            foreach (Picture file in list)
            {
                if (file.isDel == 0)
                {
                    files.Add(file);
                }
                else
                {
                    #region  除无效文件
                    string path = Tools.MapPath("~" + file.path);
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }
                    string minpath = Tools.MapPath("~" + file.minPath);
                    if (System.IO.File.Exists(minpath))
                    {
                        System.IO.File.Delete(minpath);
                    }

                    #endregion
                }
            }
            if (files.Count > 0)
            {
                #region 设置默认值
                files.title   = files[0].title;
                files.path    = files[0].path;
                files.title   = files[0].title;
                files.isDel   = files[0].isDel;
                files.minPath = files[0].minPath;
                #endregion
            }
            return(files);
        }
Exemplo n.º 2
0
        public object Convert(object data, ConvertType convertType)
        {
            object value = null;

            switch (type)
            {
            case "String":
                value = data.ToStr();
                break;

            case "Number":
                value = data.ToInt();
                break;

            case "Double":
                value = data.ToDouble();
                break;

            case "DateTime":
                try
                {
                    value = DateTime.Parse(data.ToString());
                }
                catch
                {
                    return(null);
                }
                break;

            case "Files":
                FieldType.Files file = FieldType.Files.Parse(data.ToString());
                if (convertType == ConvertType.UserData)
                {
                    value = file;
                }
                else
                {
                    if (file != null)
                    {
                        value = file.ToJson();
                    }
                    else
                    {
                        value = "";
                    }
                }
                break;

            case "Pictures":
                FieldType.Pictures file2 = FieldType.Pictures.Parse(data.ToString());
                if (convertType == ConvertType.UserData)
                {
                    value = file2;
                }
                else
                {
                    if (file2 != null)
                    {
                        value = file2.ToJson();
                    }
                    else
                    {
                        value = "";
                    }
                }
                break;

            default:
                value = data;
                break;
            }
            return(value);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 将字符串转换为Files字段数据类型
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static Pictures Parse(string data)
        {
            Pictures       files = new Pictures();
            List <Picture> list  = new List <Picture>();

            try
            {
                list = data.ParseJson <List <Picture> >();
                if (list == null)
                {
                    return(null);
                }
            }catch { return(null); }
            if (list.Count == 0)
            {
                try {
                    list.Add(data.ParseJson <Picture>());
                } catch { }
            }
            //
            try
            {
                foreach (Picture file in list)
                {
                    if (file.isDel == 0)
                    {
                        files.Add(file);
                    }
                    else
                    {
                        #region  除无效文件
                        try
                        {
                            string path = HttpContext.Current.Server.MapPath("~" + file.path);
                            if (System.IO.File.Exists(path))
                            {
                                System.IO.File.Delete(path);
                            }
                            string minpath = HttpContext.Current.Server.MapPath("~" + file.minPath);
                            if (System.IO.File.Exists(minpath))
                            {
                                System.IO.File.Delete(minpath);
                            }
                        }
                        catch
                        {
                        }
                        #endregion
                    }
                }
            }
            catch
            {
            }
            if (files.Count > 0)
            {
                #region 设置默认值
                files.title   = files[0].title;
                files.path    = files[0].path;
                files.title   = files[0].title;
                files.isDel   = files[0].isDel;
                files.minPath = files[0].minPath;
                #endregion
            }
            return(files);
        }
Exemplo n.º 4
0
        /// <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")
                    {
                        FieldType.Pictures files = 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);
                            }
                            MWMS.Helper.Picture pic      = new Helper.Picture(files[i].path);
                            FileInfo            _newfile = pic.PictureSize(new FileInfo(files[i].path.Replace("." + kzm, "_min." + kzm)), config.picWidth, config.picHeight, 100, config.picForce);
                            string newfile = _newfile.FullName;
                            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);
        }