private TextBox InsertField(string name, KeyPressEventHandler validation)
 {
     Label lbl = new Label();
     // Label
     lbl.ForeColor = Color.White;
     lbl.Font = new Font("Segoe UI Light", 16);
     lbl.Location = new Point(0, FieldOffsetY);
     lbl.Text = name;
     lbl.Size = new Size((int)(_This.Width * .2), FieldHeight);
     BoxGroup.Controls.Add(lbl);
     // Input
     int tbxW = (int)(_This.Width * .4);
     TextBox tbx = new MetroTextBox(tbxW, FieldHeight, false);
     tbx.Location = new Point(lbl.Left + lbl.Width + FieldPadding, FieldOffsetY);
     tbx.ImeMode = System.Windows.Forms.ImeMode.Disable;
     if (validation != null) tbx.KeyPress += validation;
     FieldOffsetY += FieldHeight + FieldPadding;
     BoxGroup.Controls.Add(tbx);
     return tbx;
 }
Beispiel #2
0
        public PaymentForm(Root root, IParentForm parent, bool isCheckout, bool payByCash, double total,
            bool delivery, string customer = null, string address = null, string phone = null) : base(root, parent, Root.GetMsg("cart.make-payment"))
        {
            FinalTotal = total;
            IsCheckout = isCheckout;
            PaymentMethodCash = payByCash;
            IsDelivery = delivery;
            CustomerName = customer;
            CustomerAddress = address;
            CustomerPhone = Int32.TryParse(phone, out CustomerPhone) ? CustomerPhone : -1;
            int panelpw = (int)(_This.ContentPanel.Width * (1 / 3.0));
            Panel container = new Panel();
            container.AutoSize = true;
            // amount
            Label hintAmount = new Label();
            hintAmount.AutoSize = true;
            hintAmount.Text = delivery ? Root.GetMsg("cart.deposit") : Root.GetMsg("cart.total");
            hintAmount.Font = new Font("Segoe UI Light", 13);
            hintAmount.ForeColor = Color.FromArgb(204, 204, 204);
            container.Controls.Add(hintAmount);
            hintAmount.Location = new Point(0, offsetY);
            bool canPay = false;
            if (delivery)
            {
                Label hintDeposit = new Label();
                hintDeposit.AutoSize = true;
                hintDeposit.Text = "(" + (total * .2).ToString("C", CultureInfo.CreateSpecificCulture("zh-HK")) + " - " + total.ToString("C", CultureInfo.CreateSpecificCulture("zh-HK")) + ")";
                hintDeposit.Font = new Font("Segoe UI Light", 12);
                hintDeposit.ForeColor = Color.FromArgb(255, 213, 77);
                container.Controls.Add(hintDeposit);
                hintDeposit.Location = new Point(hintAmount.Width, offsetY + hintAmount.Height / 2 - hintDeposit.Height / 2);
            }
            offsetY += hintAmount.Height + 12;
            Control amount;
            if (delivery)
            {
                amount = new MetroTextBox(panelpw, 32);
                amount.KeyPress += Validation.FloatField;
                amount.KeyUp += (sender, e) =>
                {
                    double deposit = double.TryParse(amount.Text, out deposit) ? deposit : 0.0;
                    double minimum = total * .2;
                    if (deposit >= minimum && deposit <= total)
                    {
                        canPay = true;
                        /*if (PaymentMethodCash) _This.SelectNextControl((Control)sender, true, true, true, true);
                        else */if (!PaymentMethodCash) CashIn.ForeColor = Color.White;
                    }
                    else
                    {
                        canPay = false;
                        if (!BtnPaid.Disabled) BtnPaid.Disabled = true;
                        if (!PaymentMethodCash) CashIn.ForeColor = Color.Gray;
                    }
                };
            }
            else
            {
                amount = new Label();
                amount.AutoSize = true;
                amount.Text = total.ToString("C", CultureInfo.CreateSpecificCulture("zh-HK"));
                amount.Font = new Font("Segoe UI Light", 16);
                canPay = true;
            }
            container.Controls.Add(amount);
            amount.Location = new Point(0, offsetY);
            offsetY += amount.Height + 12;
            // cash in
            Label hintCashIn = new Label();
            hintCashIn.AutoSize = true;
            hintCashIn.Text = Root.GetMsg("cart.cash-in");
            hintCashIn.Font = new Font("Segoe UI Light", 13);
            hintCashIn.ForeColor = Color.FromArgb(204, 204, 204);
            container.Controls.Add(hintCashIn);
            hintCashIn.Location = new Point(0, offsetY);
            offsetY += hintCashIn.Height + 12;
            if (PaymentMethodCash)
            {
                Change.Text = 0.ToString("C", CultureInfo.CreateSpecificCulture("zh-HK"));
                MetroTextBox tbx = new MetroTextBox(panelpw, 32);
                tbx.KeyPress += Validation.FloatField;
                EventHandler eh = new EventHandler((sender, e) =>
                {
                    double paid = double.TryParse(tbx.Text, out paid) ? paid : 0.0;
                    // <!> MUST be used only in Deposit scenario
                    double deposit = double.TryParse(amount.Text, out deposit) ? deposit : 0.0;
                    // </!> MUST be used only in Deposit scenario
                    double ttl = delivery ? deposit : total;
                    if (canPay)
                    {
                        Change.Text = (paid - ttl > 0 ? paid - ttl : 0).ToString("C", CultureInfo.CreateSpecificCulture("zh-HK"));
                        FinalAmount = ttl;
                        FinalCashIn = paid; 
                        BtnPaid.Disabled = paid < ttl;
                    }
                });
                tbx.GotFocus += eh;
                tbx.KeyUp += new KeyEventHandler(eh);
                container.Controls.Add(tbx);
                tbx.Location = new Point(0, offsetY);
                offsetY += tbx.Height + 12;
            }
            else
            {
                Change.Text = "N/A";
                // icon
                PictureBox icon = new PictureBox();
                icon.Size = new Size(24, 24);
                icon.Image = Properties.Resources.scan;
                container.Controls.Add(icon);
                icon.Location = new Point(0, offsetY);
                // status text
                CashIn = new Label();
                CashIn.AutoSize = true;
                CashIn.Text = Root.GetMsg("cart.pay-by-card");
                CashIn.Font = new Font("Segoe UI Light", 16);
                if (delivery) CashIn.ForeColor = Color.Gray;
                container.Controls.Add(CashIn);
                CashIn.Location = new Point(0 + icon.Width + 12, offsetY + (icon.Height / 2 - CashIn.Height / 2));
                offsetY += icon.Height + 12;
                // emulate payment process
                int ticked = 0;
                bool paymentSucceed = false;
                Timer emulate = new Timer();
                emulate.Interval = 500;
                emulate.Tick += (sender, e) =>
                {
                    if (paymentSucceed)
                    {
                        icon.Image = Properties.Resources.tick;
                        CashIn.Text = Root.GetMsg("cart.payment-ok");
                        BtnPaid.Disabled = false;
                        FinalAmount = !delivery ? total : double.TryParse(amount.Text, out FinalAmount) ? FinalAmount : 0.0;
                        FinalCashIn = FinalAmount; 
                        emulate.Stop();
                    }
                    else
                    {
                        if (ticked < 4)
                            CashIn.Text = Root.GetMsg("cart.payment-card-phase-1");
                        else if (ticked < 8)
                            CashIn.Text = Root.GetMsg("cart.payment-card-phase-2");
                        else if (ticked < 16)
                            CashIn.Text = Root.GetMsg("cart.payment-card-phase-3");
                        else if (ticked < 24)
                            CashIn.Text = Root.GetMsg("cart.payment-card-phase-4");
                        else
                            paymentSucceed = true;
                        ticked++;
                    }
                };
                EventHandler eh = null;
                eh = new EventHandler((sender, e) => {
                    if (delivery && !canPay) return;
                    emulate.Enabled = true;
                    emulate.Start();
                    icon.Image = Properties.Resources.loader_small;
                    icon.Click -= eh;
                    icon.Cursor = Cursors.Default;
                    CashIn.Click -= eh;
                    CashIn.Cursor = Cursors.Default;
                });
                icon.Click += eh;
                icon.Cursor = Cursors.Hand;
                CashIn.Click += eh;
                CashIn.Cursor = Cursors.Hand;
            }
            // changes
            Label hintChange = new Label();
            hintChange.AutoSize = true;
            hintChange.Text = Root.GetMsg("cart.change");
            hintChange.Font = new Font("Segoe UI Light", 13);
            hintChange.ForeColor = Color.FromArgb(204, 204, 204);
            container.Controls.Add(hintChange);
            hintChange.Location = new Point(0, offsetY);
            offsetY += hintChange.Height + 12;
            Change.AutoSize = true;
            Change.Font = new Font("Segoe UI Light", 16);
            container.Controls.Add(Change);
            Change.Location = new Point(0, offsetY);
            offsetY += Change.Height + 12;
            // offset for buttons
            offsetY += 32;
            // mark order paid
            BtnPaid.AutoSize = true;
            BtnPaid.Text = Root.GetMsg("cart.mark-and-return");
            BtnPaid.Click += ActionPaymentCompleted;
            BtnPaid.Disabled = true;
            container.Controls.Add(BtnPaid);
            BtnPaid.Location = new Point(0, offsetY);
            offsetY += BtnPaid.Height + 12;
            // print invoice checkbox
            container.Controls.Add(PrintInvoice);
            PrintInvoice.Location = new Point(BtnPaid.Left + BtnPaid.Width + 32, BtnPaid.Top + BtnPaid.Height / 2 - PrintInvoice.Height / 2);
            Label hintPrintInvoice = new Label();
            hintPrintInvoice.AutoSize = true;
            hintPrintInvoice.Text = Root.GetMsg("cart.print-invoice");
            hintPrintInvoice.Font = new Font("Segoe UI Light", 12);
            hintPrintInvoice.ForeColor = Color.FromArgb(204, 204, 204);
            container.Controls.Add(hintPrintInvoice);
            hintPrintInvoice.Location = new Point(PrintInvoice.Left + PrintInvoice.Width + 8, BtnPaid.Top + BtnPaid.Height / 2 - hintPrintInvoice.Height / 2);

            _This.ContentPanel.Controls.Add(container);
            container.Location = new Point(_This.ContentPanel.Width / 2 - container.Width / 2, _This.ContentPanel.Height / 2 - container.Height / 2 - _This.ContentPanel.Top / 2);
        }
