Форум программистов, компьютерный форум, киберфорум
C# Windows Forms
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.56/18: Рейтинг темы: голосов - 18, средняя оценка - 4.56
10 / 10 / 8
Регистрация: 07.04.2015
Сообщений: 84
1

Печать отчета

11.12.2015, 21:18. Показов 3479. Ответов 2
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Нужно сделать печать определенных значений (под тип чека).
P.S. В программе не используется DataSource
0
Лучшие ответы (1)
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
11.12.2015, 21:18
Ответы с готовыми решениями:

ReportViewer автоматическая печать отчета
Здравствуйте, подскажите как сделать автоматическую печать отчета, т.е. он обработался и сразу на...

Печать отчета Access
у меня есть бд ski.mdb в нем есть отчет polyy Вот мне надо кликом батона отправить этот отчет на...

Печать отчета
каким образом при печати отчета, остановить протяжку полного формата бумажной ленты при окончании...

Печать отчета
Приветствую. В общем проблема с печатью отчета. Генерирую отчет и нужно вывести его на печать....

2
153 / 153 / 56
Регистрация: 20.12.2011
Сообщений: 1,614
11.12.2015, 22:46 2
Эвальд, а можно подробнее?
то что вы написали сейчас этого мало, чтобы вам как-то помочь
0
10 / 10 / 8
Регистрация: 07.04.2015
Сообщений: 84
12.12.2015, 18:49  [ТС] 3
Лучший ответ Сообщение было отмечено Эвальд как решение

Решение

Что то вроде этого https://www.youtube.com/watch?v=Ns1Rad7sM_w
Вот его код
Кликните здесь для просмотра всего текста
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Printing;
using Microsoft.VisualBasic;
 
namespace Reciept_Print_Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void btnAddItem_Click(object sender, EventArgs e)
        {
            listBox1.Items.Add(txtName.Text.PadRight(30) + txtPrice.Text);
            txtName.Text = "";
            txtPrice.Text = "";
        }
 
        private void btnRemoveItem_Click(object sender, EventArgs e)
        {
            try
            {
                listBox1.Items.RemoveAt(listBox1.SelectedIndex);
            }
            catch (Exception)
            {
 
                return;
            }
        }
 
        private void btnPrintReciept_Click(object sender, EventArgs e)
        {
            PrintDialog printDialog = new PrintDialog();
 
            PrintDocument printDocument = new PrintDocument();
 
            printDialog.Document = printDocument; //add the document to the dialog box...        
 
            printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(CreateReceipt); //add an event handler that will do the printing
 
            //on a till you will not want to ask the user where to print but this is fine for the test envoironment.
 
            DialogResult result = printDialog.ShowDialog();
 
            if (result == DialogResult.OK)
            {
            printDocument.Print();
 
            } 
        }
 
        public void CreateReceipt(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            
            int total = 0;
            float cash = float.Parse(txtCash.Text.Substring(1,5));
            float change = 0.00f;
           
            //this prints the reciept
 
            Graphics graphic = e.Graphics;
 
            Font font = new Font("Courier New", 12); //must use a mono spaced font as the spaces need to line up
 
            float fontHeight = font.GetHeight();
 
            int startX = 10;
            int startY = 10;
            int offset = 40;
 
            graphic.DrawString(" Wangoland Coffee Shop", new Font("Courier New", 18), new SolidBrush(Color.Black), startX, startY);
            string top = "Item Name".PadRight(30) + "Price";
            graphic.DrawString(top, font, new SolidBrush(Color.Black), startX, startY + offset);
            offset = offset + (int)fontHeight; //make the spacing consistent
            graphic.DrawString("----------------------------------", font, new SolidBrush(Color.Black), startX, startY + offset);
            offset = offset + (int)fontHeight + 5; //make the spacing consistent
 
            float totalprice = 0.00f;
 
            foreach (string item in listBox1.Items)
            {
                //create the string to print on the reciept
                string productDescription = item;
                string productTotal = item.Substring(item.Length - 6, 6);
                float productPrice = float.Parse(item.Substring(item.Length - 5, 5));
 
                //MessageBox.Show(item.Substring(item.Length - 5, 5) + "PROD TOTAL: " + productTotal);
                
 
                totalprice += productPrice;
 
                if (productDescription.Contains("  -"))
                {
                    string productLine = productDescription.Substring(0,24);
 
                    graphic.DrawString(productLine, new Font("Courier New", 12, FontStyle.Italic), new SolidBrush(Color.Red), startX, startY + offset);
 
                    offset = offset + (int)fontHeight + 5; //make the spacing consistent
                }
                else
                {
                    string productLine = productDescription;
 
                    graphic.DrawString(productLine, font, new SolidBrush(Color.Black), startX, startY + offset);
 
                    offset = offset + (int)fontHeight + 5; //make the spacing consistent
                }
 
            }
 
            change = (cash - totalprice);
 
            //when we have drawn all of the items add the total
 
            offset = offset + 20; //make some room so that the total stands out.
 
            graphic.DrawString("Total to pay ".PadRight(30) + String.Format("{0:c}", totalprice), new Font("Courier New", 12, FontStyle.Bold), new SolidBrush(Color.Black), startX, startY + offset);
 
            offset = offset + 30; //make some room so that the total stands out.
            graphic.DrawString("CASH ".PadRight(30) + String.Format("{0:c}", cash), font, new SolidBrush(Color.Black), startX, startY + offset);
            offset = offset + 15;
            graphic.DrawString("CHANGE ".PadRight(30) + String.Format("{0:c}", change), font, new SolidBrush(Color.Black), startX, startY + offset);
            offset = offset + 30; //make some room so that the total stands out.
            graphic.DrawString("     Thank-you for your custom,", font, new SolidBrush(Color.Black), startX, startY + offset);
            offset = offset + 15;
            graphic.DrawString("       please come back soon!", font, new SolidBrush(Color.Black), startX, startY + offset);
 
        }
 
        private void label2_Click(object sender, EventArgs e)
        {
 
        }
    }
}


Делаю как там ошибка Input string was not in a correct format. на строчку float cash = float.Parse(txtCash.Text.Substring(1, 5));

Добавлено через 15 часов 4 минуты
Пока сделал немного по другому, но все же хотелось бы как на приведенных выше примерах
0
12.12.2015, 18:49
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
12.12.2015, 18:49
Помогаю со студенческими работами здесь

Печать отчета
Необходимо вывести на печать отчет из DBGrid. Или на крайний случай Чтобы переводило в Word (но...

Печать отчета
Уважаемые форумчане, требуется вывести на печать отчет по нажатию кнопки с фильтром данных. Сам...

Печать отчёта
Ситуация такая. Имеется отчёт в БД Access. С помощью Delphi (вернее, программы созданной в Delphi)...

Печать отчета MS Access
У меня в базе данных Access учет производства и продажи. Часто приходится печатать накладные и...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
3
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru