Beispiel #1
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();
                }
            }
        }
        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();
            }
        }
        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();
        }
        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();
            }
        }
        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();
            }
        }
        //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();
            }
        }
 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);
             }
         }
     }
 }
        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();
                }
            }
        }
Beispiel #9
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();
                }
            }
        }
        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();
            }
        }
        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();
            }
        }
        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();
        }
        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();
            }
        }
        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();
                }
            }
        }