Ejemplo n.º 1
0
        private async Task BuyPoint()
        {
            if (int.TryParse(txt_AddPoints.InputText, out var _addPoints) == false || _addPoints < 0)
            {
                FrmDialog.ShowDialog(this, "请输入正确的金额");
                return;
            }
            using (var db = new MemberCardContext())
            {
                var card = await db.Cards.FirstOrDefaultAsync(item => item.CardId == currentId && item.IsActive);

                if (card == null)
                {
                    FrmDialog.ShowDialog(this, "未找到该会员卡,可能不存在或者被锁定");
                    return;
                }
                int remainPoints = card.Points + _addPoints;
                card.Points = remainPoints;
                var record = new BuyRecord
                {
                    CardId     = card.CardId,
                    Record     = $"[积分消费]消费{_addPoints}元,积分{_addPoints}分,剩余总积分{remainPoints}",
                    RecordTime = DateTime.Now
                };
                db.BuyRecords.Add(record);
                await db.SaveChangesAsync();

                this.Close();
            }
        }
Ejemplo n.º 2
0
        private async void btn_Save_BtnClick(object sender, System.EventArgs e)
        {
            using (var db = new MemberCardContext())
            {
                var per = db.Configs.FirstOrDefault(item => item.Key == ConfigName.DeductPerCent.ToString());
                if (per == null)
                {
                    db.Configs.Add(new Models.Config()
                    {
                        Key = ConfigName.DeductPerCent.ToString(), Value = txt_DeductPer.InputText
                    });
                }
                else
                {
                    per.Value = txt_DeductPer.InputText;
                }
                var path = db.Configs.FirstOrDefault(item => item.Key == ConfigName.BackupPath.ToString());
                if (path == null)
                {
                    db.Configs.Add(new Models.Config()
                    {
                        Key = ConfigName.BackupPath.ToString(), Value = txt_Path.InputText
                    });
                }
                else
                {
                    path.Value = txt_Path.InputText;
                }
                await db.SaveChangesAsync();

                this.Close();
            }
        }
Ejemplo n.º 3
0
        private async void tsm_ChangeToPoint_Click(object sender, EventArgs e)
        {
            if (_currentCard == null)
            {
                return;
            }
            if (FrmDialog.ShowDialog(this, $"请确定切换为积分卡?", "提示", true) == DialogResult.OK)
            {
                using (var db = new MemberCardContext())
                {
                    var card = await db.Cards.FirstOrDefaultAsync(item => item.CardId == _currentCard.CardId);

                    if (card == null)
                    {
                        FrmDialog.ShowDialog(this, "未找到该会员卡");
                        return;
                    }
                    if (card.Money != 0)
                    {
                        FrmDialog.ShowDialog(this, "该会员卡还有余额,不允许转换");
                        return;
                    }
                    card.CardType = CardType.积分卡;
                    await db.SaveChangesAsync();
                }
                await Search();
            }
        }
Ejemplo n.º 4
0
        private async void btn_Remove_BtnClick(object sender, EventArgs e)
        {
            if (dgv_Gifts.SelectRow == null || dgv_Gifts.SelectRow.DataSource == null)
            {
                return;
            }
            var gift = dgv_Gifts.SelectRow.DataSource as Gift;

            if (gift == null)
            {
                return;
            }
            if (FrmDialog.ShowDialog(this, "确定删除吗", "提示", true) == DialogResult.OK)
            {
                using (var db = new MemberCardContext())
                {
                    var removeGift = await db.Gifts.FirstOrDefaultAsync(item => item.Id == gift.Id);

                    if (removeGift != null)
                    {
                        db.Gifts.Remove(removeGift);
                        await db.SaveChangesAsync();
                    }
                }
            }
            await RefreshGifts();
        }
Ejemplo n.º 5
0
        private async void btn_Ok_BtnClick(object sender, EventArgs e)
        {
            if (int.TryParse(txt_AddMoney.InputText, out var _addMoney) == false)
            {
                FrmDialog.ShowDialog(this, "请输入正确的金额");
                return;
            }
            if (FrmDialog.ShowDialog(this, $"请确定金额:{_addMoney}", "提示", true) == DialogResult.OK)
            {
                using (var db = new MemberCardContext())
                {
                    var card = await db.Cards.FirstOrDefaultAsync(item => item.CardId == _cardId && item.IsActive);

                    if (card == null)
                    {
                        FrmDialog.ShowDialog(this, "未找到该会员卡,可能不存在或者被锁定");
                        return;
                    }
                    var totalMoney = card.Money + _addMoney;
                    card.Money = totalMoney;
                    var record = new BuyRecord
                    {
                        CardId     = card.CardId,
                        Record     = $"[充值]充值{_addMoney}元,剩余余额{totalMoney}",
                        RecordTime = DateTime.Now
                    };
                    db.BuyRecords.Add(record);
                    await db.SaveChangesAsync();

                    this.Close();
                }
            }
        }
