using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PTMedicalInsurance.Variables;

namespace PTMedicalInsurance.Forms
{
    public partial class SaleBillInfo : Form
    {
        public string entId, code, medicalDrugId, batchNo;
        public decimal drugSalePrice = 0, unpackCount = 0;
        public int salePkg = 0;

        private void SaleBillInfo_Load(object sender, EventArgs e)
        {
            cbb_CLBS.SelectedIndex = 0;
            tb_CBXSSL.Text = "0";
        }

        private void cbb_CLBS_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbb_CLBS.SelectedIndex == 0)
            {
                tb_CBXSSL.Text = "0";
            }
            else
            {
                tb_CBXSSL.Text = "";
            }
        }

        public SaleBillInfo()
        {
            InitializeComponent();
        }

        public SaleBillInfo(string InsuCode,string InsuName)
        {
            InitializeComponent();
            tb_YBYPBM.Text = InsuCode;
            tb_YBYPMC.Text = InsuName;
            tb_JRZDBS.Text = Global.inf.hospitalNO;
        }

        private void uiButton8_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void uiButton9_Click(object sender, EventArgs e)
        {
            entId = tb_JRZDBS.Text;
            code = tb_ZSM.Text;
            medicalDrugId = tb_YBYPBM.Text;
            salePkg = int.Parse(cbb_CLBS.Text.Substring(0, 7));
            unpackCount = decimal.Parse(tb_CBXSSL.Text);
            drugSalePrice = decimal.Parse(tb_YPLSJG.Text);
            batchNo = tb_SCPC.Text;

            if ((code == "") && (batchNo == ""))            
            {
                MessageBox.Show("当【追溯码】为空时,【生产批次】必须有值!");
                return;
            }

            decimal count;
            count = unpackCount;
            if (cbb_CLBS.SelectedIndex != 0)            
            {
                if ((count <= 0) || (tb_CBXSSL.Text == ""))                
                {
                    MessageBox.Show("整包销售时【拆包销售数量】传0,拆零销售时【拆包销售数量】传大于0的整数!");
                    return;
                }
            }

            decimal price;
            price = drugSalePrice;
            if ((price <= 0) || (tb_YPLSJG.Text == ""))            
            {
                MessageBox.Show("【药品零售价格】无效!");
                return;
            }

            DialogResult = DialogResult.OK;
        }
    }
}