コード例 #1
0
ファイル: TableHandle.cs プロジェクト: 316729240/M5
        ColumnConfig GetConfig(double id)
        {
            bool          inherit = false;
            double        classId = 0, moduleId = 0;
            string        parentId = "";
            ColumnConfig  config   = new ColumnConfig();
            SqlDataReader rs       = Sql.ExecuteReader("select thumbnailWidth,thumbnailHeight,thumbnailForce,saveRemoteImages,inherit,classId,parentId,moduleId,titleRepeat,watermark from class where id=@id", new SqlParameter[] {
                new SqlParameter("id", id)
            });

            if (rs.Read())
            {
                inherit              = rs.GetInt32(4) == 1;
                config.picForce      = rs.GetInt32(2) == 1;
                config.picSave       = rs.GetInt32(3) == 1;
                config.picWidth      = rs.GetInt32(0);
                config.picHeight     = rs.GetInt32(1);
                classId              = rs.GetDouble(5);
                parentId             = rs.GetString(6);
                moduleId             = rs.GetDouble(7);
                config.titleRepeat   = (rs.IsDBNull(8) || rs.GetInt32(8) == 1);
                config.isRoot        = rs.GetDouble(5) == 7;
                config.isColumn      = rs.GetDouble(5) != 7;
                config.isModule      = false;
                config.pId           = id;
                config.watermarkFlag = rs.IsDBNull(9) || rs.GetInt32(9) == 1;
            }
            rs.Close();
            if (inherit)
            {
                string sql = "";
                if (classId == 7)
                {
                    rs = Sql.ExecuteReader("select thumbnailWidth,thumbnailHeight,thumbnailForce,saveRemoteImages,titleRepeat,watermark from module where id=@moduleId", new SqlParameter[] { new SqlParameter("moduleId", moduleId) });
                    if (rs.Read())
                    {
                        config.picForce      = rs.GetInt32(2) == 1;
                        config.picSave       = rs.GetInt32(3) == 1;
                        config.picWidth      = rs.GetInt32(0);
                        config.picHeight     = rs.GetInt32(1);
                        config.titleRepeat   = (rs.IsDBNull(4) || rs.GetInt32(4) == 1);
                        config.isModule      = true;
                        config.isRoot        = false;
                        config.isColumn      = false;
                        config.pId           = moduleId;
                        config.watermarkFlag = rs.IsDBNull(5) || rs.GetInt32(5) == 1;
                    }
                    rs.Close();
                }
                else
                {
                    sql = "select thumbnailWidth,thumbnailHeight,thumbnailForce,saveRemoteImages,titleRepeat,classId,childId,id,watermark from class where id in (" + parentId + ")  and inherit=0  order by layer desc ";
                    bool flag = false;
                    rs = Sql.ExecuteReader(sql);
                    if (rs.Read())
                    {
                        flag                 = true;
                        config.picForce      = rs.GetInt32(2) == 1;
                        config.picSave       = rs.GetInt32(3) == 1;
                        config.picWidth      = rs.GetInt32(0);
                        config.picHeight     = rs.GetInt32(1);
                        config.titleRepeat   = (rs.IsDBNull(4) || rs.GetInt32(4) == 1);
                        config.isRoot        = rs.GetDouble(5) == 7;
                        config.isColumn      = rs.GetDouble(5) != 7;
                        config.isModule      = false;
                        config.childId       = rs.GetString(6);
                        config.pId           = rs.GetDouble(7);
                        config.watermarkFlag = rs.IsDBNull(8) || rs.GetInt32(8) == 1;
                    }
                    rs.Close();
                    if (!flag)//从模块中查找配制
                    {
                        rs = Sql.ExecuteReader("select thumbnailWidth,thumbnailHeight,thumbnailForce,saveRemoteImages,titleRepeat,watermark from module where id=@moduleId", new SqlParameter[] { new SqlParameter("moduleId", moduleId) });
                        if (rs.Read())
                        {
                            config.picForce      = rs.GetInt32(2) == 1;
                            config.picSave       = rs.GetInt32(3) == 1;
                            config.picWidth      = rs.GetInt32(0);
                            config.picHeight     = rs.GetInt32(1);
                            config.titleRepeat   = (rs.IsDBNull(4) || rs.GetInt32(4) == 1);
                            config.isModule      = true;
                            config.isRoot        = false;
                            config.isColumn      = false;
                            config.pId           = moduleId;
                            config.watermarkFlag = rs.IsDBNull(5) || rs.GetInt32(5) == 1;
                        }
                        rs.Close();
                    }
                }
                return(config);
            }
            else
            {
                return(config);
            }
        }
コード例 #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);
        }