using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using Sample.Model.Store; using Sample.BusinessLogic; using WinGUI.Utils; using Sample.Common.Util; namespace WinGUI.Controls.Store { public partial class StoreItem : UserControl, IItemControl, ICustomControl { private GoodInfoModel goodInfoModel; public StoreItem() { InitializeComponent(); } #region base handlers private void btnOK_Click(object sender, EventArgs e) { this.SaveInfoModel(); this.OnActionComplete(); } private void btnCancel_Click(object sender, EventArgs e) { this.OnActionComplete(); } #endregion base handlers #region helper methods private void SaveInfoModel() { if (this.goodInfoModel == null) { this.goodInfoModel = new GoodInfoModel(); } this.goodInfoModel.Name = this.tbName.Text; this.goodInfoModel.Cost = FormatHelper.ParseDecimal(this.tbCost.Text); this.goodInfoModel.Quantity = FormatHelper.ParseInt32(this.tbQuantity.Text); if (this.goodInfoModel.Id == Guid.Empty) { ServiceFacade.GoodService.InsertGoodInfo(this.goodInfoModel); } else { ServiceFacade.GoodService.UpdateGoodInfo(this.goodInfoModel); } } #endregion helper methods #region IItemControl Members public void LoadInfoModel(Guid id) { this.goodInfoModel = ServiceFacade.GoodService.GetGoodInfoById(id); if (this.goodInfoModel != null) { this.tbName.Text = this.goodInfoModel.Name; this.tbCost.Text = FormatHelper.FormatNumberN2(this.goodInfoModel.Cost); this.tbQuantity.Text = FormatHelper.FormatNumber(this.goodInfoModel.Quantity); } } #endregion #region ICustomControl Members public event EventHandler<ActionCompleteEventArgs> ActionComplete; protected virtual void OnActionComplete() { ActionCompleteEventArgs args; if (this.goodInfoModel != null) { args = new ActionCompleteEventArgs(); args.ItemInfoID = this.goodInfoModel.Id; } else { args = ActionCompleteEventArgs.Empty; } this.OnActionComplete(args); } protected virtual void OnActionComplete(ActionCompleteEventArgs args) { if (this.ActionComplete != null) { this.ActionComplete(this, args); } } #endregion } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)