Click here to Skip to main content
14,426,851 members
Rate this:
Please Sign up or sign in to vote.
See more:
This is my printing codes
Now it's printing as default font size. Now I want to change font size to print text, give me solution for that.

Thanks for advance.


public override string PrintKOTOrders(string connectionString, long[] orderDetailNumbers, string userName, bool isReprint)
{
    string error = string.Empty;

    RawPrinterHelper receiptPrinter = new RawPrinterHelper();

    ReceiptFunction receiptFunction = new ReceiptFunction();
    

    DataSet ds = receiptFunction.GetKOTNoteFromDataSet(connectionString, orderDetailNumbers);

    DataTable headerTable = new DataTable();
    DataTable foodTable = new DataTable();
    DataTable foodModifierTable = new DataTable();

    DataTable foodPrinters = new DataTable();
    DataTable foodModifierPrinters = new DataTable();
    DataTable reciprtPrinters = new DataTable();

    if (ds.Tables.Count > 0)
    {
        headerTable = ds.Tables[0];

        if (ds.Tables.Count > 1)
        {
            foodTable = ds.Tables[1];

            string[] printerName = { "PrinterName", "FoodDept" };

            foodPrinters = this.GetDistinctRecords(foodTable, printerName);

            if (ds.Tables.Count > 2)
            {
                foodModifierTable = ds.Tables[2];

                foodModifierPrinters = this.GetDistinctRecords(foodModifierTable, printerName);
            }

            reciprtPrinters = foodPrinters.Copy();
            reciprtPrinters.Merge(foodModifierPrinters);

            reciprtPrinters = this.GetDistinctRecords(reciprtPrinters, printerName);

        }
        else
        {
            error = "No Food Records";
        }
    }
    else
    {
        error = "No Header Records";
    }

    string displayString = string.Empty;

    foreach (DataRow printer in reciprtPrinters.Rows)
    {
        receiptPrinter.PrinterName = printer["PrinterName"].ToString();

        if (isReprint)
        {
            this.PrintImage.PrintDuplicateImage(receiptPrinter, 28);
        }
        
        displayString += Environment.NewLine;
        displayString += "Order No   : " + headerTable.Rows[0]["OrderId"].ToString().Trim() + "/" + printer["FoodDept"].ToString().Trim() + Environment.NewLine;
        displayString += "Order Date : " + headerTable.Rows[0]["OrderDate"].ToString() + Environment.NewLine;
        displayString += "Table(s)   : " + headerTable.Rows[0]["TableblNos"].ToString().Trim() + Environment.NewLine;
        displayString += "Res No     : " + headerTable.Rows[0]["ReservationID"].ToString().Trim() + "  No of Guest(s): " + headerTable.Rows[0]["NoOfGuest"].ToString().Trim() + Environment.NewLine;
        displayString += "Order Taken: " + userName + Environment.NewLine;
        displayString += "C  Item                         Quantity" + Environment.NewLine;
        displayString += "----------------------------------------" + Environment.NewLine;
        


        this.Print(receiptPrinter, displayString);
        displayString = string.Empty;

        string foodDepartmentID = printer["FoodDept"].ToString();

        string filter = string.Format("FoodDept = '{0}'", foodDepartmentID);
        DataRow[] foodPrinter = foodTable.Select(filter);

        foreach (DataRow foodRow in foodPrinter)
        {
            this.PrintKOTLines(foodRow, false, receiptPrinter, false);
        }

        filter = string.Empty;
        filter = string.Format("FoodDept = '{0}' AND ModifierString is NOT NULL", foodDepartmentID);

        DataRow[] foodModifierPrinter = foodModifierTable.Select(filter);

        foreach (DataRow foodRow in foodModifierPrinter)
        {
            this.PrintKOTLines(foodRow, false, receiptPrinter, false);

            // modifier print section

            string modifiers = foodRow["ModifierString"].ToString();

            string[] modifierArray = modifiers.Split(',');
            List<string> modifierList = new List<string>(modifierArray);

            var grouped = modifierList.GroupBy(s => s).Select(g => new { FoodID = g.Key.ToString().Trim(), Count = g.Count() });

            foreach (var item in grouped)
            {
                filter = string.Empty;
                filter = string.Format("FoodDept = '{0}' AND ModifierString is NULL AND  FoodID = '{1}'", foodDepartmentID, item.FoodID);

                DataRow[] modifierPrinter = foodModifierTable.Select(filter);

                if (modifierPrinter.Count() > 0)
                {
                    string modifierName = modifierPrinter[0]["NAME"].ToString();
                    int modifierCount = int.Parse(modifierPrinter[0]["Quantity"].ToString());

                    int foodCount = 1;
                    int.TryParse(foodRow["Quantity"].ToString(), out foodCount);
                    int modifierQuantity = 0;

                    if (modifierCount < 0)
                    {
                        modifierQuantity = foodCount * int.Parse(item.Count.ToString()) * modifierCount;
                    }
                    else
                    {
                        modifierQuantity = foodCount * int.Parse(item.Count.ToString());
                    }

                    int length = (31 - modifierName.Length);
                    if (length < 0)
                    {
                        length = 0;
                    }

                    if (modifierName.Length <= 25)////30
                    {
                        if (modifierQuantity.ToString().Length > 1)
                        {
                            displayString += "     " + modifierName + " ".PadLeft(length) + " " + modifierQuantity.ToString() + Environment.NewLine;
                        }
                        else
                        {
                            displayString += "     " + modifierName + " ".PadLeft(length) + "  " + modifierQuantity.ToString() + Environment.NewLine;
                        }
                    }
                    else
                    {
                        int p = 0;
                        while (modifierName.Substring(p, p + 26).Length >= 26)
                        {
                            if (modifierQuantity.ToString().Length > 1)
                            {
                                displayString += "    " + modifierName + " ".PadLeft(length) + "    " + modifierQuantity.ToString() + Environment.NewLine;
                            }
                            else
                            {
                                displayString += "    " + modifierName + " ".PadLeft(length) + "  " + modifierQuantity.ToString() + Environment.NewLine;
                            }

                            modifierName = modifierName.Substring(p + 26, modifierName.Length - 26);

                            if (modifierName.Length < 26)
                            {
                                displayString += ("    " + modifierName + Environment.NewLine);
                                break;
                            }

                        }

                    }

                    //displayStringL1 += "    " + modifierName + " ".PadLeft(length) + modifierQuantity.ToString() + Environment.NewLine;

                    this.Print(receiptPrinter, displayString);
                    displayString = string.Empty;
                }

            }

        }
        displayString += string.Empty + Environment.NewLine + Environment.NewLine;
        displayString = this.CutPrinterPaper(displayString);
        this.Print(receiptPrinter, displayString);
        displayString = string.Empty;
    }

    return error;

}
Posted
Updated 11-Jun-13 22:09pm
v2
Comments
Oshtri Deka 12-Jun-13 3:13am
   
In all honesty, this code means nothing to me... give us code of your Print method.
lukeer 12-Jun-13 3:14am
   
Wrap code blocks in tags like these: <pre lang="c#">YourCodeHere();</pre>
It makes the code more readable.

However, I fear that this code block is already big enough that most potential helpers will be repelled by having to read through all of it.

Prepare a minimal example that exposes the behaviour you want to show. Explain what it should do and what it does instead. Provide any error messages that might help in full detail.
johannesnestler 13-Jun-13 5:37am
   
I have to agree with the other commenters - what code are you showing here? - You didn't say there is a problem with the content your are printing, you just want to change the font. So why do you show us this code? Shouldn't you show the code of the Print method? I have no problem with reading of long code snippets - if relevant for the problem... BTW: the method gives some bad code smell: way too long, use String.Format for all string concatenations, magic numbers vs. constants (why 25, 26 // 30? - I'm shure these numbers have some meaning in your problem domain - Show this meaning in the code by defining a constant with a descriptive name), shouldn't you cancel execution if there is some error (btw. never heard of exceptions? error strings are not very state of the art..., better I stop looking now...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100