using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.OleDb; using Microsoft.Win32.SafeHandles; using System.Runtime.InteropServices; using System.Threading; namespace own_act_change_price { public partial class ListOfDocumentsForm : Form { public const uint GENERIC_WRITE = 0x40000000; public const uint FILE_SHARE_READ = 0x00000001; public const uint OPEN_EXISTING = 3; [DllImport("kernel32.dll", SetLastError = true)] static extern SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile); [DllImport("kernel32.dll", SetLastError = true)] static extern bool WriteFile(SafeFileHandle hFile, String lpBuffer, uint nNumberOfBytesToWrite, out uint lpBufferOfBytesWritten, IntPtr lpOverlapped); public ListOfDocumentsForm() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) //OK button { own_PreViewAct(); } private void button2_Click(object sender, EventArgs e) //Cancel button { Close(); } private void ListOfDocumentsForm_Shown(object sender, EventArgs e) { if (dataGridView1.RowCount <= 0) button1.Enabled = false; else dataGridView1.Rows[0].Selected = true; } private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.RowCount > 0 && e.RowIndex >= 0 && e.ColumnIndex >= 0) { own_PreViewAct(); } } private void own_PreViewAct() { uint k = 0; try { string MailSlotName = ""; if(wv2.whichcase == 0) wv2.docdate = Convert.ToDateTime(dataGridView1.SelectedRows[0].Cells[1].Value).ToShortDateString(); if (wv2.whichcase == 2) m_ResultParams = "P_DATENAME=" + char.ToString('"') + "Дата исполнения" + char.ToString('"') + " P_DATE=" + wv2.execdate; else m_ResultParams = "P_DATENAME=" + char.ToString('"') + "Дата документа" + char.ToString('"') + " P_DATE=" + wv2.docdate; m_ResultParams += " P_DOC_ID=" + char.ToString('"') + Convert.ToString(dataGridView1.SelectedRows[0].Cells[0].Value).Trim() + char.ToString('"'); MailSlotName = Environment.CommandLine; int iPos = MailSlotName.IndexOf(" "); MailSlotName = iPos > 0 ? MailSlotName.Substring(0, iPos) : MailSlotName; SafeFileHandle hFile = null; hFile = CreateFile(MailSlotName, GENERIC_WRITE, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero); if (hFile.IsInvalid) { MessageBox.Show("MailSlot недоступен клиенту.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!WriteFile(hFile, m_ResultParams, (uint)(m_ResultParams.Length), out k, IntPtr.Zero)) { MessageBox.Show("Ошибка записи в MailSlot. Ошибка!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } hFile.Close(); } catch (Exception ex) { MessageBox.Show("Function name: 'button1_Click(object sender, EventArgs e)'\n" + "Method name: " + ex.TargetSite.ToString() + "\nMessage: " + ex.Message, "Error message", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } Close(); } } }