Ejemplo n.º 6
0
        private async Task RefreshGifts()
        {
            using (var db = new MemberCardContext())
            {
                var _gifts = await db.Gifts.ToListAsync();

                dgv_Gifts.DataSource = (object)_gifts;
            }
        }
Ejemplo n.º 7
0
 private void BuyForm_Load(object sender, EventArgs e)
 {
     using (var db = new MemberCardContext())
     {
         var per = db.Configs.FirstOrDefault(item => item.Key == ConfigName.DeductPerCent.ToString());
         if (per != null && int.TryParse(per.Value, out var perValue))
         {
             _deductPercent = perValue / (double)100;
         }
     }
 }
Ejemplo n.º 8
0
        private async Task Search()
        {
            var number = txt_Number.InputText;

            if (string.IsNullOrWhiteSpace(number))
            {
                ClearLabel();
                return;
            }
            using (var db = new MemberCardContext())
            {
                var cards = await db.Cards.Where(item => (item.CardId == number || item.PhoneNumber == number) && item.IsActive).ToListAsync();

                if (cards.Count() == 0)
                {
                    FrmDialog.ShowDialog(this, "未找到该会员卡,可能不存在或者被锁定");
                    ClearLabel();
                    return;
                }
                Card card;
                if (cards.Count() > 1)
                {
                    ClearLabel();
                    CardSelectForm cardSelectForm = new CardSelectForm(cards);
                    if (cardSelectForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        card = cards[cardSelectForm.SelectedIndex];
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    card = cards[0];
                }
                lbl_CardType.Text   = card.CardType.ToString();
                lbl_UserName.Text   = card.UserName;
                lbl_Points.Text     = card.Points.ToString();
                lbl_Money.Text      = card.Money.ToString();
                txt_Deduct.MaxValue = card.Money;
                remainMoney         = card.Money;
                cardType            = card.CardType;
                currentId           = card.CardId;
                ShowGroupBox(cardType);
            }
        }
        private async void btn_Ok_BtnClick(object sender, EventArgs e)
        {
            if (int.TryParse(txt_Points.InputText, out var _points) == false)
            {
                FrmDialog.ShowDialog(this, "请输入正确的积分");
                return;
            }
            if (FrmDialog.ShowDialog(this, $"请确定积分:{_points}", "提示", true) == DialogResult.OK)
            {
                using (var db = new MemberCardContext())
                {
                    var card = await db.Cards.FirstOrDefaultAsync(item => item.CardId == _cardId && item.IsActive);

                    if (card == null)
                    {
                        FrmDialog.ShowDialog(this, "未找到该会员卡,可能不存在或者被锁定");
                        return;
                    }
                    if (card.Points < _points)
                    {
                        FrmDialog.ShowDialog(this, $"积分不足,仅剩{card.Points}分");
                        return;
                    }
                    var remainPoints = card.Points - _points;
                    card.Points = remainPoints;
                    var remarks = "";
                    if (string.IsNullOrWhiteSpace(txt_Remarks.InputText))
                    {
                        remarks = "无";
                    }
                    else
                    {
                        remarks = txt_Remarks.InputText;
                    }
                    var record = new BuyRecord
                    {
                        CardId     = card.CardId,
                        Record     = $"[扣积分]扣积分{_points}分,备注:{remarks},剩余积分{remainPoints}",
                        RecordTime = DateTime.Now
                    };
                    db.BuyRecords.Add(record);
                    await db.SaveChangesAsync();

                    this.Close();
                }
            }
        }
Ejemplo n.º 10
0
 private async void btn_Input_BtnClick(object sender, EventArgs e)
 {
     using (OpenFileDialog dialog = new OpenFileDialog())
     {
         dialog.Multiselect = false;
         dialog.Title       = "请选择文件";
         dialog.Filter      = "Excel表格(*.xlsx)|*.xlsx";
         if (dialog.ShowDialog() == DialogResult.OK)
         {
             string file = dialog.FileName;
             try
             {
                 var workbook = ReoGridControl.CreateMemoryWorkbook();
                 workbook.Load(file);
                 var         sheet = workbook.Worksheets[0];
                 List <Card> cards = new List <Card>();
                 for (int i = 1; i < sheet.RowCount; i++)
                 {
                     if (string.IsNullOrEmpty(sheet[i, 0].GetString()) == false && int.TryParse(sheet[i, 4].GetString(), out var points))
                     {
                         var card = new Card()
                         {
                             CardId      = sheet[i, 0].GetString(),
                             PhoneNumber = sheet[i, 1].GetString(),
                             UserName    = sheet[i, 2].GetString(),
                             CardType    = CardType.积分卡,
                             Points      = points,
                             Money       = 0,
                             IsActive    = sheet[i, 6].GetString() == "正常" ? true : false
                         };
                         cards.Add(card);
                     }
                 }
                 using (var db = new MemberCardContext())
                 {
                     db.Cards.AddRange(cards);
                     await db.SaveChangesAsync();
                 }
                 FrmDialog.ShowDialog(this, "导入成功");
             }
             catch (Exception ex)
             {
                 FrmDialog.ShowDialog(this, ex.Message);
             }
         }
     }
 }
Ejemplo n.º 11
0
        //20201108新增修改会员信息
        private async void tsm_ChangeCardInfo_Click(object sender, EventArgs e)
        {
            if (_currentCard == null)
            {
                return;
            }
            FrmInputs frm = new FrmInputs("修改会员信息",
                                          new string[] { "手机号码", "会员姓名" },
                                          new Dictionary <string, HZH_Controls.TextInputType>()
            {
                { "手机号码", HZH_Controls.TextInputType.NotControl }, { "会员姓名", HZH_Controls.TextInputType.NotControl }
            },
                                          new Dictionary <string, string>()
            {
            },
                                          new Dictionary <string, KeyBoardType>()
            {
            },
                                          new List <string>()
            {
                "礼物名称", "礼物分值"
            },
                                          new Dictionary <string, string>()
            {
                { "手机号码", _currentCard.PhoneNumber }, { "会员姓名", _currentCard.UserName }
            });

            if (frm.ShowDialog(this) == DialogResult.OK)
            {
                var phoneNumber = frm.Values[0];
                var userName    = frm.Values[1];
                using (var db = new MemberCardContext())
                {
                    var card = await db.Cards.FirstOrDefaultAsync(item => item.CardId == _currentCard.CardId);

                    if (card == null)
                    {
                        FrmDialog.ShowDialog(this, "未找到该会员卡");
                        return;
                    }
                    card.PhoneNumber = phoneNumber;
                    card.UserName    = userName;
                    await db.SaveChangesAsync();
                }
                await Search();
            }
        }
Ejemplo n.º 12
0
        private async Task RefreshGifts()
        {
            using (var db = new MemberCardContext())
            {
                _gifts = await db.Gifts.ToListAsync();
            }
            List <KeyValuePair <string, string> > lstCom = new List <KeyValuePair <string, string> >();

            for (int i = 0; i < _gifts.Count; i++)
            {
                lstCom.Add(new KeyValuePair <string, string>(i.ToString(), _gifts[i].GiftName + " " + _gifts[i].Points + "分"));
            }
            cbx_Gifts.Source = lstCom;
            if (lstCom.Count > 0)
            {
                cbx_Gifts.SelectedIndex = 0;
            }
        }
Ejemplo n.º 13
0
        private async Task Search()
        {
            var number = txt_Number.InputText;

            using (var db = new MemberCardContext())
            {
                _cards = new List <Card>();
                if (string.IsNullOrWhiteSpace(number))
                {
                    _cards = await db.Cards.ToListAsync();
                }
                else
                {
                    _cards = await db.Cards.Where(item => item.CardId == number || item.PhoneNumber == number).ToListAsync();
                }
                pageControl.DataSource = _cards.Select(item => (object)item).ToList();
                lbl_Total.Text         = $"共{_cards.Count}条数据";
            }
        }
Ejemplo n.º 14
0
        private async void btn_Ok_BtnClickAsync(object sender, EventArgs e)
        {
            var index = cbx_Gifts.SelectedIndex;

            if (index < 0 || index >= _gifts.Count)
            {
                FrmDialog.ShowDialog(this, "请先选择礼物");
                return;
            }
            var gift = _gifts[index];

            using (var db = new MemberCardContext())
            {
                var card = await db.Cards.FirstOrDefaultAsync(item => item.CardId == _cardId && item.IsActive);

                if (card == null)
                {
                    FrmDialog.ShowDialog(this, "未找到该会员卡,可能不存在或者被锁定");
                    return;
                }
                if (card.Points < gift.Points)
                {
                    FrmDialog.ShowDialog(this, $"积分不足,仅剩{card.Points}分");
                    return;
                }
                if (FrmDialog.ShowDialog(this, $"是否兑换礼物:{gift.GiftName}", "提示", true) == DialogResult.OK)
                {
                    var remainPoints = card.Points - gift.Points;
                    card.Points = remainPoints;
                    var record = new BuyRecord
                    {
                        CardId     = card.CardId,
                        Record     = $"[积分兑换]兑换礼物{gift.GiftName},扣积分{gift.Points}分,剩余积分{remainPoints}",
                        RecordTime = DateTime.Now
                    };
                    db.BuyRecords.Add(record);
                    await db.SaveChangesAsync();

                    this.Close();
                }
            }
        }
Ejemplo n.º 15
0
        private async void btn_Add_BtnClick(object sender, EventArgs e)
        {
            FrmInputs frm = new FrmInputs("添加礼物",
                                          new string[] { "礼物名称", "礼物分值" },
                                          new Dictionary <string, HZH_Controls.TextInputType>()
            {
                { "礼物名称", HZH_Controls.TextInputType.NotControl }, { "礼物分值", HZH_Controls.TextInputType.Integer }
            },
                                          new Dictionary <string, string>()
            {
            },
                                          new Dictionary <string, KeyBoardType>()
            {
            },
                                          new List <string>()
            {
                "礼物名称", "礼物分值"
            });

            if (frm.ShowDialog(this) == DialogResult.OK)
            {
                var name   = frm.Values[0];
                var points = frm.Values[1];
                if (int.TryParse(points, out var _giftPoints) == false)
                {
                    FrmDialog.ShowDialog(this, "礼物分值格式错误");
                    return;
                }
                using (var db = new MemberCardContext())
                {
                    var gift = new Gift()
                    {
                        GiftName = name,
                        Points   = _giftPoints
                    };
                    db.Gifts.Add(gift);
                    await db.SaveChangesAsync();
                }
                await RefreshGifts();
            }
        }
Ejemplo n.º 16
0
        private async Task BuyMoney()
        {
            if (int.TryParse(txt_Deduct.InputText, out var _deduct) == false || _deduct < 0)
            {
                FrmDialog.ShowDialog(this, "请输入正确的折扣金额");
                return;
            }
            if (int.TryParse(txt_Remain.InputText, out var _remain) == false || _remain < 0)
            {
                FrmDialog.ShowDialog(this, "请输入正确的金额");
                return;
            }
            if (_deduct > remainMoney)
            {
                FrmDialog.ShowDialog(this, "余额不足");
                return;
            }
            using (var db = new MemberCardContext())
            {
                var card = await db.Cards.FirstOrDefaultAsync(item => item.CardId == currentId && item.IsActive);

                if (card == null)
                {
                    FrmDialog.ShowDialog(this, "未找到该会员卡,可能不存在或者被锁定");
                    return;
                }
                var remainMoney = card.Money - _deduct;
                card.Money = remainMoney;
                var record = new BuyRecord
                {
                    CardId     = card.CardId,
                    Record     = $"[余额消费]消费{txt_MoneyTotalMoney.InputText}元,余额抵扣{_deduct}元,实付{_remain}元,剩余余额{remainMoney}",
                    RecordTime = DateTime.Now
                };
                db.BuyRecords.Add(record);
                await db.SaveChangesAsync();

                this.Close();
            }
        }
Ejemplo n.º 17
0
        private async void btn_Ok_BtnClick(object sender, EventArgs e)
        {
            this.Enabled = false;
            var id          = txt_CardId.InputText;
            var phoneNumber = txt_PhoneNumber.InputText;
            var cardType    = (CardType)Enum.Parse(typeof(CardType), cbx_CardType.TextValue);
            var userName    = txt_UserName.InputText;

            if (string.IsNullOrWhiteSpace(id))
            {
                FrmDialog.ShowDialog(this, "卡号不能为空");
                this.Enabled = true;
                return;
            }
            using (var db = new MemberCardContext())
            {
                if (db.Cards.Any(item => item.CardId == id))
                {
                    FrmDialog.ShowDialog(this, "卡号已存在");
                    this.Enabled = true;
                    return;
                }
                //20201108移除手机号重复限制
                //if (string.IsNullOrWhiteSpace(phoneNumber) == false)
                //{
                //    if (db.Cards.Any(item => item.IsActive == true && item.PhoneNumber == phoneNumber))
                //    {
                //        FrmDialog.ShowDialog(this, "手机号已存在");
                //        this.Enabled = true;
                //        return;
                //    }
                //}
                var card = new Card {
                    CardId = id, PhoneNumber = phoneNumber, CardType = cardType, UserName = userName, Money = 0, Points = 0, IsActive = true
                };
                db.Cards.Add(card);
                await db.SaveChangesAsync();
            }
            Close();
        }
Ejemplo n.º 18
0
        private async void ucTimeLine_Load(object sender, System.EventArgs e)
        {
            List <TimeLineItem> items = new List <TimeLineItem>();

            using (var db = new MemberCardContext())
            {
                if (String.IsNullOrWhiteSpace(_cardId))
                {
                    //没传 认为是查近一百条消费记录
                    dynamic records = await db.BuyRecords.OrderByDescending(item => item.Id).Join(db.Cards, b => b.CardId, c => c.CardId, (b, c) => new { Info = b, Name = c.UserName }).Take(100).ToListAsync();

                    foreach (var record in records)
                    {
                        items.Add(new TimeLineItem {
                            Title = record.Info.RecordTime.ToString("yyyy-MM-dd HH:mm:ss"), Details = record.Info.CardId + " " + record.Name + "    " + record.Info.Record
                        });
                    }
                }
                else
                {
                    var records = await db.BuyRecords.Where(item => item.CardId == _cardId).OrderByDescending(item => item.Id).ToListAsync();

                    foreach (var record in records)
                    {
                        items.Add(new TimeLineItem {
                            Title = record.RecordTime.ToString("yyyy-MM-dd HH:mm:ss"), Details = record.Record
                        });
                    }
                }
            }
            if (items.Count == 0)
            {
                items.Add(new TimeLineItem()
                {
                    Title = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Details = "无消费记录"
                });
            }
            ucTimeLine.Items = items.ToArray();
        }
Ejemplo n.º 19
0
        private async void tsm_DoActive_Click(object sender, EventArgs e)
        {
            if (_currentCard == null)
            {
                return;
            }
            if (FrmDialog.ShowDialog(this, $"请确定{(_currentCard.IsActive?"锁定":"解锁")}", "提示", true) == DialogResult.OK)
            {
                using (var db = new MemberCardContext())
                {
                    var card = await db.Cards.FirstOrDefaultAsync(item => item.CardId == _currentCard.CardId && item.IsActive == _currentCard.IsActive);

                    if (card == null)
                    {
                        FrmDialog.ShowDialog(this, "未找到该会员卡");
                        return;
                    }
                    card.IsActive = !card.IsActive;
                    await db.SaveChangesAsync();
                }
                await Search();
            }
        }
Ejemplo n.º 20
0
 private void ConfigForm_Load(object sender, System.EventArgs e)
 {
     using (var db = new MemberCardContext())
     {
         var per = db.Configs.FirstOrDefault(item => item.Key == ConfigName.DeductPerCent.ToString());
         if (per == null)
         {
             txt_DeductPer.InputText = "10";
         }
         else
         {
             txt_DeductPer.InputText = per.Value;
         }
         var path = db.Configs.FirstOrDefault(item => item.Key == ConfigName.BackupPath.ToString());
         if (path == null)
         {
             txt_Path.InputText = "";
         }
         else
         {
             txt_Path.InputText = path.Value;
         }
     }
 }
Ejemplo n.º 21
0
        private async void tsm_Delete_Click(object sender, EventArgs e)
        {
            PasswordForm password = new PasswordForm();

            if (password.ShowDialog(this) == DialogResult.OK)
            {
                if (_currentCard == null)
                {
                    return;
                }
                if (FrmDialog.ShowDialog(this, $"确定删除:{_currentCard.CardId}({_currentCard.PhoneNumber},{_currentCard.UserName})及相关消费记录?", "提示", true) == DialogResult.OK)
                {
                    using (var db = new MemberCardContext())
                    {
                        var cards = db.Cards.Where(item => item.CardId == _currentCard.CardId);
                        var logs  = db.BuyRecords.Where(item => item.CardId == _currentCard.CardId);
                        db.Cards.RemoveRange(cards);
                        db.BuyRecords.RemoveRange(logs);
                        await db.SaveChangesAsync();
                    }
                    await Search();
                }
            }
        }