Диплом: Автоматизация электронного документооборота для компании ООО «СТАНКИ-РОССИИ»

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
96
if (Program.db.roleuser != "admin")
{
MessageBox.Show("Доступ к данной функции вам закрыт");
return;
}
string kodvida = maingrid.CurrentRow.Cells[0].Value.ToString();
Program.db.con.Open();
SqlCommand myCommand = Program.db.con.CreateCommand();
myCommand.CommandText = "select count (*) from Проект where ВидДоку-
мента=" + kodvida;
Kolstr = Convert.ToString(myCommand.ExecuteScalar());
Program.db.con.Close();
if (Kolstr != "0")
{
MessageBox.Show("Есть проекты имеющие данный вид документа. Уда-
ление невозможно ");
return;
}
caption = "Удаление вида документа";
message = "Вы хотите удалить вид документа " +
maingrid.CurrentRow.Cells[1].Value.ToString() + "?";
DialogResult result = MessageBox.Show(message, caption, MessageBox-
Buttons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
Program.db.con.Open();
SqlCommand command1 = new SqlCommand(@"delete from ВидДокумента
where Код=" + kodvida, Program.db.con);
command1.ExecuteNonQuery();
Program.db.con.Close();
p--;
}
}
//***********
if (Program.db.statusmaingrid == "misx")
{
string kodsoob = maingrid.CurrentRow.Cells[0].Value.ToString();
Program.db.con.Open();
SqlCommand myCommand = Program.db.con.CreateCommand();
myCommand.CommandText = "select count (*) from Сообщение where Код="
+ kodsoob + "and Обработан=0";
Kolstr = Convert.ToString(myCommand.ExecuteScalar());
Program.db.con.Close();
if (Kolstr == "0")
{
MessageBox.Show("Сообщение уже обработано и не может быть удале-
но");
}
else
{
caption = "Удаление сообщения";
message = "Вы хотите удалить сообщение для " +
maingrid.CurrentRow.Cells[3].Value.ToString() + "?";
DialogResult result1 = MessageBox.Show(message, caption, Mes-
sageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result1 == DialogResult.Yes)
{
Program.db.con.Open();
SqlCommand command1 = new SqlCommand(@"delete from Сообщение
where Код=" + kodsoob, Program.db.con);
command1.ExecuteNonQuery();
97
Program.db.con.Close();
p--;
}
}
}
if (Program.db.statusmaingrid == "arxotchet")
{
string kodotcheta = maingrid.CurrentRow.Cells[0].Value.ToString();
Program.db.con.Open();
SqlCommand command1 = new SqlCommand(@"delete from Отчет where Код="
+ kodotcheta, Program.db.con);
command1.ExecuteNonQuery();
Program.db.con.Close();
MessageBox.Show("Отчет удален");
p--;
}
if (Program.db.statusmaingrid == "otchet")
{
Program.db.con.Open();
SqlCommand command1 = new SqlCommand(@"update Отчет set Архив=1
where код=" + maingrid.CurrentRow.Cells[0].Value.ToString(), Program.db.con);
command1.ExecuteNonQuery();
Program.modified = true;
Program.db.con.Close();
p--;
}
Program.db.mainzapros(Program.db.statusmaingrid, maingrid, 1);
recordcounlabel.Text = Program.db.recordcount.ToString();
refreshrecordcount();
if ((p + 1 > 0) && (maingrid.RowCount-1 >= p + 1)) maingrid.Rows[p +
1].Selected = true;
}
private void tree_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
if (e.Node == null) return;
// if treeview HideSelection property is "True",
// this will always returns "False" on unfocused treeview
var selected = (e.State & TreeNodeStates.Selected) ==
TreeNodeStates.Selected;
var unfocused = !e.Node.TreeView.Focused;
// we need to do owner drawing only on a selected node
// and when the treeview is unfocused, else let the OS do it for us
if (selected && unfocused)
{
var font = e.Node.NodeFont ?? e.Node.TreeView.Font;
e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
TextRenderer.DrawText(e.Graphics, e.Node.Text, font, e.Bounds, Sys-
temColors.HighlightText, TextFormatFlags.GlyphOverhangPadding);
}
else
{
e.DrawDefault = true;
}
}
private void button4_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void настройкаToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Program.db.roleuser != "admin")
{
98
MessageBox.Show("Доступ к данной функции вам закрыт");
return;
}
FormSettings w = new FormSettings();
w.ShowDialog();
}
private void timer1_Tick(object sender, EventArgs e)
{
string kol = "0";
SqlCommand myCommand = Program.db.con.CreateCommand();
myCommand.CommandText = "select count (*) from Сообщение where (Получа-
тельКодСотрудника=" + Program.db.koduser + ") and (Обработан=0)";
Program.db.con.Open();
kol = Convert.ToString(myCommand.ExecuteScalar());
Program.db.con.Close();
label1.Text = "Входящих сообщений: " + kol;
}
private void button19_Click(object sender, EventArgs e)
{
if (Program.db.statusmaingrid == "parrent") MessageBox.Show("Выберите
таблицы для экспорта в Excel");
else
ToExcel(maingrid, tree.SelectedNode.Text);
}
public void ToExcel(System.Windows.Forms.DataGridView dgrid, string s)
{
Microsoft.Office.Interop.Excel.Application ExcelApp = new Mi-
crosoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook ExcelWorkBook;
Microsoft.Office.Interop.Excel.Worksheet ExcelWorkSheet;
//Книга.
ExcelWorkBook = ExcelApp.Workbooks.Add(System.Reflection.Missing.Value);
//Таблица.
ExcelWorkSheet = (Mi-
crosoft.Office.Interop.Excel.Worksheet)ExcelWorkBook.Worksheets.get_Item(1);
ExcelApp.Cells[1, 1] = s;
for (int j = 0; j < dgrid.ColumnCount; j++)
if ((j != 3))
if (j > 3) ExcelApp.Cells[3, j] = dgrid.Columns[j].HeaderText;
else ExcelApp.Cells[3, j + 1] = dgrid.Columns[j].HeaderText;
// string tip;
for (int i = 0; i < dgrid.RowCount; i++)
{
for (int j = 0; j < dgrid.ColumnCount; j++)
{
if ((j != 3))
if (j > 3) ExcelApp.Cells[i + 4, j] =
dgrid.Rows[i].Cells[j].Value; else ExcelApp.Cells[i + 4, j + 1] =
dgrid.Rows[i].Cells[j].Value;
}
}
//Вызываем нашу созданную эксельку.
ExcelApp.Columns.EntireColumn.AutoFit();
ExcelApp.Visible = true;
ExcelApp.UserControl = true;
}
private void оПрограммеToolStripMenuItem_Click(object sender, EventArgs e)
{
FormAbout w = new FormAbout();
w.ShowDialog();
}
private void справкаToolStripMenuItem_Click(object sender, EventArgs e)
{
99
string commandText = Directory.GetCurrentDirectory() +
"\\HelpelDoc.pdf";
if (File.Exists(commandText))
{
try
{
var proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = commandText;
proc.StartInfo.UseShellExecute = true;
proc.Start();
// MessageBox.Show(PathFileBase);
}
catch (Exception ex)
{
MessageBox.Show("Ошибка открытия файла справки");
}
}
else MessageBox.Show("Файл справки отсутствует");
}
}
}
Класс FormProject.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
using System.Diagnostics;
using System.Data.SqlClient;
namespace ELDoc
{
public partial class FormProject : Form
{
public FormProject()
{
InitializeComponent();
gridsoob.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
}
private void FormProject_Load(object sender, EventArgs e)
{
if ((Program.insert) )
{
Program.db.sql="SELECT ФИО, Код from Сотрудник where Работает=1";
if (Program.db.sql == "") return;
Program.db.con.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(Program.db.sql, Pro-
gram.db.con);
DataTable dt = new DataTable();
da.Fill(dt);
Program.db.con.Close();
comboBox1.DataSource = null;
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "ФИО";
comboBox1.ValueMember = "Код";
comboBox1.SelectedIndex = -1;
Program.db.sql = "SELECT ВидДокумента, Код from ВидДокумента";
100
if (Program.db.sql == "") return;
Program.db.con.Open();
DataSet dss = new DataSet();
SqlDataAdapter daa = new SqlDataAdapter(Program.db.sql, Pro-
gram.db.con);
DataTable dtt = new DataTable();
daa.Fill(dtt);
Program.db.con.Close();
comboBox2.DataSource = null;
comboBox2.DataSource = dtt;
comboBox2.DisplayMember = "ВидДокумента";
comboBox2.ValueMember = "Код";
comboBox2.SelectedIndex = -1;
labelfio.Text = Program.db.fiouser;
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
// button7.Enabled = false;
button8.Enabled = false;
button6.Enabled = false;
button5.Enabled = false;
return;
}
//редактирование
if (Program.insert==false)
{
Program.db.sql = "SELECT Проект.Код, Проект.РегДата, Про-
ект.КраткоеСодержание, ВидДокумента.ВидДокумента, Сотруд-
ник.ФИО,ВидДокумента.Код,Сотрудник.Код,Проект.ПодписанКодСотрудника, Проект.Подписан FROM
((Проект INNER JOIN Сотрудник ON Проект.ПодготовленКодСотрудника = Сотрудник.Код) INNER JOIN
ВидДокумента ON Проект.ВидДокумента = ВидДокумента.Код) WHERE (((Проект.Код)=" + Pro-
gram.db.kodproject + "));";
if (Program.db.sql == "") return;
Program.db.con.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(Program.db.sql, Pro-
gram.db.con);
DataTable dt = new DataTable();
da.Fill(dt);
Program.db.con.Close();
int kodvid = Convert.ToInt32(dt.Rows[0].ItemArray[5].ToString());
int kodsotr = Convert.ToInt32(dt.Rows[0].ItemArray[7].ToString());
labeldata.Text = dt.Rows[0].ItemArray[1].ToString();
labelkodproekta.Text = dt.Rows[0].ItemArray[0].ToString();
textBox1.Text = dt.Rows[0].ItemArray[2].ToString();
labelfio.Text = dt.Rows[0].ItemArray[4].ToString();
Program.db.sql = "SELECT ФИО, Код from Сотрудник where Работает=1";
if (Program.db.sql == "") return;
Program.db.con.Open();
DataSet ds2 = new DataSet();
SqlDataAdapter da2 = new SqlDataAdapter(Program.db.sql, Pro-
gram.db.con);
DataTable dt2 = new DataTable();
da2.Fill(dt2);
Program.db.con.Close();
comboBox1.DataSource = null;
comboBox1.DataSource = dt2;
comboBox1.DisplayMember = "ФИО";
comboBox1.ValueMember = "Код";
comboBox1.SelectedValue = kodsotr;
Program.db.sql = "SELECT ВидДокумента, Код from ВидДокумента";
101
if (Program.db.sql == "") return;
Program.db.con.Open();
DataSet dss = new DataSet();
SqlDataAdapter daa = new SqlDataAdapter(Program.db.sql, Pro-
gram.db.con);
DataTable dtt = new DataTable();
daa.Fill(dtt);
Program.db.con.Close();
comboBox2.DataSource = null;
comboBox2.DataSource = dtt;
comboBox2.DisplayMember = "ВидДокумента";
comboBox2.ValueMember = "Код";
comboBox2.SelectedValue = kodvid;
gridsoobrefresh();
}
listview1refresh();
if (Program.db.myproject)
{
comboBox1.Enabled = true;
comboBox2.Enabled = true;
textBox1.Enabled = true;
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
// button7.Enabled = true;
button8.Enabled = true;
button6.Enabled = true;
button9.Visible = true;
}
else
{
comboBox1.Enabled = false;
comboBox2.Enabled = false;
textBox1.Enabled = false;
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button8.Enabled = false;
button6.Enabled = false;
button9.Visible = false;
}
}
public void gridsoobrefresh()
{
Program.db.sql = @"SELECT Сообщение.Код, Сообщение.КодПроекта, Сообще-
ние.ТекстСообщения,Сообщение.ВремяСоздания,
Сотрудник.ФИО, ТипСообщения.ТипСообщения,Сообщение.Обработан,
Сообщение.Отказ
FROM (Сообщение INNER JOIN Сотрудник ON Сообщение.ПолучательКодСотрудника = Сотруд-
ник.Код)
INNER JOIN ТипСообщения ON Сообщение.ТипСообщенияКод = ТипСообщения.Код WHERE (((Со-
общение.КодПроекта)=" + Program.db.kodproject + "))";
if (Program.db.sql == "") return;
Program.db.con.Open();
DataSet dsss = new DataSet();
SqlDataAdapter daaa = new SqlDataAdapter(Program.db.sql, Pro-
gram.db.con);
DataTable dttt = new DataTable();
daaa.Fill(dttt);
gridsoob.DataSource = null;
102
gridsoob.DataSource = dttt;
gridsoob.Columns[0].Visible = false;
Program.db.con.Close();
}
private void button1_Click(object sender, EventArgs e)
{
Program.insertsoob = true;
Program.finishinsertsoob = false;
Formsoob w = new Formsoob();
w.ShowDialog();
if (Program.finishinsertsoob ) gridsoobrefresh();
Program.insertsoob = false;
}
public void listview1refresh()
{
listView1.Clear();
if (!Directory.Exists(Program.db.PathFileBase )) return;
DirectoryInfo d = new DirectoryInfo(Program.db.PathFileBase +
"\\"+Program.db.kodproject.ToString());
if (!Directory.Exists(Program.db.PathFileBase + "\\" + Pro-
gram.db.kodproject.ToString()))
{
Directory.CreateDirectory(Program.db.PathFileBase + "\\" + Pro-
gram.db.kodproject.ToString());
}
FileInfo[] f=d.GetFiles("*.*");
ImageList imageList = new ImageList();
for (int i = 0; i < f.GetLength(0); i++)
imageList.Images.Add(f[i].Extension,
(Icon)Icon.ExtractAssociatedIcon(f[i].FullName));
listView1.LargeImageList = imageList;
listView1.SmallImageList = imageList;
for (int i = 0; i < f.GetLength(0); i++)
listView1.Items.Add(f[i].Name, image-
List.Images.IndexOfKey(f[i].Extension));
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
String name = "";
String tempPath;
ListView.SelectedListViewItemCollection file =
this.listView1.SelectedItems;
String fullPath = Program.db.PathFileBase +
"\\"+Program.db.kodproject.ToString();
foreach (ListViewItem item in file)
{
fullPath = (fullPath+"\\"+item.SubItems[0].Text);
name = item.SubItems[0].Text;
break;
}
tempPath = Program.UserTempdir + "\\" + name;
if (File.Exists(tempPath))
{
try
{
File.Delete(tempPath);
}
103
catch (Exception ex)
{
MessageBox.Show("Ошибка открытия: " + ex.Message);
return;
}
}
File.Copy(fullPath, tempPath);
string commandText = tempPath;
var proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = commandText;
proc.StartInfo.UseShellExecute = true;
proc.Start();
}
private void button5_Click(object sender, EventArgs e)
{
String name = "";
String tempPath;
ListView.SelectedListViewItemCollection file =
this.listView1.SelectedItems;
String fullPath = Program.db.PathFileBase + "\\" + Pro-
gram.db.kodproject.ToString();
foreach (ListViewItem item in file)
{
fullPath = (fullPath + "\\" + item.SubItems[0].Text);
name = item.SubItems[0].Text;
break;
}
tempPath = Program.UserTempdir + "\\" + name;
if (File.Exists(tempPath))
{
try
{
File.Delete(tempPath);
}
catch (Exception ex)
{
MessageBox.Show("Ошибка открытия: " + ex.Message);
return;
}
}
File.Copy(fullPath, tempPath);
string commandText = tempPath;
var proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = commandText;
proc.StartInfo.UseShellExecute = true;
proc.Start();
}
private void button7_Click(object sender, EventArgs e)
{
}
private void button6_Click(object sender, EventArgs e)
{
ListView.SelectedListViewItemCollection file =
this.listView1.SelectedItems;
String fullPath = Program.db.PathFileBase + "\\" + Pro-
gram.db.kodproject.ToString();
String name="" ;
foreach (ListViewItem item in file)
{
104
fullPath = (fullPath + "\\" + item.SubItems[0].Text);
name = item.SubItems[0].Text;
break;
}
if (name != "")
{
var resultt = MessageBox.Show("Вы действительно хотите удалить " +
name + "?", "Выбор",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
// If the no button was pressed ...
if (resultt == DialogResult.Yes)
{
File.Delete(fullPath);
listview1refresh();
}
}
else
MessageBox.Show("Нет файлов для удаления");
}
private void button8_Click(object sender, EventArgs e)
{
Stream myStream = null;
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "офисные файлы |*.txt;*.doc,
*.docx;*.rtf;*.xls;*xlsx;*.ppt;*.pptx;*.rar;*.zip;*.tiff|Изображения|*.bmp;*.dib;*.rle;*.emf
;*.eps;*.gif;*.icn;*.jpg;*.jpeg;*.icl;*.ico;*.cur;*ani;*.iff;*.lbm;*.jp*g*;*.pbm;*.pcd;*.pcx
;*.pgm;*.pic;*.pix;*.png;*.psd;*.psp;*.tga;*.tif;*.tiff;*.xif;*.wmf;*.xbm;*.xpm";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
try
{
var str = openFileDialog1.FileName.Split(new[] { '\\'
}).Last();
if (!System.IO.File.Exists(Program.db.PathFileBase +
"\\" + Program.db.kodproject + "\\" + str))
{
File.Copy(openFileDialog1.FileName, Pro-
gram.db.PathFileBase + "\\" + Program.db.kodproject + "\\" + str);
listview1refresh();
}
else MessageBox.Show("Файл с таким именем в проекте уже
есть");
}
// Catch exception if the file was already copied.
catch (IOException copyError)
{
Console.WriteLine(copyError.Message);
}
}
}
catch (Exception ex)
{
105
MessageBox.Show("Ошибка: Не удалось прочитать файл с диска. Ис-
ходная ошибка:" + ex.Message);
}
}
}
private void gridsoob_MouseDoubleClick(object sender, MouseEventArgs e)
{
button2_Click(sender, e);
}
private void button9_Click(object sender, EventArgs e)
{
if (Program.insert)
{
if (proverka_zapolneniya_poleiproecta())
{
Program.db.con.Open();
SqlCommand command1 = new SqlCommand(@"INSERT INTO Проект (Ре-
гДата, ВидДокумента, КраткоеСодержание,
ПодготовленКодСотрудника, ПодписанКодСотрудника, Подписан)
values (@datetime,@viddoc,@soderj,@kodpodgotovlen,
@kodpodpisatel,@podpisan)", Program.db.con);
command1.Parameters.Add("@datetime", SqlDbType.DateTime).Value =
DateTime.Now;
command1.Parameters.Add("@viddoc", SqlDbType.Int).Value = com-
boBox2.SelectedValue; //textBox1.Text;
command1.Parameters.Add("@soderj", SqlDbType.Char).Value = text-
Box1.Text; //Program.db.kodproject;
command1.Parameters.Add("@kodpodgotovlen", SqlDbType.Int).Value
= Program.db.koduser;
command1.Parameters.Add("@kodpodpisatel", SqlDbType.Int).Value =
command1.Parameters.Add("@kodtipsoob", SqlDbType.Int).Value =
comboBox1.SelectedValue;
command1.Parameters.Add("@podpisan", SqlDbType.Bit).Value =
false;
command1.ExecuteNonQuery();
Program.db.con.Close();
Program.modified= true;
this.Close();
}
}
if (!Program.insert)
{
if (proverka_zapolneniya_poleiproecta())
{
Program.db.con.Open();
SqlCommand command1 = new SqlCommand(@"update Проект set ВидДо-
кумента=@viddoc, КраткоеСодержание=@soderj,
ПодписанКодСотрудника=@kodpodpisatel where Проект.Код=" + Program.db.kodproject,
Program.db.con);
command1.Parameters.Add("@viddoc", OleDbType.Integer).Value =
comboBox2.SelectedValue;
command1.Parameters.Add("@soderj", OleDbType.Char).Value = text-
Box1.Text;
command1.Parameters.Add("@kodpodpisatel",
OleDbType.Integer).Value = comboBox1.SelectedValue;

Смотрите также:

"Автоматизация обработки заявок ООО "Проектно-Строительная Компания"
"Автоматизация процесса аттестации персонала для ООО "Нэт Бай Нэт Холдинг"
"Анализ интернет-активности конкурентов ( на примере конкурентов "Газпром нефть")
"Бухгалтерский учёт и аудит расчётов с подотчётними лицами в организации на примере ООО "ЛОЦ 10""
«Психологическое сопровождение персонала в организации на примере ООО «Крокус»
Cовершенствование деловой оценки персонала в организации (на примере ООО "Даймонд кейтеринг развитие")
IPO - инструмент финансирования деятельности организации. На примере ПАО «Нефтяная компания «Лукойл»
PR как средство продвижения организации (на примере ПАО "Тамбовский завод "Комсомолец им. Н.С. Артемова")
PR-коммуникации в сфере общественного питания (на примере кафе-кондитерской «Cream Cheese»)
SMM как средство повышения эффективности работы учреждений социокультурной сферы (на примере Малого театра)