Example #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //empSearch
            dataAccess data = new dataAccess();

            table = new DataTable();

            if (Search.Text == "" || Search.Text == null)
            {
                MessageBox.Show("Search Field required");
            }
            else
            {
                table = data.getEmployee(int.Parse(Search.Text));
                if (table.Rows.Count > 0)
                {
                    foreach (DataRow row in table.Rows)
                    {
                        EmployeeNumber.Text = row["EmployeeNumber"].ToString();
                        EmployeeName.Text   = row["EmployeeName"].ToString();
                        EmployeeID.Text     = row["EmployeeID"].ToString();
                        Address.Text        = row["Address"].ToString();
                        Email.Text          = row["Email"].ToString();
                        PositionID.Text     = row["PositionID"].ToString();
                        Username.Text       = row["Username"].ToString();
                        Password.Password   = row["Password"].ToString();
                        ReportTo.Text       = row["ReportTo"].ToString();
                    }
                }
                else
                {
                    MessageBox.Show("Employee Not Found !!");
                }
            }
        }
Example #2
0
        private void Purchase_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection connection = new SqlConnection(
                ConfigurationManager.ConnectionStrings["POS.Properties.Settings.Setting"].ConnectionString
                );
            DataSet    dataSet = new DataSet();
            DataTable  table   = new DataTable();
            dataAccess data    = new dataAccess();

            SqlCommand cmd = new SqlCommand();

            connection.Open();

            double change   = 0;
            string usernaam = MainWindow.userN;

            if (tenderedAmount.Text.Equals("") || tenderedAmount.Text == null || BarCode.Text.Equals("") || BarCode.Text == null)
            {
                MessageBox.Show("BarCode/Tendered Amount are empty of not of correct type");
            }
            else
            {
                if (Double.Parse(tenderedAmount.Text) < sum)
                {
                    MessageBox.Show("Insufficient cash provided");
                }
                else if (Double.Parse(tenderedAmount.Text) > sum)
                {
                    change = Double.Parse(tenderedAmount.Text) - (sum + (sum * 0.15));
                    changeLabel.Content = "R " + change;


                    //Obtain values of the invoice table
                    string query    = "SELECT * FROM Employee WHERE Username = '******' ";
                    string secQuery = "";

                    for (int i = 0; i < prodName.Count; i++)
                    {
                        secQuery = "SELECT * FROM Product WHERE ProductName = '" + prodName[i].ToString() + "' ";
                        using (SqlDataAdapter adapter = new SqlDataAdapter())
                        {
                            cmd = new SqlCommand(secQuery, connection);
                            adapter.SelectCommand = cmd;
                            adapter.Fill(dataSet, "product");
                            table = dataSet.Tables["product"];

                            cmd = new SqlCommand(query, connection);
                            adapter.SelectCommand = cmd;
                            adapter.Fill(dataSet, "emp");
                            empnum = int.Parse(dataSet.Tables["emp"].Rows[0]["EmployeeNumber"].ToString());

                            foreach (DataRow row in table.Rows)
                            {
                                barcode = long.Parse(row["BarCode"].ToString());
                                price   = Double.Parse(row["UnitPrice"].ToString());
                                tiime   = time[i];

                                data.recordHistory(barcode, price, empnum, tiime);

                                inv++;
                            }
                        }
                    }
                    for (int i = 0; i < prodName.Count; i++)
                    {
                        secQuery = "SELECT * FROM Product WHERE ProductName = '" + prodName[i].ToString() + "' ";
                        int leftStock = 0, reorder;

                        using (SqlDataAdapter adapter = new SqlDataAdapter())
                        {
                            cmd = new SqlCommand(secQuery, connection);
                            adapter.SelectCommand = cmd;
                            adapter.Fill(dataSet, "product");
                            table = dataSet.Tables["product"];

                            foreach (DataRow row in table.Rows)
                            {
                                leftStock  = Int32.Parse(row["UnitInStock"].ToString());
                                reorder    = Int32.Parse(row["ReorderLevel"].ToString());
                                leftStock += dcr;
                                //string email = data.isAvailable(int.Parse(table.Rows[0]["SupplierID"].ToString()));

                                if (leftStock < reorder)
                                {
                                    //send an email
                                    NetworkCredential network;
                                    SmtpClient        client;
                                    MailMessage       message;

                                    network            = new NetworkCredential("*****@*****.**", "Sx082@0797479084");
                                    client             = new SmtpClient("smtp.gmail.com"); //txtSmpt.Text
                                    client.Port        = Int32.Parse("587");               //
                                    client.EnableSsl   = true;
                                    client.Credentials = network;
                                    message            = new MailMessage {
                                        From = new MailAddress("sm.ced.xulu" + "smtp.gmail.com".Replace("smtp.", "@"), "Lucy", Encoding.UTF8)
                                    };
                                    message.To.Add(new MailAddress("*****@*****.**"));
                                    if (!string.IsNullOrEmpty(""))
                                    {
                                        message.To.Add(new MailAddress(""));
                                    }
                                    message.Subject = "Product Shortage";
                                    message.Body    = "Dear " + prodName[i].ToString() + " \n" +
                                                      "We Are in need of your stock so please get it for us Immediatly\n" +
                                                      "Thank you";
                                    message.BodyEncoding = Encoding.UTF8;
                                    message.IsBodyHtml   = true;
                                    message.Priority     = MailPriority.Normal;
                                    message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                                    client.SendCompleted += new SendCompletedEventHandler(SendCompleteCallBack);
                                    string userstate = "Sending...";
                                    client.SendAsync(message, userstate);
                                }
                            }

                            string instockQuery = "UPDATE Product " +
                                                  "SET UnitInStock = " + leftStock + " " +
                                                  "WHERE  ProductName = '" + prodName[i].ToString() + "' ";

                            cmd = new SqlCommand(instockQuery, connection);
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
            }

            tableRecords = ((DataView)invoiceGrid.ItemsSource).ToTable();
            for (int er = 0; er < tableRecords.Rows.Count; er++)
            {
                data.invoice(long.Parse(tableRecords.Rows[er]["BarCode"].ToString()), int.Parse(tableRecords.Rows[er]["Quantity"].ToString()),
                             double.Parse(tableRecords.Rows[er]["Price"].ToString()), empnum);


                data = new dataAccess();
            }
            //Printi out A SLIIP
            DataTable     prodFinder     = new DataTable();
            DataTable     empFinder      = new DataTable();
            double        totalSlipPrice = 0;
            List <string> listedItems    = new List <string>();

            empFinder = data.getEmployee(empnum);
            string cashierName = empFinder.Rows[0]["EmployeeName"].ToString();

            string formalSlip = "";

            foreach (DataRow rw in tableRecords.Rows)
            {
                totalSlipPrice += double.Parse(rw["Price"].ToString());
            }
            foreach (DataRow rw in tableRecords.Rows)
            {
                formalSlip = "Bar Code: " + rw["BarCode"].ToString() + "\n" +
                             "Product Name: " + rw["ProductName"].ToString() + "\n" +
                             "Quantity: " + rw["Quantity"].ToString() + "\n" +
                             "Product(s) Price:" + rw["Price"] + "\n" +
                             "---------------------------------------\n";
                listedItems.Add(formalSlip);
            }

            Document  doc    = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("C:/Users/smced/Music/Slip.pdf", FileMode.Create));

            doc.Open();
            totalSlipPrice += (totalSlipPrice * 0.15);
            listedItems.Add("Total Price :" + totalSlipPrice + "\n" +
                            "Cashier Name: " + cashierName);

            Paragraph elements;

            for (int c = 0; c < listedItems.Count; c++)
            {
                elements = new Paragraph(listedItems[c]);
                doc.Add(elements);
            }

            doc.Close();
            MessageBox.Show("Slip Printed");


            connection.Close();
        }