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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
| private void button1_Click_1(object sender, EventArgs e)
{
var wordApp = new Word.Application();
wordApp.Visible = false;
object missing = Type.Missing;
var wordDocument = wordApp.Documents.Open(Template);
string cs = "Data Source=192.168.1.74\\ERASQL; Initial Catalog = job; User Id = jobbd; Password = jobbd";
string sql1 = "select * from dbo.price where idp = '" + Form3.idspec + "' and ids = " + Form3.idtext + "";
SqlConnection conn2 = new SqlConnection(cs);
SqlCommand cmd1 = new SqlCommand(sql1, conn2);
conn2.Open();
SqlDataReader reader1 = cmd1.ExecuteReader();
while (reader1.Read())
{
for (int j = 0; j < reader1.FieldCount; j++)
{
int i = (j * 3);
Microsoft.Office.Interop.Word.Table tbl = wordApp.ActiveDocument.Tables[2];
tbl.Rows.Add(ref missing);
tbl.Rows.Add(ref missing);
tbl.Rows.Add(ref missing);
wordApp.Visible = true;
tbl.Cell(i + 3, 1).Range.Text = Convert.ToString(j + 1);
tbl.Cell(i + 3, 2).Range.Text = "";
tbl.Cell(i + 3, 3).Range.Text = "{name}";
tbl.Cell(i + 3, 4).Range.Text = "{name}";
tbl.Cell(i + 3, 5).Range.Text = "{ism}";
tbl.Cell(i + 3, 6).Range.Text = "{ism}";
tbl.Cell(i + 4, 6).Range.Text = "{ism}";
tbl.Cell(i + 5, 6).Range.Text = "{ism}";
tbl.Cell(i + 3, 7).Range.Text = "{price1}";
tbl.Cell(i + 4, 7).Range.Text = "{price2}";
tbl.Cell(i + 5, 7).Range.Text = "{price3}";
tbl.Cell(i + 3, 8).Range.Text = "{price4}";
tbl.Cell(i + 4, 8).Range.Text = "{price5}";
tbl.Cell(i + 5, 8).Range.Text = "{price6}";
tbl.Cell(i + 3, 10).Range.Text = "{price4}";
tbl.Cell(i + 4, 10).Range.Text = "{price5}";
tbl.Cell(i + 5, 10).Range.Text = "{price6}";
tbl.Cell(i + 3, 11).Range.Text = "{god}";
tbl.Cell(i + 4, 11).Range.Text = "{god}";
tbl.Cell(i + 5, 11).Range.Text = "{god}";
tbl.Cell(i + 3, 12).Range.Text = "{date1}";
tbl.Cell(i + 4, 12).Range.Text = "{date2}";
tbl.Cell(i + 5, 12).Range.Text = "{date3}";
tbl.Cell(i + 3, 13).Range.Text = "{company1}";
tbl.Cell(i + 4, 13).Range.Text = "{company2}";
tbl.Cell(i + 5, 13).Range.Text = "{company3}";
tbl.Cell(i + 3, 14).Range.Text = "{kpp1}";
tbl.Cell(i + 4, 14).Range.Text = "{kpp2}";
tbl.Cell(i + 5, 14).Range.Text = "{kpp3}";
tbl.Cell(i + 3, 15).Range.Text = "{inn1}";
tbl.Cell(i + 4, 15).Range.Text = "{inn2}";
tbl.Cell(i + 5, 15).Range.Text = "{inn3}";
tbl.Cell(i + 3, 16).Range.Text = "{site1}";
tbl.Cell(i + 4, 16).Range.Text = "{site2}";
tbl.Cell(i + 5, 16).Range.Text = "{site3}";
tbl.Cell(i + 3, 17).Range.Text = "{city1}";
tbl.Cell(i + 4, 17).Range.Text = "{city2}";
tbl.Cell(i + 5, 17).Range.Text = "{city3}";
tbl.Cell(i + 3, 18).Range.Text = "{stat1}";
tbl.Cell(i + 4, 18).Range.Text = "{stat2}";
tbl.Cell(i + 5, 18).Range.Text = "{stat3}";
string constring1 = "Data Source=192.168.1.74\\ERASQL; Initial Catalog = job; User Id = jobbd; Password = jobbd";
string quest1 = "select * from dbo.partners where name = '" + String.Format("{0}", reader1["partners1"]) + "'";
string quest2 = "select * from dbo.partners where name = '" + String.Format("{0}", reader1["partners2"]) + "'";
string quest3 = "select * from dbo.partners where name = '" + String.Format("{0}", reader1["partners3"]) + "'";
string quest4 = "select * from dbo.cpeca where id = " + Form3.idspec + "";
SqlConnection conn3 = new SqlConnection(constring1);
SqlConnection conn4 = new SqlConnection(constring1);
SqlConnection conn5 = new SqlConnection(constring1);
SqlConnection conn6 = new SqlConnection(constring1);
SqlCommand cmd2 = new SqlCommand(quest1, conn3);
SqlCommand cmd3 = new SqlCommand(quest2, conn4);
SqlCommand cmd4 = new SqlCommand(quest3, conn5);
SqlCommand cmd5 = new SqlCommand(quest4, conn6);
conn3.Open();
conn4.Open();
conn5.Open();
conn6.Open();
SqlDataReader reader2 = cmd2.ExecuteReader();
SqlDataReader reader3 = cmd3.ExecuteReader();
SqlDataReader reader4 = cmd4.ExecuteReader();
SqlDataReader reader5 = cmd5.ExecuteReader();
while (reader2.Read() && reader3.Read() && reader4.Read() && reader5.Read())
{
string name = String.Format("{0}", reader1["spekaid"]);
string ipartners1 = String.Format("{0}", reader1["partners1"]);
string price1 = String.Format("{0}", reader1["price1"]);
string status1 = String.Format("{0}", reader1["status1"]);
double x = Convert.ToDouble(price1);
string price4 = Convert.ToString(x / 1.2);
double py = Convert.ToDouble(price4);
py = Math.Round(py, 2);
price4 = Convert.ToString(py);
string kpp1 = string.Format("{0}", reader2["kpp"]);
string inn1 = string.Format("{0}", reader2["inn"]);
string site1 = string.Format("{0}", reader2["site"]);
string city1 = string.Format("{0}", reader2["city"]);
string ipartners2 = String.Format("{0}", reader1["partners2"]);
string price2 = String.Format("{0}", reader1["price2"]);
string status2 = String.Format("{0}", reader1["status2"]);
double y = Convert.ToDouble(price2);
string price5 = Convert.ToString(x / 1.2);
double pr = Convert.ToDouble(price5);
pr = Math.Round(pr, 2);
price5 = Convert.ToString(pr);
string kpp2 = string.Format("{0}", reader3["kpp"]);
string inn2 = string.Format("{0}", reader3["inn"]);
string site2 = string.Format("{0}", reader3["site"]);
string city2 = string.Format("{0}", reader3["city"]);
string ipartners3 = String.Format("{0}", reader1["partners3"]);
string price3 = String.Format("{0}", reader1["price3"]);
string status3 = String.Format("{0}", reader1["status3"]);
double z = Convert.ToDouble(price3);
string price6 = Convert.ToString(x / 1.2);
double px = Convert.ToDouble(price6);
px = Math.Round(pr, 2);
price6 = Convert.ToString(px);
string kpp3 = string.Format("{0}", reader4["kpp"]);
string inn3 = string.Format("{0}", reader4["inn"]);
string site3 = string.Format("{0}", reader4["site"]);
string city3 = string.Format("{0}", reader4["city"]);
string kol = String.Format("{0}", reader1["kol"]);
string date1 = String.Format("{0}", reader5["date1"]);
string date2 = String.Format("{0}", reader5["date2"]);
string date3 = String.Format("{0}", reader5["date3"]);
string date4 = date1.Remove(date1.Length - 8);
string date5 = date2.Remove(date2.Length - 8);
string date6 = date3.Remove(date3.Length - 8);
string date = date6.Remove(0, 6);
try
{
ReplaceWordStub("{name}", name, wordDocument);
ReplaceWordStub("{name}", name, wordDocument);
ReplaceWordStub("{ism}", kol, wordDocument);
ReplaceWordStub("{ism}", kol, wordDocument);
ReplaceWordStub("{ism}", kol, wordDocument);
ReplaceWordStub("{ism}", kol, wordDocument);
ReplaceWordStub("{price1}", price1, wordDocument);
ReplaceWordStub("{price2}", price2, wordDocument);
ReplaceWordStub("{price3}", price3, wordDocument);
ReplaceWordStub("{price4}", price4, wordDocument);
ReplaceWordStub("{price5}", price5, wordDocument);
ReplaceWordStub("{price6}", price6, wordDocument);
ReplaceWordStub("{price4}", price4, wordDocument);
ReplaceWordStub("{price5}", price5, wordDocument);
ReplaceWordStub("{price6}", price6, wordDocument);
ReplaceWordStub("{company1}", ipartners1, wordDocument);
ReplaceWordStub("{company2}", ipartners2, wordDocument);
ReplaceWordStub("{company3}", ipartners3, wordDocument);
ReplaceWordStub("{kpp1}", kpp1, wordDocument);
ReplaceWordStub("{kpp2}", kpp2, wordDocument);
ReplaceWordStub("{kpp3}", kpp3, wordDocument);
ReplaceWordStub("{inn1}", inn1, wordDocument);
ReplaceWordStub("{inn2}", inn2, wordDocument);
ReplaceWordStub("{inn3}", inn3, wordDocument);
ReplaceWordStub("{site1}", site1, wordDocument);
ReplaceWordStub("{site2}", site2, wordDocument);
ReplaceWordStub("{site3}", site3, wordDocument);
ReplaceWordStub("{city1}", city1, wordDocument);
ReplaceWordStub("{city2}", city2, wordDocument);
ReplaceWordStub("{city3}", city3, wordDocument);
ReplaceWordStub("{stat1}", status1, wordDocument);
ReplaceWordStub("{stat2}", status2, wordDocument);
ReplaceWordStub("{stat3}", status3, wordDocument);
ReplaceWordStub("{date1}", date4, wordDocument);
ReplaceWordStub("{date2}", date5, wordDocument);
ReplaceWordStub("{date3}", date6, wordDocument);
ReplaceWordStub("{god}", date, wordDocument);
ReplaceWordStub("{god}", date, wordDocument);
ReplaceWordStub("{god}", date, wordDocument);
}
catch (SystemException ex)
{
MessageBox.Show(ex.Message);
}
}
conn3.Close();
conn4.Close();
conn5.Close();
conn6.Close();
}
conn2.Close();
}
string outpatch = Application.StartupPath.ToString() + "\\Output\\KA" + Form3.idspec + ".docx";
wordDocument.SaveAs(outpatch, 12);
// wordApp.Visible = true;
MessageBox.Show("Готово");
} |