Beispiel #3
0
        private void InitialInfoPaneComponents()
        {
            FieldMaxWidth = InfoPane.Width - PanePadding * 2;
            // subtotal
            InsertFieldHeader(Root.GetMsg("cart.subtotal"), InfoPane);
            InsertField(FieldSubtotal, InfoPane, typeof(Label));
            // discount
            InsertFieldHeader(Root.GetMsg("cart.discounted"), InfoPane);
            InsertField(FieldDiscounted, InfoPane, typeof(Label));
            // total
            InsertFieldHeader(Root.GetMsg("cart.total"), InfoPane);
            InsertField(FieldTotal, InfoPane, typeof(Label));
            // panel for contain optional delivery inputs
            Panel dPane = new Panel();
            dPane.Visible = false;
            dPane.AutoSize = true;
            // is delivery item (for checkout only)
            if (IsCheckout)
            {
                InsertFieldHeader(Root.GetMsg("cart.delivery"), InfoPane);
                InsertField(FieldDelivery, InfoPane, typeof(MetroCheckBox));
            }
            // customer name
            FieldCustomerName = new MetroTextBox(FieldMaxWidth - 6 * 2, 32);
            InsertFieldHeader(Root.GetMsg("cart.cust-name"), dPane);
            InsertField(FieldCustomerName, dPane, typeof(MetroTextBox));
            FieldCustomerName.KeyPress += Validation.NonNumberField;
            // address
            FieldAddress = new MetroTextBox(FieldMaxWidth - 6 * 2, 64);
            InsertFieldHeader(Root.GetMsg("cart.cust-addr"), dPane);
            InsertField(FieldAddress, dPane, typeof(MetroTextBox));
            FieldAddress.Multiline = true;
            // phone
            FieldPhoneNum = new MetroTextBox(FieldMaxWidth - 6 * 2, 32);
            InsertFieldHeader(Root.GetMsg("cart.cust-phone"), dPane);
            InsertField(FieldPhoneNum, dPane, typeof(MetroTextBox));
            FieldPhoneNum.KeyPress += (sender, e) => { Validation.NumberField(sender, e, 8); };
            // insert optional delivery inputs panel
            dPane.Top = FieldsOffsetY;
            InfoPane.Controls.Add(dPane);
            FieldsOffsetY += dPane.Height + FieldsPadding;
            Size dPaneSavedSize = new Size(dPane.Size.Width, dPane.Size.Height);
            dPane.AutoSize = false;
            if (IsCheckout) dPane.Size = new Size(dPaneSavedSize.Width, 0);
            dPane.Visible = true;
            // padding for buttons
            FieldsOffsetY += 12;
            // PayByCash
            PayByCash.AutoSize = true;
            int btnWidth = (int)(FieldMaxWidth * .4);
            PayByCash.MinimumSize = new Size(btnWidth, 48);
            PayByCash.Padding = new Padding(32, 0, 0, 0);
            PayByCash.Left = FieldMaxWidth / 2 - btnWidth - FieldsPadding;
            PayByCash.Paint += (sender, e) =>
            {
                Image im = Properties.Resources.money;
                SizeF size = e.Graphics.MeasureString(PayByCash.Text, PayByCash.Font);
                e.Graphics.DrawImage(im, (btnWidth - size.Width) / 2 - PayByCash.Padding.Left / 2, PayByCash.Height / 2 - im.Height / 2);
            };
            PayByCash.Click += (sender, e) => { DoPayment(true); };
            PayByCash.Top = FieldsOffsetY - (IsCheckout ? dPaneSavedSize.Height : 0);
            PayByCash.Text = Root.GetMsg("cart.cash");
            InfoPane.Controls.Add(PayByCash);
            // PayByCreditCard
            PayByCreditCard.MinimumSize = new Size(btnWidth, 48);
            PayByCreditCard.Padding = PayByCash.Padding;
            PayByCreditCard.Left = FieldMaxWidth / 2 + FieldsPadding;
            PayByCreditCard.Paint += (sender, e) =>
            {
                Image im = Properties.Resources.credit_card;
                SizeF size = e.Graphics.MeasureString(PayByCreditCard.Text, PayByCreditCard.Font);
                e.Graphics.DrawImage(im, (btnWidth - size.Width) / 2 - PayByCreditCard.Padding.Left / 2, PayByCreditCard.Height / 2 - im.Height / 2);
            };
            PayByCreditCard.Click += (sender, e) => { DoPayment(false); };
            PayByCreditCard.Top = FieldsOffsetY - (IsCheckout ? dPaneSavedSize.Height : 0);
            PayByCreditCard.Text = Root.GetMsg("cart.card");
            InfoPane.Controls.Add(PayByCreditCard);
            int savedPaymentButtonOffsetY = FieldsOffsetY;
            FieldsOffsetY += PayByCreditCard.Height + FieldsPadding;

            // animate for slide down
            InfoPane.Top = _This.ContentPanel.Height / 2 - InfoPane.Height / 2;
            int savedInfoPaneY = InfoPane.Top;
            int savedInfoPaneHeight = InfoPane.Height;
            InfoPane.AutoSize = false;
            InfoPane.Height = savedInfoPaneHeight + (IsCheckout ? 0 : dPaneSavedSize.Height);
            if (IsCheckout)
            {
                FieldDelivery.CheckedChanged += (sender, e) =>
                {
                    if (FieldDelivery.Checked)
                    {
                        Transition t = new Transition(new TransitionType_EaseInEaseOut(250));
                        t.add(dPane, "Height", dPaneSavedSize.Height);
                        t.add(PayByCash, "Top", savedPaymentButtonOffsetY);
                        t.add(PayByCreditCard, "Top", savedPaymentButtonOffsetY);
                        t.add(InfoPane, "Height", savedInfoPaneHeight + dPaneSavedSize.Height);
                        t.add(InfoPane, "Top", savedInfoPaneY - dPaneSavedSize.Height / 2);
                        t.run();
                    }
                    else
                    {
                        dPane.AutoSize = false;
                        Transition t = new Transition(new TransitionType_EaseInEaseOut(250));
                        t.add(dPane, "Height", 0);
                        t.add(PayByCash, "Top", savedPaymentButtonOffsetY - dPaneSavedSize.Height);
                        t.add(PayByCreditCard, "Top", savedPaymentButtonOffsetY - dPaneSavedSize.Height);
                        t.add(InfoPane, "Height", savedInfoPaneHeight);
                        t.add(InfoPane, "Top", savedInfoPaneY);
                        t.run();
                    }
                };
            }
            else dPane.Size = dPaneSavedSize;
        }
