Example #1
0
        private void btnadd_Click(object sender, RoutedEventArgs e)
        {
            if (Txtquantity.Text == "")
            {
                MessageBox.Show("Quantity !");
                Txtquantity.Focus();
            }
            else
            {
                int price  = Convert.ToInt32(Txtpricee.Text);
                int qty    = Convert.ToInt32(Txtquantity.Text);
                int subtot = price * qty;

                transid = Convert.ToInt32(TxtID.Text.ToString());
                var trans = myContext.Transactions.Where(t => t.Id == transid).FirstOrDefault();
                var item  = myContext.Items.Where(i => i.Id == itemId).FirstOrDefault();


                if (Convert.ToInt32(Txtquantity.Text) <= item.Stock)
                {
                    item.Stock -= Convert.ToInt32(Txtquantity.Text);
                    Transcart.Add(new TransactionItem {
                        Transaction = trans, Item = item, Quantity = Convert.ToInt32(Txtquantity.Text)
                    });
                    GridTransItem.Items.Add(new { Name = cbNameitem.Text, Quantity = Txtquantity.Text, Price = Txtpricee.Text, subTotal = subtot.ToString() });
                    lasttot         += subtot;
                    Txttotalpay.Text = Convert.ToString(lasttot);
                    Showdata();
                }
                else
                {
                    MessageBox.Show("Quantity is limit");
                }



                Txttotal.Text    = "Rp. " + lasttot.ToString("n0") + ",-";
                Txttotalpay.Text = lasttot.ToString();

                Txtquantity.Text = "";
                Txtpricee.Text   = "";
                TxtStock.Text    = "";
            }
        }
Example #2
0
        private void btnsave_Click(object sender, RoutedEventArgs e)
        {
            int vpay     = Convert.ToInt32(Txtpay.Text);
            int totalpay = Convert.ToInt32(Txttotalpay.Text);

            if (Txttotalpay.Text == "")
            {
                MessageBox.Show("Payment required !");
                Txtquantity.Focus();
            }
            else if (totalpay <= vpay)
            {
                transid = Convert.ToInt32(TxtID.Text.ToString());
                var trans      = myContext.Transactions.Where(t => t.Id == transid).FirstOrDefault();
                var item       = myContext.Items.Where(i => i.Id == itemId).FirstOrDefault();
                int totalprice = Convert.ToInt32(Txttotalpay.Text);
                trans.Total = totalprice;
                Showdata();
                foreach (var transcart in Transcart)
                {
                    myContext.TransactionItems.Add(transcart);
                    myContext.SaveChanges();
                    struk += transcart.Item.Id.ToString() + "\t" + transcart.Item.Name + "\t" + transcart.Item.Price + "\t" + transcart.Quantity + "\t";
                }
                totalprice = 0;
                MessageBox.Show("Your Change is Rp." + (vpay - totalpay).ToString("n0") + "Thank You", "Notification", MessageBoxButton.OK);
                using (PdfDocument document = new PdfDocument())
                {
                    //Add a page to the document
                    PdfPage page = document.Pages.Add();

                    //Create PDF graphics for the page
                    PdfGraphics graphics = page.Graphics;

                    //Set the standard font
                    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);

                    //Draw the text
                    graphics.DrawString(struk, font, PdfBrushes.Black, new PointF(0, 0));

                    //Save the document
                    document.Save("Output.pdf");

                    #region View the Workbook
                    //Message box confirmation to view the created document.
                    if (MessageBox.Show("Do you want to view the PDF?", "PDF has been created",
                                        MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                    {
                        try
                        {
                            //Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer]
                            System.Diagnostics.Process.Start("Output.pdf");

                            //Exit
                            Close();
                        }
                        catch (Win32Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    }
                    else
                    {
                        Close();
                    }
                    #endregion
                }
            }
            else
            {
                MessageBox.Show("Your Payment is Invalid !");
            }
        }