Exemple #1
0
        private void DispenseForm_ButtonClicked(object sender, DispenseUpdateEventArgs e)
        {
            loadProductTable();

            int    daunits    = e.getDaUnits;
            int    daunitsout = e.getDaUnitsOut;
            string thepid     = e.getPid;
            string thedosage  = e.getDosage;
            string thedrug    = e.getTheDrugDispensed;

            string dispenseQuery = "update apms.stock SET " +
                                   "`quantity` = '" + daunits + "'" +
                                   " where `stockid` = '" + thepid + "'; ";

            updateStockLevels(dispenseQuery, daunits, thepid);

            // font for list box -- ensure all paddigns are well aligned
            dosage_list.Font = new Font(FontFamily.GenericMonospace, dosage_list.Font.Size);
            string pharmDosage = thedrug.PadRight(30) + thedosage;

            dosage_list.Items.Add(pharmDosage);

            int    remainingUnits = daunits - daunitsout;
            string dispenseRecord = thepid + "*" + thedrug + "*" + daunits + "*" + daunitsout + "*" + remainingUnits + "*" + dateclock_txt.Text;

            dispenseRecord_list.Items.Add(dispenseRecord); // Dispense List -- Captures ALL History

            runStockControlCard(thepid, thedrug, daunits, daunitsout);

            loadProductTable();
        }
        // this button click event handler will raise the event which can then intercepted by any
        // listeners // read the textboxes and set the variables
        private void done_btn_Click(object sender, EventArgs e)
        {
            string uUnitsOut = unitsOUT_txt.Text;
            string dDosage   = dosage_txt.Text;

            // form validation
            // if empty >
            if (string.IsNullOrEmpty(uUnitsOut))
            {
                MessageBox.Show("~ please enter units to dispense", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); unitsOUT_txt.Focus(); return;
            }
            if (string.IsNullOrEmpty(dDosage))
            {
                MessageBox.Show("~ please enter dosage instructions", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); dosage_txt.Focus(); return;
            }

            // if non-integer >
            int tester;

            if (!Int32.TryParse(unitsOUT_txt.Text, out tester))
            {
                { MessageBox.Show("~ units dispense entry must be an integer", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); unitsOUT_txt.Focus(); return; }
            }

            // if illogical
            int unitsOut = Int32.Parse(uUnitsOut);

            if (unitsOut < 1)
            {
                MessageBox.Show("~ units dispense entry is illogical", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); unitsOUT_txt.Focus(); return;
            }

            // theunits = STOCK_AVAIL - STOCK_OUT
            int theunits = Int32.Parse(unitsAvail) - unitsOut;

            if (theunits >= 0) // products still in-stock
            {
                DialogResult result = MessageBox.Show("Dispense this product?", "Dispense Confirmation",
                                                      MessageBoxButtons.YesNoCancel,
                                                      MessageBoxIcon.Question,
                                                      MessageBoxDefaultButton.Button2);

                if (result == DialogResult.Yes)
                {
                    // instance the event args and pass it each value
                    DispenseUpdateEventArgs args = new DispenseUpdateEventArgs(pid, dDosage, theunits, unitsOut, theDrugDispensed);

                    // raise the event with the updated arguments
                    DispenseUpdated(this, args);
                    this.Dispose();
                }
            }
            else // products will be out of stock
            {
                MessageBox.Show("> Sorry, dispense limit exceeded. Re-stock or Try again!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
        }