Beispiel #1
0
        private void SetInvoiceData(Graphics g, System.Drawing.Printing.PrintPageEventArgs e)
        {// Set Invoice Table:
            string  FieldValue     = "";
            int     CurrentRecord  = 0;
            int     RecordsPerPage = 0; // twenty items in a page
            decimal Amount         = 0;
            bool    StopReading    = false;
            // Set Table Head:
            //            int xProductID = leftMargin;
            int xProductID = leftMargin - 90;

            for (int i = 10; i <= 250; i++)
            {
                g.DrawString("-", InvoiceTitle, BlueBrush, i, CurrentY);
            }
            CurrentY = CurrentY + InvoiceFontHeight;
            g.DrawString("Sr", InvoiceTitle, BlueBrush, xProductID, CurrentY);

            int xProductName = xProductID + (int)g.MeasureString("Products", InvoiceFont).Width + 4;

            g.DrawString("Products", InvoiceTitle, BlueBrush, xProductName - 30, CurrentY);

            int xQuantity = xProductName + (int)g.MeasureString("Qty", InvoiceFont).Width + 72;

            g.DrawString("Qty", InvoiceTitle, BlueBrush, xQuantity - 50, CurrentY);


            int xUnit = xQuantity + (int)g.MeasureString("Unit", InvoiceFont).Width + 4;

            g.DrawString("Unit", InvoiceTitle, BlueBrush, xUnit - 55, CurrentY);

            int xRate = xUnit + (int)g.MeasureString("Rate", InvoiceFont).Width + 4;

            g.DrawString("Rate", InvoiceTitle, BlueBrush, xRate - 60, CurrentY);

            AmountPosition = xRate + (int)g.MeasureString("Amount", InvoiceFont).Width + 4;
            g.DrawString("Amount", InvoiceTitle, BlueBrush, AmountPosition - 50, CurrentY);
            // Set Invoice Table:
            CurrentY = CurrentY + InvoiceFontHeight + 8;

            for (int i = 10; i <= 250; i++)
            {
                g.DrawString("-", InvoiceTitle, BlueBrush, i, CurrentY);
            }

            CurrentY = CurrentY + InvoiceFontHeight + 8;

            AppConfiguration a              = new AppConfiguration();
            float            TotalQuantity  = 0;
            float            TotalAmount    = 0;
            float            TotalTaxAmount = 0;
            float            ItemValue      = 0;

            try
            {
                using (SqlConnection con = new SqlConnection(ConnString))
                {
                    using (SqlCommand cmd = new SqlCommand("GetOrderForCashMemoPrintingByOrderID", con))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@OrderID", a.OrderID);
                        cmd.CommandTimeout = 0;
                        con.Open();
                        SqlDataAdapter da = new SqlDataAdapter(cmd);
                        DataTable      dt = new DataTable();
                        da.Fill(dt);
                        if (dt.Rows.Count > 0)
                        {
                            RecordsPerPage = Convert.ToInt32(dt.Rows.Count);
                            while (CurrentRecord < RecordsPerPage)
                            {
                                DataRow dr = (DataRow)dt.Rows[CurrentRecord];
                                FieldValue = "" + dr["SNO"];
                                g.DrawString(FieldValue, InvoiceFont, BlackBrush, xProductID, CurrentY);
                                FieldValue = "" + dr["ItemName"];
                                // if Length of (Product Name) > 20, Draw 20 character only
                                //if (FieldValue.Length > 50)
                                //    FieldValue = FieldValue.Remove(50, FieldValue.Length - 50);
                                g.DrawString(FieldValue, InvoiceFont, BlackBrush, xProductName - 30, CurrentY);
                                CurrentY   = CurrentY + InvoiceFontHeight;
                                FieldValue = "" + dr["Qty"];
                                float  Quantity       = float.Parse(FieldValue);
                                string taxamount      = "" + dr["TaxAmount"];
                                string amount         = "" + dr["Amount"];
                                float  QuantityAmount = float.Parse(taxamount) + float.Parse(amount);
                                TotalAmount = TotalAmount + float.Parse(taxamount) + float.Parse(amount);
                                ItemValue   = ItemValue + float.Parse(amount);
                                float RateAmount = QuantityAmount / Quantity;
                                TotalQuantity = TotalQuantity + float.Parse(FieldValue);
                                g.DrawString(FieldValue, InvoiceFont, BlackBrush, xQuantity - 50, CurrentY);
                                FieldValue = "" + dr["Unit"];
                                g.DrawString(FieldValue, InvoiceFont, BlackBrush, xUnit - 55, CurrentY);
                                FieldValue = String.Format("{0:0.00}", RateAmount);
                                g.DrawString(FieldValue, InvoiceFont, BlackBrush, xRate - 60, CurrentY);

                                // Format Extended Price and Align to Right:
                                FieldValue = String.Format("{0:0.00}", (float.Parse(amount) + float.Parse(taxamount)));

                                int xAmount = AmountPosition + (int)g.MeasureString("Amount", InvoiceFont).Width;
                                xAmount    = xAmount - (int)g.MeasureString(FieldValue, InvoiceFont).Width;
                                FieldValue = String.Format("{0:0.00}", QuantityAmount);
                                g.DrawString(FieldValue, InvoiceFont, BlackBrush, xAmount - 50, CurrentY);
                                CurrentY = CurrentY + InvoiceFontHeight;

                                int xTax = leftMargin - 60;
                                TotalTaxAmount = TotalTaxAmount + float.Parse(taxamount);
                                //                                TotalAmount = TotalAmount + TotalTaxAmount;
                                FieldValue        = "T " + String.Format("{0:0.00}", dr["TaxRate"]) + "% " + String.Format("{0:0.00}", dr["TaxAmount"]);
                                PaidAmount        = String.Format("{0:0.00}", dr["PaidAmount"]);
                                OutstandingAmount = String.Format("{0:0.00}", dr["OutstandingAmount"]);
                                g.DrawString(FieldValue, InvoiceFont, BlackBrush, xTax, CurrentY);


                                CurrentY = CurrentY + InvoiceFontHeight;
                                if (CurrentRecord == RecordsPerPage)
                                {
                                    StopReading = true;
                                    break;
                                }

                                CurrentRecord++;
                            }
                            for (int i = 10; i <= 250; i++)
                            {
                                g.DrawString("-", InvoiceTitle, BlueBrush, i, CurrentY);
                            }

                            CurrentY = CurrentY + InvoiceFontHeight;

                            int xTotal = leftMargin - 90;
                            FieldValue = "Total Qty:           " + String.Format("{0:0.00}", TotalQuantity) + "  Amt:              " + String.Format("{0:0.00}", TotalAmount);
                            g.DrawString(FieldValue, InvoiceTitle, BlueBrush, xTotal, CurrentY);

                            CurrentY = CurrentY + InvoiceFontHeight;
                            int    xCurrency   = leftMargin - 90;
                            string FieldValue1 = "";
                            FieldValue = CurrencyConverter.AmountInWords(Convert.ToDecimal(TotalAmount));
                            if (FieldValue.Length > 40)
                            {
                                FieldValue1 = FieldValue.Substring(41, FieldValue.Length - 41);
                                FieldValue  = FieldValue.Substring(0, 41);
                            }
                            g.DrawString(FieldValue, InvoiceFont, BlueBrush, xTotal, CurrentY);
                            CurrentY = CurrentY + InvoiceFontHeight;
                            g.DrawString(FieldValue1, InvoiceFont, BlueBrush, xTotal, CurrentY);
                            CurrentY = CurrentY + InvoiceFontHeight;
                            for (int i = 10; i <= 250; i++)
                            {
                                g.DrawString("-", InvoiceTitle, BlueBrush, i, CurrentY);
                            }
                            CurrentY = CurrentY + InvoiceFontHeight;

                            int xTaxAmount = leftMargin - 90;
                            FieldValue = "Item Value:                                            " + String.Format("{0:0.00}", ItemValue);
                            g.DrawString(FieldValue, InvoiceFont, BlackBrush, xTotal, CurrentY);
                            CurrentY = CurrentY + InvoiceFontHeight;

                            try
                            {
                                using (SqlConnection con1 = new SqlConnection(ConnString))
                                {
                                    using (SqlCommand cmd1 = new SqlCommand("GetTaxGroupingDetailsForPrintingByOrderID", con1))
                                    {
                                        cmd1.CommandType = CommandType.StoredProcedure;
                                        cmd1.Parameters.AddWithValue("@OrderID", a.OrderID);
                                        cmd1.CommandTimeout = 0;
                                        con1.Open();
                                        SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
                                        DataTable      dt1 = new DataTable();
                                        da1.Fill(dt1);
                                        CurrentRecord = 0;
                                        if (dt1.Rows.Count > 0)
                                        {
                                            RecordsPerPage = Convert.ToInt32(dt1.Rows.Count);
                                            while (CurrentRecord < RecordsPerPage)
                                            {
                                                int     xTaxType = leftMargin - 90;
                                                DataRow dr       = (DataRow)dt1.Rows[CurrentRecord];
//                                                FieldValue = "" + dr["TaxType"];
                                                FieldValue = String.Format("{0:0.00}", dr["TaxType"]) + "%                                             " + String.Format("{0:0.00}", dr["TaxAmount"]);
                                                g.DrawString(FieldValue, InvoiceFont, BlackBrush, xTaxType, CurrentY);
                                                CurrentRecord = CurrentRecord + 1;
                                                CurrentY      = CurrentY + InvoiceFontHeight;
                                                if (CurrentRecord == RecordsPerPage)
                                                {
                                                    break;
                                                }
                                            }

                                            CurrentY = CurrentY + InvoiceFontHeight;
                                            int CurrentX = leftMargin;
                                            for (int i = 10; i <= 250; i++)
                                            {
                                                g.DrawString("-", InvoiceTitle, BlueBrush, i, CurrentY);
                                            }

                                            CurrentY = CurrentY + InvoiceFontHeight;
                                            int xPaidAmountLabel = leftMargin - 90;
                                            FieldValue = "Total Paid Amount:                                                  ";
                                            g.DrawString(FieldValue, InvoiceFont, BlueBrush, xPaidAmountLabel, CurrentY);
                                            g.DrawString(PaidAmount, InvoiceFont, BlueBrush, xPaidAmountLabel + 250 - (FieldValue.Length), CurrentY);
                                            CurrentY = CurrentY + InvoiceFontHeight;
                                            int xOutstanding = leftMargin - 90;
                                            FieldValue = "Total Due Amount :                                                  ";
                                            g.DrawString(FieldValue, InvoiceFont, BlueBrush, xOutstanding, CurrentY);
                                            g.DrawString(OutstandingAmount, InvoiceFont, BlueBrush, xOutstanding + 250 - (FieldValue.Length), CurrentY);
                                            CurrentY = CurrentY + InvoiceFontHeight;
                                            for (int i = 10; i <= 250; i++)
                                            {
                                                g.DrawString("-", InvoiceTitle, BlueBrush, i, CurrentY);
                                            }

                                            CurrentY   = CurrentY + InvoiceFontHeight;
                                            CurrentY   = CurrentY + InvoiceFontHeight;
                                            CurrentY   = CurrentY + InvoiceFontHeight;
                                            CurrentY   = CurrentY + InvoiceFontHeight;
                                            CurrentY   = CurrentY + InvoiceFontHeight;
                                            CurrentY   = CurrentY + InvoiceFontHeight;
                                            CurrentY   = CurrentY + InvoiceFontHeight;
                                            FieldValue = "||  THANK YOU VISIT AGAIN ||";
                                            int lenSalutation = (int)g.MeasureString(FieldValue, InvSalutation).Width;
                                            // Set Titles Left:
                                            int xSalutation = CurrentX + (InvoiceWidth - lenSalutation) / 2;
                                            g.DrawString(FieldValue, InvSalutation, BlueBrush, xSalutation, CurrentY);
                                        }
                                    }
                                }
                            }
                            catch (Exception)
                            {
                            }



                            g.Dispose();

                            if (CurrentRecord < RecordsPerPage)
                            {
                                e.HasMorePages = false;
                            }
                            else
                            {
                                e.HasMorePages = true;
                            }

                            if (StopReading)
                            {
                                SetInvoiceTotal(g);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Alert Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        private void SetInvoiceHead(Graphics g)
        {
            AppConfiguration a = new AppConfiguration();

            ReadInvoiceHead(a.OrderID);

            CurrentY = topMargin;
            CurrentX = leftMargin;
            int ImageHeight = 0;

            // Draw Invoice image:
            if (System.IO.File.Exists(InvImage))
            {
                Bitmap oInvImage = new Bitmap(InvImage);
                // Set Image Left to center Image:
                int xImage = CurrentX + (InvoiceWidth - oInvImage.Width) / 2;
                ImageHeight = oInvImage.Height; // Get Image Height
                g.DrawImage(oInvImage, xImage, CurrentY);
            }

            InvTitleHeight    = (int)(InvTitleFont.GetHeight(g));
            InvSubTitleHeight = (int)(InvSubTitleFont.GetHeight(g));

            // Get Titles Length:
            int lenInvTitle     = (int)g.MeasureString(InvTitle, InvTitleFont).Width;
            int lenInvSubTitle1 = (int)g.MeasureString(InvSubTitle1, InvSubTitleFont).Width;
            int lenInvSubTitle2 = (int)g.MeasureString(InvSubTitle2, InvSubTitleFont).Width;
            int lenInvSubTitle3 = (int)g.MeasureString(InvSubTitle3, InvSubTitleFont).Width;
            // Set Titles Left:
            int xInvTitle     = CurrentX + (InvoiceWidth - lenInvTitle) / 2;
            int xInvSubTitle1 = CurrentX + (InvoiceWidth - lenInvSubTitle1) / 2;
            int xInvSubTitle2 = CurrentX + (InvoiceWidth - lenInvSubTitle2) / 2;
            int xInvSubTitle3 = CurrentX + (InvoiceWidth - lenInvSubTitle3) / 2;

            // Draw Invoice Head:
            if (InvTitle != "")
            {
                CurrentY = CurrentY + ImageHeight;
                g.DrawString(InvTitle, InvTitleFont, BlueBrush, xInvTitle, CurrentY);
            }
            if (InvSubTitle1 != "")
            {
                CurrentY = CurrentY + InvTitleHeight;
                g.DrawString(InvSubTitle1, InvTitleFont, BlueBrush, xInvSubTitle1, CurrentY);
            }
            if (InvSubTitle2 != "")
            {
                CurrentY = CurrentY + InvSubTitleHeight;
                g.DrawString(InvSubTitle2, InvTitleFont, BlueBrush, xInvSubTitle2, CurrentY);
            }
            if (InvSubTitle3 != "")
            {
                CurrentY = CurrentY + InvSubTitleHeight;
                g.DrawString(InvSubTitle3, InvTitleFont, BlueBrush, xInvSubTitle3, CurrentY);
            }

            // Draw line:
            //CurrentY = CurrentY + InvSubTitleHeight + 8;
            //g.DrawLine(new Pen(Brushes.Black, 2), CurrentX, CurrentY, rightMargin, CurrentY);


            CurrentY = CurrentY + InvSubTitleHeight;
            String FieldValue    = "CASH MEMO";
            int    lenSalutation = (int)g.MeasureString(FieldValue, InvSalutation).Width;
            // Set Titles Left:
            int xSalutation = CurrentX + (InvoiceWidth - lenSalutation) / 2;

            g.DrawString(FieldValue, InvSalutation, BlueBrush, xSalutation, CurrentY);

            CurrentY      = CurrentY + InvSubTitleHeight;
            FieldValue    = "==>>" + InvoiceType + "<<==";
            lenSalutation = (int)g.MeasureString(FieldValue, InvSalutation).Width;
            // Set Titles Left:
            xSalutation = CurrentX + (InvoiceWidth - lenSalutation) / 2;
            g.DrawString(FieldValue, InvSalutation, BlueBrush, xSalutation, CurrentY);

            CurrentY = CurrentY + InvSubTitleHeight;
        }
Beispiel #3
0
        private void frmHome_Load(object sender, EventArgs e)
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\SMS";
            //if (!Directory.Exists(path))
            //{
            //    this.Visible = false;
            //    new frmSqlSetting().Show();
            //}

            int              counter = 0;
            string           line;
            AppConfiguration c = new AppConfiguration();

            if (File.Exists(path + "\\config.txt"))
            {
                System.IO.StreamReader file = new System.IO.StreamReader(path + "\\config.txt");
                while ((line = file.ReadLine()) != null)
                {
                    if (counter == 0)
                    {
                        c.CounterID = Convert.ToInt32(line);
                    }
                    else if (counter == 1)
                    {
                        c.TerminalID = Convert.ToInt32(line);
                    }

                    counter++;
                }

                file.Close();
                System.Console.WriteLine("There were {0} lines.", counter);
                // Suspend the screen.
                System.Console.ReadLine();
            }

            if (File.Exists(path + "\\server.txt"))
            {
                counter = 0;
                SQLServer s = new SQLServer();
                System.IO.StreamReader serverfile = new System.IO.StreamReader(path + "\\server.txt");
                while ((line = serverfile.ReadLine()) != null)
                {
                    if (counter == 0)
                    {
                        s.ServerIP = "" + line;
                    }
                    else if (counter == 1)
                    {
                        s.ServerUserID = "" + line;
                    }
                    else if (counter == 2)
                    {
                        s.ServerPassword = "" + line;
                    }

                    counter++;
                }

                serverfile.Close();
                System.Console.WriteLine("There were {0} lines.", counter);
                // Suspend the screen.
                System.Console.ReadLine();

                string  AppConnectionString = String.Format("Data Source = {0}; Initial Catalog = SMS; Persist Security Info = True; User ID = {1}; Password = {2}", s.ServerIP, s.ServerUserID, s.ServerPassword);
                Globals g = new Globals();
                g.ConnString = AppConnectionString;
            }

            if (!File.Exists(path + "\\server.txt"))
            {
                this.Visible = false;
                new frmSqlSetting().Show();
            }
            else if (!File.Exists(path + "\\config.txt"))
            {
                this.Visible = false;
                new frmSettings().Show();
            }
        }
Beispiel #4
0
        public void LOAD_SUB_CATEGORY_BUTTON(String CategoryName)
        {
            try
            {
                using (SqlConnection con = new SqlConnection(ConnString))
                {
                    using (SqlCommand cmd = new SqlCommand("GetAllInventryByCategoryName", con))
                    {
                        cmd.CommandType    = CommandType.StoredProcedure;
                        cmd.CommandTimeout = 0;
                        con.Open();
                        SqlDataAdapter da = new SqlDataAdapter(cmd);
                        cmd.Parameters.AddWithValue("@CategoryName", CategoryName);
                        DataTable dt = new DataTable();
                        da.Fill(dt);
                        int cnt    = 0;
                        int Left   = 19;
                        int Top    = 19;
                        int Repeat = 0;

                        if (dt.Rows.Count > 0)
                        {
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                DataRow dr = (DataRow)dt.Rows[i];
                                if (cnt == 5)
                                {
                                    Left   = 19;
                                    Top    = Top + 101;
                                    Repeat = +1;
                                    cnt    = 0;
                                }
                                Button button = new Button();
                                button.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));
                                button.Font      = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                                button.Location  = new System.Drawing.Point(Left, Top);
                                button.Name      = "" + dr["InvName"];
                                button.Size      = new System.Drawing.Size(141, 95);
                                button.TabIndex  = i;
                                button.Text      = "" + dr["InvName"].ToString().ToUpper();;
                                button.UseVisualStyleBackColor = false;
                                groupSubCategory.Controls.Add(button);
                                cnt  = cnt + 1;
                                Left = Left + 147;
                                AppConfiguration a   = new AppConfiguration();
                                int TokenPrintStatus = Check_Token_Print_Status(a.TerminalID);
                                if (TokenPrintStatus == 0)
                                {
                                    button.Enabled = true;
                                }
                                else
                                {
                                    button.Enabled = false;
                                }

                                button.Click += delegate
                                {
                                    // Your code
                                    String SubCategory = button.Text;
                                    Pass_Inventry_Info(SubCategory);
                                    this.Visible = false;
                                    this.Close();
                                    this.Hide();
                                    if (Application.OpenForms.OfType <frmNewOrder>().Any())
                                    {
                                        frmNewOrder frm = new frmNewOrder();
                                        frm.Visible = false;
                                        frm.Close();
                                        frm.Hide();
                                    }
                                    frmNewOrder frm1 = new frmNewOrder();
                                    frm1.Show();
                                    //                                    MessageBox.Show(SubCategory);
                                };
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Beispiel #5
0
        private void frmPaymentHistory_Load(object sender, EventArgs e)
        {
            AppConfiguration a = new AppConfiguration();

            LoadPaymentHistory(a.TokenNo);
        }