Beispiel #4
0
 public LoginForm(Root p) : base(p, Root.GetMsg("login.title"), 540, 320)
 {
     _Root = p;
     // label - staff id
     LabelLogin = new Label();
     LabelLogin.AutoSize = true;
     LabelLogin.Font = new Font("Segoe UI Light", 14);
     LabelLogin.AutoSize = true;
     int lblX = base.Title.Left * 3;
     int lblHeight = LabelLogin.Height;
     int panelAdjust = (base.Size.Height - base.ContentPanel.Height) / 2;
     int lblInFormMiddle = (base.ContentPanel.Height / 2 - lblHeight / 2) - panelAdjust;
     int yOffsetLogin = lblInFormMiddle - lblHeight - 8;
     LabelLogin.Location = new Point(lblX, yOffsetLogin);
     LabelLogin.Text = Root.GetMsg("login.staffid");
     this.ContentPanel.Controls.Add(LabelLogin);
     // label - password
     LabelPassword = new Label();
     LabelPassword.AutoSize = true;
     LabelPassword.Font = new Font("Segoe UI Light", 14);
     LabelPassword.AutoSize = true;
     int yOffsetPassword = lblInFormMiddle + lblHeight + 8;
     LabelPassword.Location = new Point(lblX, yOffsetPassword);
     LabelPassword.Text = Root.GetMsg("login.passwd");
     this.ContentPanel.Controls.Add(LabelPassword);
     // textbox - staff id
     InputLogin = new MetroTextBox(256, 32);
     InputLogin.BackColor = Color.FromArgb(77, 77, 77);
     InputLogin.BorderStyle = BorderStyle.None;
     InputLogin.Font = new Font("Segoe UI Light", 16);
     InputLogin.ForeColor = Color.White;
     int txtX = base.Size.Width - lblX - InputLogin.Width;
     InputLogin.Location = new Point(txtX, yOffsetLogin - 8);
     InputLogin.TabStop = false;
     InputLogin.KeyDown += DetectHotKey;
     InputLogin.KeyPress += ValidateCharacters;
     this.ContentPanel.Controls.Add(InputLogin);
     // textbox - password
     InputPassword = new MetroTextBox(256, 32);
     InputPassword.BackColor = Color.FromArgb(77, 77, 77);
     InputPassword.BorderStyle = BorderStyle.None;
     InputPassword.Font = new Font("Segoe UI Light", 16);
     InputPassword.ForeColor = Color.White;
     InputPassword.Location = new Point(txtX, yOffsetPassword - 8);
     InputPassword.TabStop = false;
     InputPassword.KeyDown += DetectHotKey;
     InputPassword.KeyPress += ValidateCharacters;
     InputPassword.PasswordChar = '*';
     this.ContentPanel.Controls.Add(InputPassword);
     InputLogin.Text = "1";
     InputPassword.Text = "1234";
     // button login
     ButtonLogin = new MetroButton(fontSize: 12);
     ButtonLogin.Text = Root.GetMsg("login.title");
     ButtonLogin.AutoSize = true;
     ButtonLogin.Click += HandleLogin;
     ButtonLogin.TabStop = false;
     this.ContentPanel.Controls.Add(ButtonLogin);
     int btnX = base.Size.Width - lblX - ButtonLogin.Width;
     int btnY = base.Size.Height - base.ContentPanel.Top - base.Title.Top - ButtonLogin.Height + 1/* border size */;
     int minus = base.Size.Height - (base.ContentPanel.Top + yOffsetPassword + InputPassword.Height);
     btnY = (btnY - minus / 2) + ButtonLogin.Height - 1 * 2;
     ButtonLogin.Location = new Point(btnX, btnY);
     // lang chooser
     DropLang = new MetroComboBox();
     DropLang.Size = new Size(128, ButtonLogin.Height);
     DropLang.ImeMode = System.Windows.Forms.ImeMode.Disable;
     this.ContentPanel.Controls.Add(DropLang);
     DropLang.Location = new Point(InputPassword.Left, btnY + 1 /* border */);
     // add langs
     DropLang.SelectedIndexChanged += (sender, e) =>
     {
         int lang = (int)((sender as ComboBox).SelectedItem as ComboItem).Value;
         Root.SetLang(lang);
         UpdateFormLang();
     };
     DropLang.Items.Add(new ComboItem("English", 0xa));
     DropLang.Items.Add(new ComboItem("繁體中文", 0xb));
     DropLang.Items.Add(new ComboItem("简体中文", 0xc));
     DropLang.SelectedIndex = 0;
     // add clock
     Label currTime = new Label();
     currTime.AutoSize = true;
     currTime.Font = new Font("Segoe UI Light", 11);
     currTime.ForeColor = Color.FromArgb(204, 204, 204);
     currTime.Location = new Point(lblX, btnY + ButtonLogin.Height / 4);
     this.ContentPanel.Controls.Add(currTime);
     Timer tm = new Timer();
     tm.Tick += (sender, e) => {
         currTime.Text = DateTime.Now.ToString("yyyy/M/d H:mm:ss");
     };
     tm.Start();
 }
