public bool addItemsToBill(int BillId, int itemid, int qty)
        {
            bill_item bi = new bill_item();

            bi.billid = BillId;
            bi.itemid = itemid;
            bi.qty    = qty;
            dc.bill_items.InsertOnSubmit(bi);
            dc.SubmitChanges();

            bill_master bil = (from x in dc.GetTable <bill_master>()
                               where x.billid == BillId
                               select x).SingleOrDefault();
            item cos = (from x in dc.GetTable <item>()
                        where x.itemid == itemid
                        select x).SingleOrDefault();

            bil.total += (cos.cost_per_item * qty);

            dc.SubmitChanges();

            return(true);
        }
Exemplo n.º 2
0
        public bool Insert(bill_item c)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(myconnstrng);

            try
            {
                String     sql = "INSERT INTO bill_item(bill_id,product_id,quantity,total_price) values(@bill_id,@product_id,@quantity,@total_price)";
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@bill_id", c.bill_id);
                cmd.Parameters.AddWithValue("@product_id", c.product_id);
                cmd.Parameters.AddWithValue("@quantity", c.quantity);
                cmd.Parameters.AddWithValue("@total_price", c.total_price);
                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
        private void button7_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                if (regbtn.Checked)
                {
                    if (float.Parse(balancelabel.Text) <= float.Parse(payablelabel.Text))
                    {
                        MessageBox.Show("Insufficient Balance");
                    }
                    else
                    {
                        float var = float.Parse(balancelabel.Text) - float.Parse(payablelabel.Text);
                        cf.Deduct(Int32.Parse(cidbox.Text.Trim()), var);
                        balancelabel.Text = var.ToString();
                        foreach (DataGridViewRow row in cartlist.Rows)
                        {
                            if (row.Cells[3].Value != null)
                            {
                                sf.deduce(Int32.Parse(row.Cells[3].Value.ToString()), Int32.Parse(row.Cells[2].Value.ToString()));
                            }
                        }
                        foreach (DataGridViewRow row in cartlist.Rows)
                        {
                            if (row.Cells[3].Value != null)
                            {
                                bill_item bi = new bill_item();
                                bi.bill_id     = Int32.Parse(bidbox.Text.Trim());
                                bi.product_id  = Int32.Parse(row.Cells[3].Value.ToString());
                                bi.quantity    = Int32.Parse(row.Cells[2].Value.ToString());
                                bi.total_price = float.Parse(row.Cells[1].Value.ToString());
                                bf.Insert(bi);
                            }
                        }
                        Bill f = new Bill();
                        f.bill_id        = Int32.Parse(bidbox.Text.Trim());
                        f.customer_id    = Int32.Parse(cidbox.Text.Trim());
                        f.amount         = float.Parse(amountbox.Text.Trim());
                        f.final_discount = float.Parse(discountbox.Text.Trim());
                        f.grand_total    = float.Parse(payablelabel.Text);
                        f.date_time      = DateTime.Now;
                        bf.bill_insert(f);


                        cartlist.DataSource = tcf.Select();
                        try
                        {
                            var    pdfDoc = new Document(PageSize.LETTER, 40f, 40f, 60f, 60f);
                            string path   = $"C:\\Users\\Deepu\\Desktop\\Test.pdf";
                            PdfWriter.GetInstance(pdfDoc, new FileStream(path, FileMode.OpenOrCreate));
                            pdfDoc.Open();
                            var spacer = new Paragraph("")
                            {
                                SpacingBefore = 10f,
                                SpacingAfter  = 10f,
                            };
                            iTextSharp.text.Font times        = FontFactory.GetFont("TIMES_ROMAN", 25, iTextSharp.text.Font.BOLD);
                            iTextSharp.text.Font normal       = FontFactory.GetFont("TIMES_ROMAN", 12);
                            iTextSharp.text.Font normalbold   = FontFactory.GetFont("TIMES_ROMAN", 12, iTextSharp.text.Font.BOLD);
                            iTextSharp.text.Font normalitalic = FontFactory.GetFont("FREESTYLE_SCRIPT", 10, iTextSharp.text.Font.ITALIC);
                            var spacer1 = new Paragraph("LA FRESCO - The IITI Facilitation Center", times)
                            {
                                SpacingBefore = 10f,
                                SpacingAfter  = 10f,
                            };
                            pdfDoc.Add(spacer);
                            pdfDoc.Add(spacer);
                            spacer1.Alignment = Element.ALIGN_CENTER;
                            pdfDoc.Add(spacer1);

                            Chunk     glue = new Chunk(new VerticalPositionMark());
                            Paragraph P    = new Paragraph("BILL ID: " + bidbox.Text.Trim(), normal);
                            P.Add(new Chunk(glue));
                            P.Add("Date: " + DateTime.Now.ToString());
                            pdfDoc.Add(P);



                            //IMAGE

                            //var imagepath = @"C:\Users\Deepu\Desktop\thumb.png";
                            //using (FileStream fs = new FileStream(imagepath, FileMode.Open))
                            //{
                            //   var png = iTextSharp.text.Image.GetInstance(System.Drawing.Image.FromStream(fs), ImageFormat.Png);
                            //  png.ScalePercent(5f);
                            // png.SetAbsolutePosition(pdfDoc.Left, pdfDoc.Top);
                            //pdfDoc.Add(png);
                            //}



                            //pdfDoc.Add(spacer);


                            var spacer2 = new Paragraph("NAME: " + textBox1.Text.Trim(), normal)
                            {
                                SpacingBefore = 10f,
                                SpacingAfter  = 10f,
                            };

                            pdfDoc.Add(spacer2);
                            pdfDoc.Add(spacer);

                            var columnCount = cartlist.ColumnCount;

                            var columnWidths = new[] { 0.75f, .75f, .75f, 0.75f };

                            var table = new PdfPTable(columnWidths)
                            {
                                HorizontalAlignment = Left,
                                WidthPercentage     = 100,
                                DefaultCell         = { MinimumHeight = 22f }
                            };

                            var cell = new PdfPCell(new Phrase("Product Details "))
                            {
                                Colspan             = columnCount,
                                HorizontalAlignment = 1,  //0=Left, 1=Centre, 2=Right
                                MinimumHeight       = 30f
                            };
                            cell.BorderWidthBottom = 1f;
                            cell.BorderWidthLeft   = 0f;
                            cell.BorderWidthRight  = 0f;
                            cell.BorderWidthTop    = 1f;

                            table.AddCell(cell);

                            //Adding Header row
                            foreach (DataGridViewColumn column in cartlist.Columns)
                            {
                                PdfPCell ycell = new PdfPCell(new Phrase(column.HeaderText));
                                ycell.FixedHeight       = 25f;
                                ycell.BorderWidthBottom = 1f;
                                ycell.BorderWidthLeft   = 0f;
                                ycell.BorderWidthRight  = 0f;
                                ycell.BorderWidthTop    = 0f;

                                // ycell.BackgroundColor = new iTextSharp.text.Color(240, 240, 240);
                                table.AddCell(ycell);
                            }

                            /*    cartlist.Columns
                             *      .OfType<DataGridViewColumn>()
                             *      .ToList()
                             *      .ForEach(c =>
                             *      c.BorderWidthBottom = 1f,
                             *  c.BorderWidthLeft= 0f,
                             *  c.BorderWidthRight = 0f,
                             *  c.BorderWidthTop = 0f,
                             *
                             *      table.AddCell(c.Name)); */


                            /*    cartlist.Rows
                             *     .OfType<DataGridViewRow>()
                             *     .ToList()
                             *     .ForEach(r =>
                             *     {
                             *         var cells = r.Cells.OfType<DataGridViewCell>().ToList();
                             *         cells.ForEach(c => table.AddCell(c.Value.ToString()));
                             *     }); */

                            table.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER;
                            //Adding DataRow
                            foreach (DataGridViewRow row in cartlist.Rows)
                            {
                                foreach (DataGridViewCell cellx in row.Cells)
                                {
                                    if (cellx.Value != null)
                                    {
                                        table.AddCell(cellx.Value.ToString());
                                    }
                                }
                            }

                            pdfDoc.Add(table);

                            var spacer3 = new Paragraph("TOTAL AMOUNT PAYABLE: ₹" + payablelabel.Text.Trim(), normalbold)
                            {
                                SpacingBefore = 10f,
                                SpacingAfter  = 5f,
                            };
                            int savings;
                            savings = Int32.Parse(amountbox.Text.Trim()) - Int32.Parse(payablelabel.Text.Trim());
                            var spacer4 = new Paragraph("YOUR SAVINGS OVER MRP: ₹" + savings.ToString(), normalbold)
                            {
                                SpacingBefore = 5f,
                                SpacingAfter  = 20f,
                            };
                            var spacer5 = new Paragraph("THANK YOU FOR VISITING LAFRESCO! HAVE A NICE DAY!", normalitalic)
                            {
                                SpacingBefore = 10f,
                                SpacingAfter  = 10f,
                            };
                            spacer5.Alignment = Element.ALIGN_CENTER;

                            pdfDoc.Add(spacer3);
                            pdfDoc.Add(spacer4);
                            pdfDoc.Add(spacer5);


                            pdfDoc.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
                else if (unregbtn.Checked)
                {
                    try
                    {
                        var    pdfDoc = new Document(PageSize.LETTER, 40f, 40f, 60f, 60f);
                        string path   = $"C:\\Users\\Deepu\\Desktop\\Test.pdf";
                        PdfWriter.GetInstance(pdfDoc, new FileStream(path, FileMode.OpenOrCreate));
                        pdfDoc.Open();
                        var spacer = new Paragraph("")
                        {
                            SpacingBefore = 10f,
                            SpacingAfter  = 10f,
                        };
                        iTextSharp.text.Font times        = FontFactory.GetFont("TIMES_ROMAN", 25, iTextSharp.text.Font.BOLD);
                        iTextSharp.text.Font normal       = FontFactory.GetFont("TIMES_ROMAN", 12);
                        iTextSharp.text.Font normalbold   = FontFactory.GetFont("TIMES_ROMAN", 12, iTextSharp.text.Font.BOLD);
                        iTextSharp.text.Font normalitalic = FontFactory.GetFont("FREESTYLE_SCRIPT", 10, iTextSharp.text.Font.ITALIC);
                        var spacer1 = new Paragraph("LA FRESCO - The IITI Facilitation Center", times)
                        {
                            SpacingBefore = 10f,
                            SpacingAfter  = 10f,
                        };
                        pdfDoc.Add(spacer);
                        pdfDoc.Add(spacer);
                        spacer1.Alignment = Element.ALIGN_CENTER;
                        pdfDoc.Add(spacer1);

                        Chunk     glue = new Chunk(new VerticalPositionMark());
                        Paragraph P    = new Paragraph("BILL ID: " + bidbox.Text.Trim(), normal);
                        P.Add(new Chunk(glue));
                        P.Add("Date: " + DateTime.Now.ToString());
                        pdfDoc.Add(P);



                        //IMAGE

                        //var imagepath = @"C:\Users\Deepu\Desktop\thumb.png";
                        //using (FileStream fs = new FileStream(imagepath, FileMode.Open))
                        //{
                        //   var png = iTextSharp.text.Image.GetInstance(System.Drawing.Image.FromStream(fs), ImageFormat.Png);
                        //  png.ScalePercent(5f);
                        // png.SetAbsolutePosition(pdfDoc.Left, pdfDoc.Top);
                        //pdfDoc.Add(png);
                        //}



                        //pdfDoc.Add(spacer);


                        var spacer2 = new Paragraph("NAME: " + textBox1.Text.Trim(), normal)
                        {
                            SpacingBefore = 10f,
                            SpacingAfter  = 10f,
                        };

                        pdfDoc.Add(spacer2);
                        pdfDoc.Add(spacer);

                        var columnCount = cartlist.ColumnCount;

                        var columnWidths = new[] { 0.75f, .75f, .75f, 0.75f };

                        var table = new PdfPTable(columnWidths)
                        {
                            HorizontalAlignment = Left,
                            WidthPercentage     = 100,
                            DefaultCell         = { MinimumHeight = 22f }
                        };

                        var cell = new PdfPCell(new Phrase("Product Details "))
                        {
                            Colspan             = columnCount,
                            HorizontalAlignment = 1,  //0=Left, 1=Centre, 2=Right
                            MinimumHeight       = 30f
                        };
                        cell.BorderWidthBottom = 1f;
                        cell.BorderWidthLeft   = 0f;
                        cell.BorderWidthRight  = 0f;
                        cell.BorderWidthTop    = 1f;

                        table.AddCell(cell);

                        //Adding Header row
                        foreach (DataGridViewColumn column in cartlist.Columns)
                        {
                            PdfPCell ycell = new PdfPCell(new Phrase(column.HeaderText));
                            ycell.FixedHeight       = 25f;
                            ycell.BorderWidthBottom = 1f;
                            ycell.BorderWidthLeft   = 0f;
                            ycell.BorderWidthRight  = 0f;
                            ycell.BorderWidthTop    = 0f;

                            // ycell.BackgroundColor = new iTextSharp.text.Color(240, 240, 240);
                            table.AddCell(ycell);
                        }

                        /*    cartlist.Columns
                         *      .OfType<DataGridViewColumn>()
                         *      .ToList()
                         *      .ForEach(c =>
                         *      c.BorderWidthBottom = 1f,
                         *  c.BorderWidthLeft= 0f,
                         *  c.BorderWidthRight = 0f,
                         *  c.BorderWidthTop = 0f,
                         *
                         *      table.AddCell(c.Name)); */


                        /*    cartlist.Rows
                         *     .OfType<DataGridViewRow>()
                         *     .ToList()
                         *     .ForEach(r =>
                         *     {
                         *         var cells = r.Cells.OfType<DataGridViewCell>().ToList();
                         *         cells.ForEach(c => table.AddCell(c.Value.ToString()));
                         *     }); */

                        table.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER;
                        //Adding DataRow
                        foreach (DataGridViewRow row in cartlist.Rows)
                        {
                            foreach (DataGridViewCell cellx in row.Cells)
                            {
                                if (cellx.Value != null)
                                {
                                    table.AddCell(cellx.Value.ToString());
                                }
                            }
                        }

                        pdfDoc.Add(table);

                        var spacer3 = new Paragraph("TOTAL AMOUNT PAYABLE: ₹" + payablelabel.Text.Trim(), normalbold)
                        {
                            SpacingBefore = 10f,
                            SpacingAfter  = 5f,
                        };
                        int savings;
                        savings = Int32.Parse(amountbox.Text.Trim()) - Int32.Parse(payablelabel.Text.Trim());
                        var spacer4 = new Paragraph("YOUR SAVINGS OVER MRP: ₹" + savings.ToString(), normalbold)
                        {
                            SpacingBefore = 5f,
                            SpacingAfter  = 20f,
                        };
                        var spacer5 = new Paragraph("THANK YOU FOR VISITING LAFRESCO! HAVE A NICE DAY!", normalitalic)
                        {
                            SpacingBefore = 10f,
                            SpacingAfter  = 10f,
                        };
                        spacer5.Alignment = Element.ALIGN_CENTER;

                        pdfDoc.Add(spacer3);
                        pdfDoc.Add(spacer4);
                        pdfDoc.Add(spacer5);


                        pdfDoc.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            this.Refresh();
        }