Дипломная работа: Автоматизация складских процессов предприятия ООО «АТОЛ»

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
100
{
System.Windows.Forms.TextBox t =
(System.Windows.Forms.TextBox)dict[m];
currentSelection.TypeText(string.IsNullOrEmpty(t.Text) ? "" : t.Text);
}
else
{
//вставляем таблицу
DataGrid dgv = (DataGrid)dict[m];
document.Bookmarks[m.Наименование].Select();
System.Data.DataTable dt = (System.Data.DataTable)dgv.DataSource;
Microsoft.Office.Interop.Word.Table tbl1 =
ap.Selection.Tables.Add(ap.Selection.Range, 1, dt.Columns.Count);
//заголовки колонок
for (int i = 0; i <= dt.Columns.Count - 1; i++)
{
tbl1.Cell(1, i + 1).Range.Text = dt.Columns[i].ColumnName;
tbl1.Cell(1, i + 1).Range.Borders[WdBorderType.wdBorderLeft].LineStyle
= WdLineStyle.wdLineStyleSingle;
tbl1.Cell(1, i +
1).Range.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wd
LineStyleSingle;
tbl1.Cell(1, i + 1).Range.Borders[WdBorderType.wdBorderTop].LineStyle
= WdLineStyle.wdLineStyleSingle;
tbl1.Cell(1, i +
1).Range.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.w
dLineStyleSingle;
}
//строки таблицы
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
tbl1.Rows.Add();
for (int j = 0; j <= dt.Columns.Count - 1; j++)
{
tbl1.Cell(tbl1.Rows.Count, j + 1).Range.Text = dt.Rows[i][j] == null ?
""
: dt.Rows[i][j].ToString();
tbl1.Cell(tbl1.Rows.Count, j +
1).Range.Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdL
ineStyleSingle;
tbl1.Cell(tbl1.Rows.Count, j +
1).Range.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wd
LineStyleSingle;
tbl1.Cell(tbl1.Rows.Count, j +
101
1).Range.Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLi
neStyleSingle;
tbl1.Cell(tbl1.Rows.Count, j +
1).Range.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.w
dLineStyleSingle;
}
}
}
}
//получаем список меток с текущей датой и временем
foreach (BDDataSet.МеткиRow m in dictDatetime)
{
document.Bookmarks[m.Наименование].Select();
Microsoft.Office.Interop.Word.Selection currentSelection = ap.Selectio
n;
if (m.КодВидаМетки == 3)
currentSelection.TypeText(DateTime.Now.ToShortDateString());
if (m.КодВидаМетки == 4)
currentSelection.TypeText(DateTime.Now.ToShortTimeString());
}
//колонтитулы
ap.ActiveDocument.Sections[1].Footers[Microsoft.Office.Interop.Word.WdH
eaderFooterIndex.wd
HeaderFooterPrimary].Range.Text = textBox2.Text;
ap.ActiveDocument.Sections[1].Headers[Microsoft.Office.Interop.Word.WdH
eaderFooterIndex.wd
HeaderFooterPrimary].Range.Text = textBox1.Text;
//ReleaseObject(ap);
ap.Visible = true;
return document;
}
catch (Exception ee)
{
MessageBox.Show(ee.Message, "Возникла ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return null;
}
}
/// <summary>
/// Заполняем вордовский документ
/// </summary>
/// <param name="filename"></param>
102
/// <param name="sh"></param>
public string FillWordDocPacket(string filename, string filenameData)
{
Microsoft.Office.Interop.Excel.Application apData = new
Microsoft.Office.Interop.Excel.Application();
apData.Visible = false;
Microsoft.Office.Interop.Excel.Workbook bookData = null;
Microsoft.Office.Interop.Excel.Workbooks databook = apData.Workbooks;
apData.Workbooks.Open(filenameData,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
bookData = databook[1];
Microsoft.Office.Interop.Excel.Worksheet sheetData = bookData.Workshee
ts[1];
Microsoft.Office.Interop.Word.Application ap = new
Microsoft.Office.Interop.Word.Application();
ap.Visible = false;
string nameFold = "";
//создаем папку
nameFold = System.Windows.Forms.Application.StartupPath + @"\документы
\" +
sh.Выражение1 + "_" + DateTime.Now.ToShortDateString().Replace(".", "-
");
DirectoryInfo d;
if (!Directory.Exists(nameFold))
d = Directory.CreateDirectory(nameFold);
else
{
nameFold = System.Windows.Forms.Application.StartupPath + @"\документы
\"
+ sh.Выражение1 + "_" + DateTime.Now.ToShortDateString().Replace(".", "
-") + "-" +
DateTime.Now.ToShortTimeString().Replace(":", "-");
d = Directory.CreateDirectory(nameFold);
}
for (int j = 7; j <= sheetData.UsedRange.Rows.Count - 1; j++)//строки
{
if (sheetData.Cells[j, 1].value2 == null) continue; //нет порядковго н
омера
документа
string numberDoc = Convert.ToString(sheetData.Cells[j, 1].Value2);
//////////////новый документ
103
Document documentData = null;
documentData = ap.Documents.Open(filename);
//////////////
for (int i = 2; i <= sheetData.UsedRange.Columns.Count - 3; i++)//коло
нки
{
string nameCol = sheetData.Cells[5, i].Value2 == null ? "" :
Convert.ToString(sheetData.Cells[5, i].Value2);
if (nameCol == "") continue;
DataRow[] dr = bDDataSet1.Метки.Select("КодШаблона=" + sh.КодШаблона
+ " and Наименование='" + nameCol + "'");
if (dr == null || dr.Length == 0) continue;
BDDataSet.МеткиRow metka = ((BDDataSet.МеткиRow)dr[0]);
int vidMetka = metka.КодВидаМетки;
documentData.Bookmarks[metka.Наименование].Select();
Microsoft.Office.Interop.Word.Selection currentSelection = ap.Selectio
n;
if (vidMetka == 1)
{
currentSelection.TypeText(sheetData.Cells[j, i].Value2 == null ? "" :
Convert.ToString(sheetData.Cells[j, i].Value2));
}
//текущая дата
if (vidMetka == 3)
currentSelection.TypeText(DateTime.Now.ToShortDateString());
//текущее время
if (vidMetka == 4)
currentSelection.TypeText(DateTime.Now.ToShortTimeString());
if (vidMetka == 2)
{
///вставляем таблицу
string[] s = metka.ЗаголовкиКолонок.Split('/');
//int row = b.RefersToRange.Row;
// int col = b.RefersToRange.Column;
int rowsCount = 0;
int colCount = s.Length;
for (int k = j + 1; k <= sheetData.UsedRange.Rows.Count - 1; k++)
{
if (sheetData.Cells[k, 1].Value2 != null)
{
rowsCount = (k - j) ;
break;
}
}
104
if (rowsCount == 0) rowsCount = sheetData.UsedRange.Rows.Count - j +1;
documentData.Bookmarks[metka.Наименование].Select();
Microsoft.Office.Interop.Word.Table tbl1 =
ap.Selection.Tables.Add(ap.Selection.Range, 1, colCount);
////заголовки колонок
for (int c = 0; c <= colCount - 1; c++)
{
tbl1.Cell(1, c + 1).Range.Text = s[c];
tbl1.Cell(1, c + 1).Range.Borders[WdBorderType.wdBorderLeft].LineStyle
= WdLineStyle.wdLineStyleSingle;
tbl1.Cell(1, c +
1).Range.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wd
LineStyleSingle;
tbl1.Cell(1, c + 1).Range.Borders[WdBorderType.wdBorderTop].LineStyle
= WdLineStyle.wdLineStyleSingle;
tbl1.Cell(1, c +
1).Range.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.w
dLineStyleSingle;
}
////строки таблицы
for (int r = 0; r <= rowsCount - 1; r++)
{
tbl1.Rows.Add();
for (int m = 0; m <= colCount - 1; m++)
{
tbl1.Cell(tbl1.Rows.Count, m + 1).Range.Text = sheetData.Cells[j + r,
i
+ m].Value2 == null ? "" : Convert.ToString(sheetData.Cells[j + r, i +
m].Value2);
tbl1.Cell(tbl1.Rows.Count, m +
1).Range.Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdL
ineStyleSingle;
tbl1.Cell(tbl1.Rows.Count, m +
1).Range.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wd
LineStyleSingle;
tbl1.Cell(tbl1.Rows.Count, m +
1).Range.Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLi
neStyleSingle;
tbl1.Cell(tbl1.Rows.Count, m +
1).Range.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.w
dLineStyleSingle;
}
}
}
Источник: https://baza.diplomsite.ru/previewfile/594