示例#1
0
        public IEnumerable <TMeasurement> GetAll()
        {
            DBTableAttribute dbTableAttribute =
                (DBTableAttribute)Attribute.GetCustomAttribute(typeof(BMeasurement), typeof(DBTableAttribute));
            TStorage q = new TStorage
            {
                Table = dbTableAttribute.Table
            };
            var storageItems = LoadList(q);

            List <TMeasurement> measurements = new List <TMeasurement>();

            foreach (var si in storageItems)
            {
                TMeasurement m = new TMeasurement
                {
                    TMeasurementId  = (int)(si.Fields[BMeasurement.KeyParm.Key]),
                    Text            = (string)(si.Fields[BMeasurement.TextParm.Key]),
                    Description     = (string)(si.Fields[BMeasurement.DescriptionParm.Key]),
                    PhotoClientPath = (string)(si.Fields[BMeasurement.PhotoClientPathParm.Key]),
                    PhotoServerPath = (string)(si.Fields[BMeasurement.PhotoServerPathParm.Key])
                };
                measurements.Add(m);
            }
            return(measurements);
        }
 public Status DeleteStorage(string productinfo)
 {
     this._logger.LogWarning("The server execute DeleteStorage Fuction  --" + DateTime.Now.ToString());
     using (SchoolCookHouseContext dbcontext = new SchoolCookHouseContext())
     {
         TStorage userInfo = new TStorage()
         {
             ProductInfo = productinfo
         };
         try
         {
             var a = dbcontext.TStorage.Where(a => true).ToList().Find(a => a.ProductInfo == productinfo);
             dbcontext.TStorage.Remove(a);
             dbcontext.SaveChanges();
             Status status = new Status()
             {
                 StatusCode = 200,
                 Message    = "删除成功",
                 ReturnTime = DateTime.Now
             };
             return(status);
         }
         catch (Exception ex)
         {
             this._logger.LogWarning("The server execute DeleteStorage Fuction  --" + ex.Message + DateTime.Now.ToString());
             Status status = new Status()
             {
                 StatusCode = 0,
                 Message    = "删除失败",
                 ReturnTime = DateTime.Now
             };
             return(status);
         }
     }
 }
示例#3
0
        public static IEnumerable <T> LoadObjectList <T>(Dictionary <string, object> filter = null) where T : TObject
        {
            DBTableAttribute dbTableAttribute =
                (DBTableAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(DBTableAttribute));

            TStorage tStorage = new TStorage
            {
                Fields = filter,
                Table  = dbTableAttribute.Table
            };

            TrackingServiceClient  tsc          = new TrackingServiceClient();
            IEnumerable <TStorage> tStorageList = tsc.LoadList(tStorage);

            List <T> result = new List <T>();

            foreach (TStorage s in tStorageList)
            {
                var ctor = typeof(T).GetConstructor(new Type[] { });
                var item = ctor.Invoke(new object[] { }) as T;
                item.SetKeyValuePairs(s.Fields);
                item.SetKeyValue(s.Fields[item.GetKeyField()]);
                result.Add(item);
            }

            return(result);
        }
示例#4
0
        public LoginModule()
        {
            var config = TinyfxCore.Configuration;

            _tinyfxPageRender = new TinyfxPageRender(config);

            Get("/login", _ =>
            {
                bool islogin = false;
                if (Context.CurrentUser != null && Context.CurrentUser.Identity != null && Context.CurrentUser.Identity.Name != null && Context.CurrentUser.Identity.Name.Length > 0)
                {
                    islogin = true;
                }
                return(Response.AsText(_tinyfxPageRender.RenderLogin("GET", islogin, false), "text/html"));
            });

            Post("/login", _ =>
            {
                DateTime _lastLoginFail = DateTime.MinValue;
                DateTime.TryParse(TStorage.GetInstance()["_last_login_fail"] + "", out _lastLoginFail);

                double tspan = (DateTime.Now - _lastLoginFail).TotalSeconds;

                if (tspan < TinyfxCore.Configuration.LoginRetryTimeSpanSeconds)
                {
                    return(Response.AsText(ResourceHelper.LoadStringResource("login.html").AsHtmlFromTemplate(new
                    {
                        Error = "拒绝登录,请" + (TinyfxCore.Configuration.LoginRetryTimeSpanSeconds - (int)tspan) + "秒后重试!"
                    }), "text/html"));
                }
                else
                {
                    string username = Request.Form.username;
                    string password = Request.Form.password;

                    LogHelper.WriteLog(LogHelper.LogType.INFO, "HTTP POST /login username="******",password="******"_POSTS"] = null;
                        return(this.LoginAndRedirect(uobj.Value, DateTime.Now.AddSeconds(config.AuthExpireSeconds)));
                    }
                    else
                    {
                        TStorage.GetInstance()["_last_login_fail"] = DateTime.Now;
                        return(Response.AsText(_tinyfxPageRender.RenderLogin("POST", false, false), "text/html"));
                    }
                }
            });

            Get("/logout", _ =>
            {
                TStorage.GetInstance()["_POSTS"] = null;
                return(this.LogoutAndRedirect("/login"));
            });
        }
示例#5
0
 public void EmptyPostsCache()
 {
     try
     {
         TStorage.GetInstance()["_POSTS"] = null;
     }
     catch (Exception ex)
     {
         LogHelper.WriteLog(LogHelper.LogType.ERROR, ex.Message, ex);
     }
 }
