Пример #1
0
        ListViewItem AppendFundsLogToList(FundsLog item, int index = -1, bool byAdd = false)
        {
            ListView     listView     = listView1;
            ListViewItem listViewItem = null;

            if (index == -1)
            {
                if (byAdd)
                {
                    listViewItem = listView.Items.Insert(0, "id_" + item.Id, (listView.Items.Count + 1).ToString(), -1);
                }
                else
                {
                    listViewItem = listView.Items.Add("id_" + item.Id, (listView.Items.Count + 1).ToString(), -1);
                }
                listViewItem.SubItems.Add(item.ByDate.ToString("yyyy-MM-dd HH:mm"));
                listViewItem.SubItems.Add(item.ConsumeTypeName);
                listViewItem.SubItems.Add((item.IsOut ? -item.Money : item.Money).ToString("#,##0.00"));
                listViewItem.SubItems.Add(item.RelatedPerson);
                listViewItem.SubItems.Add(item.Comment);
                listViewItem.ForeColor = item.IsOut ? System.Drawing.Color.Red : System.Drawing.Color.Green;
            }
            else
            {
                listViewItem = listView.Items[index];
                listViewItem.SubItems[1].Text = item.ByDate.ToString("yyyy-MM-dd HH:mm");
                listViewItem.SubItems[2].Text = item.ConsumeTypeName;
                listViewItem.SubItems[3].Text = (item.IsOut ? -item.Money : item.Money).ToString("#,##0.00");
                listViewItem.SubItems[4].Text = item.RelatedPerson;
                listViewItem.SubItems[5].Text = item.Comment;
            }
            listViewItem.Tag = item;
            return(listViewItem);
        }
Пример #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            //Symbol.Forms.SelectedItem<Funds> fundsItem = (Symbol.Forms.SelectedItem<Funds>)cbFundsId.SelectedItem;
            Symbol.Forms.SelectedItem <ConsumeType> consumeTypeItem = (Symbol.Forms.SelectedItem <ConsumeType>)cbConsumeTypeId.SelectedItem;
            if (!UIValidtion.Create()
                .Next(cbConsumeTypeId, p => p.SelectedIndex != -1, p => consumeTypeItem == null ? "" : consumeTypeItem.Text, "消费方式", true)
                .Next(dtByDate, p => p.Value.HasValue, p => p.Value == null ? "" : p.Value.Value.ToString(p.Format), "日期")
                .Null(txtMoney, "金额")
                .NumDec(0)
                .Null(txtRelatedPerson, "相关人")
                .Len(1, 10)
                .Result)
            {
                return;
            }

            _model = new FundsLog()
            {
                UserId    = Program.CurrentUser.Id,
                ByDate    = dtByDate.Value.Value,
                ByDateDay = dtByDate.DayNumber,
                //FundsId = fundsItem.Value.Id,
                ConsumeTypeId = consumeTypeItem.Value.Id,
                Money         = Math.Abs(TypeExtensions.Convert <decimal>(txtMoney.Text, 0M)),
                //LastMoney= fundsItem.Value.Money,
                RelatedPerson = txtRelatedPerson.Text,
                Comment       = txtComment.Text,
                IsOut         = consumeTypeItem.Value.IsOut,
            };
            Program.DataStore.Add(_model);
            //Symbol.FastWrapper.Set(_model, "FundsName", fundsItem.Value.Name);
            FastWrapper.Set(_model, "ConsumeTypeName", consumeTypeItem.Value.Name);

            DialogResult = System.Windows.Forms.DialogResult.OK;
        }
Пример #3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            FundsLog item = ShowAdd(this);

            if (item == null)
            {
                return;
            }
            //AppendFundsLogToList(item, -1, true);
            Reload();
        }
Пример #4
0
        public static FundsLog ShowAdd(Form parentForm, FundsLog from = null)
        {
            using (AddFundsLogForm form = new AddFundsLogForm()) {
                form.Icon = parentForm.Icon;
                form.Font = parentForm.Font;

                if (form.ShowDialog(from) == System.Windows.Forms.DialogResult.Cancel)
                {
                    return(null);
                }
                return(form.Model);
            }
        }
Пример #5
0
        void OnCopyClick()
        {
            if (listView1.SelectedItems.Count == 0)
            {
                return;
            }
            FundsLog item = listView1.SelectedItems[0].Tag as FundsLog;

            if (ShowAdd(this, item) != null)
            {
                Reload();
            }
        }
        public void Add(FundsLog model)
        {
            using (var builder = _dataContext.CreateInsert("FundsLog")) {
                builder.Fields.SetValues(model);
                builder.Fields.Remove("Id");
                builder.Fields.Remove("ByDate");
                builder.Fields.Add("ByDateLong", model.ByDate.Ticks);

                model.Id = TypeExtensions.Convert <int>(_dataContext.ExecuteScalar(builder.CommandText, builder.Values), 0);
            }

            onFundsConsumeTypeDay(model);
        }
