You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
5.2 KiB
C#

9 months ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar.Controls;
using POSV.Entity;
using POSV.Utils;
namespace POSV.Component
{
public partial class AddPaymentForm : BaseForm
{
private List<PayType> _paytypes = new List<PayType>();
private List<PayMode> _paymodes = new List<PayMode>();
public AddPaymentForm()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
lock (Global.Instance.SyncLock)
{
using (var db = Global.Instance.OpenDataBase)
{
this._paymodes = db.Query<PayMode>().ToList();
this._paytypes = db.Query<PayType>().ToList();
}
}
this.cmbPayType.DataSource = this._paytypes;
this.cmbPayType.DisplayMember = "Name";
this.cmbPayType.SelectedIndex = 0;
}
private void ButtonSaveClick(object sender , EventArgs e)
{
bool isException = true;
try
{
if(this.cmbPayMode.SelectedValue != null && this.cmbPayMode.SelectedValue is PayMode)
{
var payMode = this.cmbPayMode.SelectedValue as PayMode;
var lists = new List<Resources>();
using (var db = Global.Instance.OpenDataBase)
{
lists = db.Query<Resources>("where [group] = @0 and [keycode] = @1 and [keydata] = @2", ResourcesGroup..ToString(), "自定义支付" ,payMode.No).ToList();
}
if(lists.Count > 0)
{
var resource = lists[0];
var result = MessageBox.Show(string.Format("已添加编号[{0}]名称为[{1}]的支付方式,请确定是否继续保存?", resource.KeyData, resource.Name), "重复提示", MessageBoxButtons.OKCancel);
if(result == DialogResult.Cancel)
{
this.ShowMessage(this.lblInfo , "已添加,不能重复" , true);
return;
}
}
Resources entity = new Resources();
entity.Id = IdWorkerUtils.Instance.NextId();
entity.TenantId = Global.Instance.Authc.TenantId;
entity.Group = ResourcesGroup..ToString();
entity.Name = payMode.Name;
entity.KeyCode = "自定义支付";
entity.KeyData = payMode.No;
entity.Enable = 1;
lock (Global.Instance.SyncLock)
{
using (var db = Global.Instance.OpenDataBase)
{
using (var transaction = db.GetTransaction())
{
if(lists.Count > 0)
{
foreach(var item in lists)
{
db.Execute(string.Format("delete from pos_resources where id = '{0}';", item.Id));
db.Execute(string.Format("delete from pos_module where resourceId = '{0}';", item.Id));
}
}
db.Save<Resources>(entity);
transaction.Complete();
}
}
}
isException = false;
}
else
{
this.ShowMessage(this.lblInfo , "请选择支付方式" , true);
return;
}
}
catch (Exception ex)
{
isException = true;
this.ShowMessage(this.lblInfo , "保存自定义支付功能异常" , true);
LOGGER.Error(ex , "保存自定义支付功能异常");
}
finally
{
if (!isException)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}
private void OnCloseClick(object sender , EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
private void OnPayTypeSelectedIndexChanged(object sender , EventArgs e)
{
var cmbObject = (ComboBoxEx)sender;
if(cmbObject.SelectedValue != null && cmbObject.SelectedValue is PayType)
{
var payType = cmbObject.SelectedValue as PayType;
this.cmbPayMode.DataSource = this._paymodes.FindAll(x => x.TypeId == payType.Id && x.FrontFlag == 1);
this.cmbPayMode.DisplayMember = "Name";
}
}
}
}