Beispiel #5
0
 private TextBox InsertField(string name, KeyPressEventHandler validation, int? height, int? wDimen)
 {
     Label lbl = new Label();
     int whichDimen = wDimen ?? 0;
     // Label
     if (whichDimen <= 1)
     {
         lbl.ForeColor = Color.White;
         lbl.Font = new Font("Segoe UI Light", 14);
         lbl.Location = new Point(0, FieldOffsetY);
         lbl.Text = name;
         lbl.Size = new Size((int)(_This.Width * .2), FieldHeight);
         BoxGroup.Controls.Add(lbl);
     }
     // Input
     int tbxW = (int)(_This.Width * .35);
     if (whichDimen >= 1) tbxW = (int)(tbxW * (1 / 3f)) - 8;
     TextBox tbx = new MetroTextBox(tbxW, height ?? FieldHeight, height != null);
     if (validation != null) tbx.KeyPress += validation;
     if (whichDimen <= 1)
     {
         tbx.Location = new Point(lbl.Left + lbl.Width + (int)(_This.Width * .05), FieldOffsetY);
         FieldOffsetY += (whichDimen <= 1) ? (height ?? FieldHeight) + FieldPadding : 0;
     }
     else
     {
         int offset = whichDimen - 1;
         tbx.Location = new Point(BoxDimen1.Left + BoxDimen1.Width * offset + 12 * offset, BoxDimen1.Top);
     }
     BoxGroup.Controls.Add(tbx);
     return tbx;
 }