Пример #7
0
        void OnEditClick()
        {
            if (listView1.SelectedItems.Count == 0)
            {
                Symbol.Forms.ProgramHelper.ShowInformation("请任意选中一行!");
                return;
            }
            FundsLog item = listView1.SelectedItems[0].Tag as FundsLog;

            if (ShowEdit(this, item))
            {
                Reload();
            }
        }
Пример #8
0
 public DialogResult ShowDialog(FundsLog from)
 {
     if (from != null)
     {
         dtByDate.Value = from.ByDate;
         FillConsumeTypeList(from.ConsumeTypeId);
         txtMoney.Text         = from.Money.ToString("#,##0.##");
         txtRelatedPerson.Text = from.RelatedPerson;
         txtComment.Text       = from.Comment;
     }
     else
     {
         FillConsumeTypeList();
     }
     return(base.ShowDialog());
 }
        public void Edit(FundsLog model)
        {
            FundsLog original = FindFundsLog(model.Id);

            using (var builder = _dataContext.CreateUpdate("FundsLog")) {
                builder.Fields.SetValues(model);
                builder.Fields.Remove("Id");
                builder.Fields.Remove("UserId");
                builder.Fields.Remove("ConsumeTypeId");
                builder.Fields.Remove("ByDate");
                builder.Fields.Add("ByDateLong", model.ByDate.Ticks);
                _dataContext.ExecuteNonQuery(builder.CommandText + " where [id]=" + model.Id, builder.Values);
            }
            onFundsConsumeTypeDay(original, true);
            onFundsConsumeTypeDay(model, false);
        }
Пример #10
0
 public static bool ShowEdit(Form parentForm, FundsLog model)
 {
     if (model == null)
     {
         return(false);
     }
     using (EditFundsLogForm form = new EditFundsLogForm()) {
         form.Icon  = parentForm.Icon;
         form.Font  = parentForm.Font;
         form.Model = model;
         if (form.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
         {
             return(false);
         }
         return(true);
     }
 }
Пример #11
0
        void OnRemoveClick()
        {
            if (listView1.SelectedItems.Count == 0)
            {
                Symbol.Forms.ProgramHelper.ShowInformation("请任意选中一行!");
                return;
            }
            FundsLog item = listView1.SelectedItems[0].Tag as FundsLog;

            if (!Symbol.Forms.ProgramHelper.ShowQuestion("确认要删除此项吗?\n\n{0} {1} ¥{2}", item.ByDate.ToString("yyyy-MM-dd"), item.ConsumeTypeName, item.Money.ToString("#,##0.##")))
            {
                return;
            }
            Program.DataStore.Remove(item);
            listView1.SelectedItems[0].Remove();
            Reload();
        }
        void onFundsConsumeTypeDay(FundsLog model, bool undo = false)
        {
            int day = model.ByDateDay;
            //if (undo) {
            //    dataContext.ExecuteNonQuery("update [Funds] set [Money]=[Money]" + (model.IsOut ? "+" : "-") + "@p1 where [Id]=@p2", model.Money, model.FundsId);
            //} else {
            //    dataContext.ExecuteNonQuery("update [Funds] set [Money]=[Money]" + (model.IsOut ? "-" : "+") + "@p1 where [Id]=@p2", model.Money, model.FundsId);
            //}
            //FundsConsumeTypeDay item = dataContext.getFundsConsumeTypeDayByWhere("[FundsId]=@p1 and [ConsumeTypeId]=@p2 and [Day]=@p3", model.FundsId, model.ConsumeTypeId, model.ByDateDay);
            FundsConsumeTypeDay item = getFundsConsumeTypeDayByWhere("[ConsumeTypeId]=@p1 and [Day]=@p2", model.ConsumeTypeId, model.ByDateDay);

            if (item == null)
            {
                if (undo)
                {
                    return;
                }
                item = new FundsConsumeTypeDay()
                {
                    UserId = model.UserId,
                    //FundsId = model.FundsId,
                    ConsumeTypeId = model.ConsumeTypeId,
                    Day           = model.ByDateDay,
                    IsOut         = model.IsOut,
                    Money         = model.Money,
                };
                using (var builder = _dataContext.CreateInsert("FundsConsumeTypeDay")) {
                    builder.Fields.SetValues(item);
                    builder.Fields.Remove("Id");
                    _dataContext.ExecuteNonQuery(builder.CommandText, builder.Values);
                }
            }
            else
            {
                _dataContext.ExecuteNonQuery("update [FundsConsumeTypeDay] set [Money]=[Money]" + (undo ? "-" : "+") + "@p1 where [Id]=@p2", model.Money, item.Id);
            }
        }
 public void Remove(FundsLog model)
 {
     onFundsConsumeTypeDay(model, true);
     _dataContext.ExecuteNonQuery("delete from [FundsLog] where [Id]=@p1", model.Id);
 }