示例#6
0
        public static object InsertObject <T>(T obj) where T : TObject
        {
            DBTableAttribute dbTableAttribute =
                (DBTableAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(DBTableAttribute));

            TStorage tStorage = new TStorage
            {
                Fields  = obj.GetKeyValuePairs(),
                Table   = dbTableAttribute.Table,
                PKField = obj.GetKeyField()
            };

            TrackingServiceClient tsc = new TrackingServiceClient();

            return(tsc.Insert(tStorage));
        }
        public Status UpdateStorage(string conditionuserproductinfo, string productinfo, float price, DateTime storagetime, string remark)
        {
            this._logger.LogWarning("The server execute UpdateStorage Fuction  --" + DateTime.Now.ToString());
            using (SchoolCookHouseContext dbcontext = new SchoolCookHouseContext())
            {
                TStorage storage = new TStorage()
                {
                    ProductInfo = productinfo,
                    Price       = price,
                    StorageTime = storagetime,
                    Remark      = remark,
                };

                var ReadPeoples = dbcontext.TStorage.Where(a => true).ToList().Find(a => a.ProductInfo == conditionuserproductinfo);

                ReadPeoples.ProductInfo = storage.ProductInfo;
                ReadPeoples.Price       = storage.Price;
                ReadPeoples.StorageTime = storage.StorageTime;
                ReadPeoples.Remark      = storage.Remark;

                try
                {
                    dbcontext.Entry(ReadPeoples).State = EntityState.Modified;
                    dbcontext.SaveChanges();
                    Status status = new Status()
                    {
                        StatusCode = 200,
                        Message    = "修改成功",
                        ReturnTime = DateTime.Now
                    };
                    return(status);
                }
                catch (Exception ex)
                {
                    this._logger.LogWarning("The server execute UpdateStorage Fuction  --" + ex.Message + DateTime.Now.ToString());
                    Status status = new Status()
                    {
                        StatusCode = 0,
                        Message    = "修改失败",
                        ReturnTime = DateTime.Now
                    };
                    return(status);
                }
            }
        }
示例#8
0
        public static T LoadObject <T>(int id) where T : TObject
        {
            DBTableAttribute dbTableAttribute =
                (DBTableAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(DBTableAttribute));

            TStorage tStorage = new TStorage
            {
                ID    = id,
                Table = dbTableAttribute.Table
            };

            TrackingServiceClient tsc = new TrackingServiceClient();
            TStorage tObjStorage      = tsc.LoadDetails(tStorage);
            var      ctor             = typeof(T).GetConstructor(new Type[] { });
            var      result           = ctor.Invoke(new object[] { }) as T;

            result.SetKeyValuePairs(tObjStorage.Fields);

            return(result);
        }
示例#9
0
        public void Add(TMeasurement item)
        {
            DBTableAttribute dbTableAttribute =
                (DBTableAttribute)Attribute.GetCustomAttribute(typeof(BMeasurement), typeof(DBTableAttribute));

            TStorage tStorage = new TStorage
            {
                Table   = dbTableAttribute.Table,
                PKField = BMeasurement.KeyParm.Key,
                Fields  = new Dictionary <string, object>()
                {
                    { BMeasurement.TextParm.Key, item.Text },
                    { BMeasurement.DescriptionParm.Key, item.Description },
                    { BMeasurement.PhotoClientPathParm.Key, item.PhotoClientPath },
                    { BMeasurement.PhotoServerPathParm.Key, item.PhotoServerPath },
                }
            };

            Insert(tStorage);
        }
示例#10
0
        public static void DeleteObject <T>(T obj) where T : TObject
        {
            try
            {
                DBTableAttribute dbTableAttribute =
                    (DBTableAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(DBTableAttribute));

                TStorage tStorage = new TStorage
                {
                    ID      = Convert.ToInt32(obj.GetKeyValue()),
                    Table   = dbTableAttribute.Table,
                    PKField = obj.GetKeyField()
                };

                TrackingServiceClient tsc = new TrackingServiceClient();
                tsc.Delete(tStorage);
            }
            catch (Exception ex)
            {
            }
        }
示例#11
0
 public Status AddStorage(string productinfo, float price, DateTime storagetime, string remark)
 {
     this._logger.LogWarning("The server execute AddStorage Fuction  --" + DateTime.Now.ToString());
     using (SchoolCookHouseContext dbcontext = new SchoolCookHouseContext())
     {
         TStorage storage = new TStorage()
         {
             ProductInfo = productinfo,
             Price       = price,
             StorageTime = storagetime,
             Remark      = remark,
         };
         try
         {
             dbcontext.Add(storage);
             dbcontext.SaveChanges();
             Status status = new Status()
             {
                 StatusCode = 200,
                 Message    = "添加成功",
                 ReturnTime = DateTime.Now
             };
             return(status);
         }
         catch (Exception ex)
         {
             this._logger.LogWarning("The server execute AddStorage Fuction  --" + ex.Message + DateTime.Now.ToString());
             Status status = new Status()
             {
                 StatusCode = 0,
                 Message    = "添加失败",
                 ReturnTime = DateTime.Now
             };
             return(status);
         }
     }
 }