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(); } }
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); }
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")); }
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 })); } }
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); }
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)); }
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)); }
public int Update(SpendingModel model) { return(dal.Update(model)); }
public int Insert(SpendingModel model) { return(dal.Insert(model)); }
public void Update(SpendingModel model) { _model = model; Calc(); }
public SpendingViewModel(SpendingModel model) { Update(model); }
public BudgetItemViewModel(DateTime date, SpendingModel model) { Date = date; Model = model; _viewModel = new SpendingViewModel(model); }
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); } }