public SpendingViewModel()
 {
     if (DesignMode.DesignModeEnabled)
     {
         var current = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
         _model = new SpendingModel {
             DID = "1", TotalCost = 6456
         };
         _model.Spends.Add(new OneSpendItem
         {
             Date    = new DateDataModel(current.AddDays(-5)),
             Name    = "Comment 1",
             Sum     = 156,
             idClass = 0
         });
         _model.Spends.Add(new OneSpendItem
         {
             Date    = new DateDataModel(current.AddDays(-4)),
             Name    = "Comment 2",
             Sum     = 268,
             idClass = 1
         });
         _model.Spends.Add(new OneSpendItem
         {
             Date    = new DateDataModel(current.AddDays(-2)),
             Name    = "Comment 3",
             Sum     = 878,
             idClass = 2
         });
         _model.TotalCost = _model.Spends.Sum(o => o.Sum);
         Calc();
     }
 }
Beispiel #2
0
        public List <XmlModel> LoadData()
        {
            List <XmlModel> datas = new List <XmlModel>();
            XmlDocument     xDoc  = new XmlDocument();

            xDoc.Load(pathToXml);
            XmlElement xRoot = xDoc.DocumentElement;

            foreach (XmlNode xnode in xRoot)
            {
                //получаем data
                XmlModel data = new XmlModel();
                data.Notes     = new List <NoteModel>();
                data.Spendings = new List <SpendingModel>();
                // получаем атрибут date
                if (xnode.Attributes.Count > 0)
                {
                    XmlNode attr = xnode.Attributes.GetNamedItem("date");
                    if (attr != null)
                    {
                        data.Date = DateTime.Parse(attr.Value);
                    }
                }
                // обходим все дочерние узлы элемента spendings
                foreach (XmlNode childnode in xnode.ChildNodes)
                {
                    if (childnode.Name == "spending")
                    {
                        SpendingModel spending = new SpendingModel();
                        foreach (XmlNode child in childnode.ChildNodes)
                        {
                            if (child.Name == "amount")
                            {
                                spending.Message = child.Value;
                            }
                            if (child.Name == "message")
                            {
                                spending.Message = child.Value;
                            }
                        }
                        data.Spendings.Add(spending);
                    }
                    else
                    {
                        NoteModel note = new NoteModel();
                        foreach (XmlNode child in childnode.ChildNodes)
                        {
                            note.Message = child.Value;
                        }
                        data.Notes.Add(note);
                    }
                }
                datas.Add(data);
            }
            return(datas);
        }
