using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Dress.svs;
using Dress.Controls;namespace Dress.Subs
{
    public partial class BaseInputForm : FormBase
    {
        private BizerInfo _bizer;
        private IProductGrid _grid;
        private ProductInfo _inputInfo;
        public BaseInputForm()
        {
            InitializeComponent();
            string v = DressConfig.GetValue(this.CheckKey);
            if (!string.IsNullOrEmpty(v))
                this.chkContinue.Checked = bool.Parse(v);
        }
        public BaseInputForm(BizerInfo bizer, IProductGrid grid)
            : this()
        {
            _grid = grid;
            _bizer = bizer;
            this.lblTitle.Text = bizer.BizerName;
        }        private void txtBarCode_LostFocus(object sender, EventArgs e)
        {
            if (_inputInfo != null)
                this.txtBarCode.Text = _inputInfo.ProductBarCode;
        }
        private void txtBarCode_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                if (this.txtBarCode.Text.Trim() == string.Empty)
                {
                    this.txtBarCode.Focus(); return;
                }
                try
                {
                    this.ShowStatus("正在查询条码");
                    string barCode = this.txtBarCode.Text.Trim();
                    _inputInfo = this.GetProductInfo(_bizer.BizerId, barCode);
                    this.HideStatus();
                    if (this._inputInfo == null)
                    {
                        this.txtProductName.Text = string.Empty;
                        this.numPrice.Value = 0;
                        this.numAmount.Value = 1;
                        this.ShowInfo(barCode + " 条码并不存在。");
                        this.txtBarCode.SelectAll();
                        this.txtBarCode.Focus();
                    }
                    else
                    {
                        this.txtBarCode.Text = _inputInfo.ProductBarCode;
                        this.txtProductName.Text = _inputInfo.ProductName;
                        this.numPrice.Value = _inputInfo.ProductPrice;
                        this.numAmount.Value = 1;
                        this.numPrice.Focus();
                    }
                }
                catch (Exception err)
                {
                    this.HideStatus();
                    MessageBox.Show(err.Message, this.Text);
                }
            }
        }
        protected virtual ProductInfo GetProductInfo(int bizerId, string barCode)
        {
            return null;
        }        private void numPrice_ValueChanged(object sender, EventArgs e)
        {
            decimal price = this.numPrice.Value;
            int amount = (int)this.numAmount.Value;
            decimal money = amount * price;
            this.txtMoney.Text = "¥" + money.ToString("0.00");
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (_inputInfo == null)
            {
                this.txtBarCode.Focus(); return;
            }
            _inputInfo.ProductPrice = this.numPrice.Value;
            _inputInfo.ProductAmount = (int)this.numAmount.Value;
            _grid.AddRow(_inputInfo);
            if (this.chkContinue.Checked)
            {
                this.txtBarCode.Text = string.Empty;
                this.txtProductName.Text = string.Empty;
                this.numAmount.Value = 1;
                this.numPrice.Value = 0;
                this.txtBarCode.Focus();
            }
            else
                this.DialogResult = DialogResult.Cancel;
        }        private void btnClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }        private string CheckKey
        {
            get
            {
                return "ContinueInput";
            }
        }        private void BaseInputForm_Closing(object sender, CancelEventArgs e)
        {
            DressConfig.SetValue(this.CheckKey, this.chkContinue.Checked.ToString());
        }希望能详细点!大白话就可以.....