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 _paytypes = new List(); private List _paymodes = new List(); 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().ToList(); this._paytypes = db.Query().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(); using (var db = Global.Instance.OpenDataBase) { lists = db.Query("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(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"; } } } }