Beispiel #3
0
 private async Task Split(string msg)
 {
     try
     {
         _model = JsonConvert.DeserializeObject <SpendingModel>(msg);
     }
     catch (Exception)
     {
     }
 }
 public ActionResult CreateSpendingModel(SpendingModel model)
 {
     if (!ModelState.IsValid)
     {
         throw new HttpException(400, "Invalid Submission");
     }
     using (var context = new DollaDollaContext())
     {
         context.Spendings.Add(model);
         context.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Beispiel #5
0
        private async Task <SpendingModel> GetModel(int indx)
        {
            var res = new SpendingModel();
            var st  = _current.AddMonths(indx);
            var end = _current.AddMonths(indx + 1);

            res.Spends.Clear();
            foreach (var el in BudgetHandler.Model.Spends.Where(o => o.Date.ToDate >= st && o.Date.ToDate < end))
            {
                res.Spends.Add(el);
            }
            res.TotalCost = res.Spends.Sum(o => o.Sum);
            return(res);
        }
 public JsonResult Delete(int spendID)
 {
     try
     {
         SpendingModel model = spendingBll.GetModel(spendID);
         if (model != null)
         {
             spendingBll.Delete(spendID);
         }
         else
         {
             return(Json(new { code = 500, msg = "parms is null" }));
         }
         return(Json(new { code = 200 }));
     }
     catch (Exception ex)
     {
         return(Json(new { code = 500, msg = ex.Message }));
     }
 }
        public JsonResult Update(SpendingViewModel model)
        {
            try
            {
                SpendingModel spendingModel = spendingBll.GetModel(model.SpendID);
                spendingModel.TaskID     = model.TaskID;
                spendingModel.Title      = model.Title;
                spendingModel.RecordDate = model.RecordDate;
                spendingModel.SpendHour  = model.SpendHour;
                spendingModel.CreatedBy  = model.CreatedBy;
                spendingModel.CreateTime = model.CreateTime;

                spendingBll.Update(spendingModel);
                return(Json(new { code = 200 }));
            }
            catch (Exception ex)
            {
                return(Json(new { code = 500, msg = ex.Message }));
            }
        }
Beispiel #8
0
        public SpendingModel DataRowToModel(DataRow row)
        {
            SpendingModel model = new SpendingModel();

            if (row == null)
            {
                return(model);
            }

            if (row["SpendID"] != null && row["SpendID"].ToString() != "")
            {
                model.SpendID = int.Parse(row["SpendID"].ToString());
            }
            if (row["TaskID"] != null && row["TaskID"].ToString() != "")
            {
                model.TaskID = int.Parse(row["TaskID"].ToString());
            }
            if (row["Title"] != null && row["Title"].ToString() != "")
            {
                model.Title = row["Title"].ToString();
            }
            if (row["RecordDate"] != null && row["RecordDate"].ToString() != "")
            {
                model.RecordDate = DateTime.Parse(row["RecordDate"].ToString());
            }
            if (row["SpendHour"] != null && row["SpendHour"].ToString() != "")
            {
                model.SpendHour = int.Parse(row["SpendHour"].ToString());
            }
            if (row["CreatedBy"] != null && row["CreatedBy"].ToString() != "")
            {
                model.CreatedBy = row["CreatedBy"].ToString();
            }
            if (row["CreateTime"] != null && row["CreateTime"].ToString() != "")
            {
                model.CreateTime = DateTime.Parse(row["CreateTime"].ToString());
            }

            return(model);
        }
Beispiel #9
0
        public int Insert(SpendingModel model)
        {
            string sql = "INSERT INTO [Spending]([TaskID],[Title],[RecordDate],[SpendHour],[CreatedBy],[CreateTime]) VALUES(@TaskID,@Title,@RecordDate,@SpendHour,@CreatedBy,@CreateTime)";

            SqlParameter[] parameters =
            {
                new SqlParameter("@TaskID",     SqlDbType.Int),
                new SqlParameter("@Title",      SqlDbType.NVarChar),
                new SqlParameter("@RecordDate", SqlDbType.Date),
                new SqlParameter("@SpendHour",  SqlDbType.Int),
                new SqlParameter("@CreatedBy",  SqlDbType.VarChar),
                new SqlParameter("@CreateTime", SqlDbType.DateTime),
            };
            parameters[0].Value = model.TaskID == null ? (object)DBNull.Value : model.TaskID;
            parameters[1].Value = model.Title == null ? (object)DBNull.Value : model.Title;
            parameters[2].Value = model.RecordDate == null ? (object)DBNull.Value : model.RecordDate;
            parameters[3].Value = model.SpendHour == null ? (object)DBNull.Value : model.SpendHour;
            parameters[4].Value = model.CreatedBy == null ? (object)DBNull.Value : model.CreatedBy;
            parameters[5].Value = model.CreateTime == null ? (object)DBNull.Value : model.CreateTime;

            return(DbHelperSQL.ExecuteSql(sql, parameters));
        }
Beispiel #10
0
        public int Update(SpendingModel model)
        {
            string sql = "UPDATE [Spending] SET [TaskID]=@TaskID,[Title]=@Title,[RecordDate]=@RecordDate,[SpendHour]=@SpendHour,[CreatedBy]=@CreatedBy,[CreateTime]=@CreateTime WHERE SpendID=@SpendID";

            SqlParameter[] parameters =
            {
                new SqlParameter("@SpendID",    SqlDbType.Int),
                new SqlParameter("@TaskID",     SqlDbType.Int),
                new SqlParameter("@Title",      SqlDbType.NVarChar),
                new SqlParameter("@RecordDate", SqlDbType.Date),
                new SqlParameter("@SpendHour",  SqlDbType.Int),
                new SqlParameter("@CreatedBy",  SqlDbType.VarChar),
                new SqlParameter("@CreateTime", SqlDbType.DateTime),
            };
            parameters[0].Value = model.SpendID;
            parameters[1].Value = model.TaskID == null ? (object)DBNull.Value : model.TaskID;
            parameters[2].Value = model.Title == null ? (object)DBNull.Value : model.Title;
            parameters[3].Value = model.RecordDate == null ? (object)DBNull.Value : model.RecordDate;
            parameters[4].Value = model.SpendHour == null ? (object)DBNull.Value : model.SpendHour;
            parameters[5].Value = model.CreatedBy == null ? (object)DBNull.Value : model.CreatedBy;
            parameters[6].Value = model.CreateTime == null ? (object)DBNull.Value : model.CreateTime;

            return(DbHelperSQL.ExecuteSql(sql, parameters));
        }
Beispiel #11
0
 public int Update(SpendingModel model)
 {
     return(dal.Update(model));
 }
Beispiel #12
0
 public int Insert(SpendingModel model)
 {
     return(dal.Insert(model));
 }
Beispiel #13
0
 public void Update(SpendingModel model)
 {
     _model = model;
     Calc();
 }
Beispiel #14
0
 public SpendingViewModel(SpendingModel model)
 {
     Update(model);
 }
Beispiel #15
0
 public BudgetItemViewModel(DateTime date, SpendingModel model)
 {
     Date       = date;
     Model      = model;
     _viewModel = new SpendingViewModel(model);
 }
Beispiel #16
0
        private async Task UpdateSourceAsync()
        {
            #region DesignMode

            if (DesignMode.DesignModeEnabled)
            {
                _model = new SpendingModel {
                    DID = "1", TotalCost = 6456
                };
                _model.Spends.Add(new OneSpendItem
                {
                    Date    = new DateDataModel(_current.AddDays(-35)),
                    Name    = "Comment 1",
                    Sum     = 156,
                    idClass = 0
                });
                _model.Spends.Add(new OneSpendItem
                {
                    Date    = new DateDataModel(_current.AddDays(-34)),
                    Name    = "Comment 2",
                    Sum     = 268,
                    idClass = 1
                });
                _model.Spends.Add(new OneSpendItem
                {
                    Date    = new DateDataModel(_current.AddDays(-35)),
                    Name    = "Comment 3",
                    Sum     = 878,
                    idClass = 2
                });
                _model.Spends.Add(new OneSpendItem
                {
                    Date    = new DateDataModel(_current.AddDays(-5)),
                    Name    = "Comment 4",
                    Sum     = 658,
                    idClass = 3
                });
                _model.Spends.Add(new OneSpendItem
                {
                    Date    = new DateDataModel(_current.AddDays(-1)),
                    Name    = "Comment 5",
                    Sum     = 984,
                    idClass = 4
                });
                _model.Spends.Add(new OneSpendItem
                {
                    Date    = new DateDataModel(_current.AddDays(-65)),
                    Name    = "Comment 6",
                    Sum     = 741,
                    idClass = 2
                });
            }

            #endregion

            var res = await TcpConnection.Send("CA");

            res = await TcpConnection.Send("CB" + CarId);

            if (!string.IsNullOrEmpty(res.Msg))
            {
                await Split(res.Msg);
            }
        }