Form1.cs 3.68 KB
using BarcodeScannerClient;
//using HttpUtils;
using MoyaAdminLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows.Forms;

namespace Cloakroom
{
    public partial class Form1 : Form
    {

        private string cloakroomLabel = "narikkalappu.lbx";
        //private int number = 1;

        public Form1()
        {
            InitializeComponent();
            Properties.Settings.Default.Reload();
        }

        private void settingsToolStripButton_Click(object sender, EventArgs e)
        {
            Settings frm = new Settings();
            frm.ShowDialog();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            numberNumericUpDown.Value = Properties.Settings.Default.CodeNumber;
            
        }

        private void submitButton_Click(object sender, EventArgs e)
        {
            LuggageHold luggage = new LuggageHold();
            luggage.luggageCode = numberNumericUpDown.Value.ToString();
            luggage.description = luggaageDescriptionTextBox.Text;
            luggage.date = DateTime.Now;
            ListViewItem lvi = new ListViewItem(luggage.date.ToString("d.M.yyyy HH:mm"));
            lvi.SubItems.Add(luggage.description);
            lvi.SubItems.Add(luggage.luggageCode);
            //luggagesListView.Items.Add(lvi);

            if (printLabel((int)numberNumericUpDown.Value, luggage.description))
            {
                addMessageToListView("Luggage submitted.Code " + numberNumericUpDown.Value.ToString() + ", Description: '" + luggaageDescriptionTextBox.Text + "'");
                numberNumericUpDown.Value += 1;
                Properties.Settings.Default.CodeNumber = (int)numberNumericUpDown.Value;
                Properties.Settings.Default.Save();
            }
        }
        

        private bool printLabel(int number, string desc)
        {
            if (!File.Exists(cloakroomLabel))
            {
                MessageBox.Show("Cannot find print template");
                return false;
            }
            bpac.DocumentClass doc = null;
            try
            {
                doc = new bpac.DocumentClass();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not print luggage label. LuggageCode: " + number.ToString());
                Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace);
                return false;
            }
            //doc.SetPrinter(Objects.Conf.BoxLabelPrinter, false);
            if (doc != null)
            {
                //doc.Open(Path.Combine(Properties.Settings.Default.dd, cloakroomLabel));
                doc.Open(cloakroomLabel);

                doc.GetObject("Code").Text = number.ToString();
                doc.GetObject("Desc").Text = desc;

                doc.StartPrint("", bpac.PrintOptionConstants.bpoDefault);
                doc.PrintOut(2, bpac.PrintOptionConstants.bpoDefault);
                doc.EndPrint();
                
                doc.Close();

                return true;
            }
            return false;
        }

        private void addMessageToListView(string p)
        {
            ListViewItem lvi = new ListViewItem(DateTime.Now.ToString("d.M.yyyy HH:mm"));
            lvi.SubItems.Add(p);
            messageListView.Items.Insert(0, lvi);
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
        }

    }

     
}