Esempio n. 1
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         _reader?.Dispose();
     }
 }
Esempio n. 2
0
            public IEnumerable <Student> Get()
            {
                ObservableCollection <Student> products = new ObservableCollection <Student>();
                Conexion            _conexion           = new Conexion();
                List <SqlParameter> _Parametros         = new List <SqlParameter>();
                DataTableReader     dtr = null;
                Student             p   = null;

                _conexion.Conectar();
                _conexion.PrepararProcedimiento("dbo.GetAllStudents", _Parametros);
                dtr = _conexion.EjecutarTableReader();
                while (dtr.Read())
                {
                    p           = new Student();
                    p.IdStudent = Int32.Parse(dtr["IdStudent"].ToString());
                    p.Name      = dtr["Name"].ToString();
                    p.LastName  = dtr["LastName"].ToString();
                    p.LastNameM = dtr["LastNameM"].ToString();
                    p.DOB       = DateTime.Parse(dtr["DOB"].ToString());
                    p.Status    = Int32.Parse(dtr["Status"].ToString());
                    if (p.Status == 1)
                    {
                        products.Add(p);
                    }
                }
                _conexion.Desconectar();
                _conexion = null;
                if (dtr != null)
                {
                    dtr.Close(); dtr.Dispose();
                }
                return(products);
            }
        private void PropertiesSharedWorkFolderDialog_Load(object sender, EventArgs e)
        {
            var empID = Environment.SharedFolderData.GetOwnerID(id);
            var emp   = new Employee(empID, Environment.EmpData);

            labelCreator.Text += emp.LongName;

            using (DataTable dt = Environment.SharedFolderData.GetClients(id))
                using (DataTableReader dr = dt.CreateDataReader())
                {
                    while (dr.Read())
                    {
                        empID = (int)dr[Environment.SharedFolderData.ClientIDField];
                        emp   = new Employee(empID, Environment.EmpData);

                        listViewAllowed.Items.Add(new ListViewItem(new string[2]
                        {
                            emp.LongName,
                            Environment.SharedFolderData.Rights(id, empID)
                                                                           ? Environment.StringResources.GetString(
                                "Full")
                                                                           : Environment.StringResources.GetString(
                                "ReadOnly")
                        }
                                                                   ));
                    }
                    dr.Close();
                    dr.Dispose();
                    dt.Dispose();
                }
        }
        private void DocProertiesPersons_Load(DateTime date)
        {
            using (DataTable dt = Environment.DocData.GetDocPersons(DocID, date))
                using (DataTableReader dr = dt.CreateDataReader())
                {
                    if (dr.HasRows)
                    {
                        originalPersons = new Dictionary <int, int>();
                        while (dr.Read())
                        {
                            var  personId = (int)dr[Environment.PersonData.IDField];
                            var  person   = (string)dr[Environment.PersonData.NameField];
                            var  position = (byte)dr[Environment.DocData.PersonPositionField];
                            bool isValid  = 0 < (int)dr[Environment.DocData.PersonIsValidField];

                            if (!originalPersons.ContainsKey(personId))
                            {
                                originalPersons.Add(personId, position);
                            }
                            else if (originalPersons[personId] < position)
                            {
                                originalPersons[personId] = position;
                            }
                            if (!string.IsNullOrEmpty(person))
                            {
                                personBlock.AddPerson(personId, person, position, isValid);
                            }
                        }
                    }
                    dr.Close();
                    dr.Dispose();
                    dt.Dispose();
                }
        }
        private void DocUserListDialog_Load(object sender, EventArgs e)
        {
            Text += docID.ToString() + ")";

            empList.Columns.Add(Environment.StringResources.GetString("Employee"), 180, HorizontalAlignment.Left);
            empList.Columns.Add(Environment.StringResources.GetString("InWork"), empList.Width - 200,
                                HorizontalAlignment.Center);

            using (DataTable dt = Environment.DocData.GetDocRights(docID))
                using (DataTableReader dr = dt.CreateDataReader())
                {
                    while (dr.Read())
                    {
                        var empID = (int)dr[Environment.DocData.EmpIDField];

                        var values = new string[2];

                        values[0] = dr[Environment.DocData.EmpField].ToString();

                        var rights = (int)dr[Environment.DocData.InWorkField];

                        if (rights == 1)
                        {
                            values[1] = Environment.StringResources.GetString("Yes");
                        }

                        var li = new ListItem(empID, values);
                        li.ToolTipText = li.Text;
                        empList.Items.Add(li);
                    }
                    dr.Close();
                    dr.Dispose();
                    dt.Dispose();
                }
        }
Esempio n. 6
0
        public void CreateFaxRoot <T>(SynchronizedCollection <T> faxNodes, Func <String, DataTable> execFunc, Func <int, string, string, T> CreateRoot) where T : FaxNode
        {
            faxNodes = new SynchronizedCollection <T>();

            using (DataTable dt = execFunc(Environment.CurCultureInfo.TwoLetterISOLanguageName))
                using (DataTableReader dr = dt.CreateDataReader())
                {
                    while (dr.Read())
                    {
                        var nodeID   = (int)dr[Environment.FaxFolderData.IDField];
                        var nodeName = (string)dr[Environment.FaxFolderData.NameField];
                        var nodePath = (string)dr[Environment.FaxFolderData.NetworkPathField];
                        var server   = Lib.Win.Document.Environment.GetServers().FirstOrDefault(t => Directory.Exists(Path.Combine(t.FaxPath, nodePath)));

                        if (server != null && !string.IsNullOrEmpty(server.FaxPath))
                        {
                            if (DirectoryAnalyser.IsAccessible(Path.Combine(server.FaxPath, nodePath)))
                            {
                                T node = CreateRoot(nodeID, nodeName, Path.Combine(server.FaxPath, nodePath));
                                PrepareAndAdd(node);
                                faxNodes.Add(node);
                            }
                        }
                    }
                    dr.Close();
                    dr.Dispose();
                    dt.Dispose();
                }
        }
 private void Init()
 {
     using (DataTable dt = Environment.OPFormsData.OPForms())
         using (DataTableReader dr = dt.CreateDataReader())
         {
             int maxWidth = cbOrganizationalForm.DropDownWidth;
             using (Graphics g = Graphics.FromHwnd(Handle))
             {
                 while (dr.Read())
                 {
                     var    id    = (int)dr[Environment.OPFormsData.IDField];
                     string name  = dr[Environment.OPFormsData.NameField].ToString();
                     var    item  = new ComboBoxItem(id, name);
                     SizeF  size  = g.MeasureString(item.ToString(), Font);
                     int    width = (int)size.Width + 5;
                     if (width <= 500)
                     {
                         maxWidth = Math.Max(maxWidth, width);
                     }
                     cbOrganizationalForm.Items.Add(item);
                 }
             }
             cbOrganizationalForm.DropDownWidth = maxWidth;
             dr.Close();
             dr.Dispose();
             dt.Dispose();
         }
     gbProject.Enabled = false;
 }
Esempio n. 8
0
        protected override void FillForm()
        {
            string id = elOption.GetAttribute("value");

            using (
                DataTable dt =
                    Environment.TransactionTypeData.GetData(Environment.CurCultureInfo.TwoLetterISOLanguageName))
                using (DataTableReader dr = dt.CreateDataReader())
                {
                    while (dr.Read())
                    {
                        ListViewItem item = new ListViewItem(dr[Environment.TransactionTypeData.NameField].ToString())
                        {
                            Tag = dr[Environment.TransactionTypeData.IDField]
                        };
                        lv“ипы.Items.Add(item);
                        if (item.Tag.ToString() == id)
                        {
                            item.Selected = true;
                        }
                    }
                    cHName.Width = dt.Rows.Count < 9
                                   ? lv“ипы.Width - 5
                                   : lv“ипы.Width - SystemInformation.VerticalScrollBarWidth - 4;

                    dr.Close();
                    dr.Dispose();
                    dt.Dispose();
                }
        }
Esempio n. 9
0
 public void Dispose()
 {
     if (!isDisposed)
     {
         reader.Dispose();
         columns.Clear();
         columns    = null;
         isDisposed = true;
     }
 }
Esempio n. 10
0
        private void FillList()
        {
            try
            {
                list.BeginUpdate();
                list.Items.Clear();

                using (DataTable dt = Environment.FolderData.GetClients(folderID))
                    using (DataTableReader dr = dt.CreateDataReader())
                    {
                        while (dr.Read())
                        {
                            int      id    = (int)dr[Environment.FolderData.ShareIDField];
                            int      empID = (int)dr[Environment.FolderData.ClientIDField];
                            Employee emp   = new Employee(empID, Environment.EmpData);

                            AccessLevel rights     = AccessLevel.ReadOnly;
                            var         byteRights = (byte)dr[Environment.FolderData.RightsField];
                            if (byteRights == 1)
                            {
                                rights = AccessLevel.FullAccess;
                            }

                            var wfItem = new WFAccessItem(id, empID, emp.ShortName, rights);

                            if (rights == AccessLevel.FullAccess)
                            {
                                wfItem.ImageIndex = 0;
                            }

                            list.Items.Add(wfItem);
                        }
                        dr.Close();
                        dr.Dispose();
                        dt.Dispose();
                    }

                list.Sort();
                list.EndUpdate();
            }
            catch (Exception ex)
            {
                Lib.Win.Data.Env.WriteToLog(ex);
            }
        }
Esempio n. 11
0
        public override void LoadSubNodes()
        {
            Nodes.Clear();

            if (TreeView != null)
            {
                TreeView.Cursor = Cursors.WaitCursor;
            }

#if AdvancedLogging
            using (Lib.Log.Logger.DurationMetter("FoundNode LoadSubNodes() using(DataTable dt = Environment.QueryData.GetSearchParamSets(Emp.ID))"))
#endif
            using (DataTable dt = Environment.QueryData.GetSearchParamSets(Emp.ID))
                using (DataTableReader dr = dt.CreateDataReader())
                {
                    while (dr.Read())
                    {
                        var nodeID = (int)dr[Environment.QueryData.IDField];
                        if (nodeID == rootID)
                        {
                            continue;
                        }

                        var nodeName  = (string)dr[Environment.QueryData.NameField];
                        var nodeXML   = (string)dr[Environment.QueryData.XMLField];
                        var nodeEmpID = (int)dr[Environment.QueryData.EmpIDField];
                        var nodeEmp   = new Employee(nodeEmpID, Environment.EmpData);
                        var node      = new FoundNode(nodeID, nodeName, nodeEmp, nodeXML);
                        Nodes.Add(node);
                    }
                    dr.Close();
                    dr.Dispose();
                    dt.Dispose();
                }

            if (TreeView != null)
            {
                TreeView.Cursor = Cursors.Default;
            }

            base.LoadSubNodes();
        }
        private void ShowTran(DataTable dt)
        {
            using (DataTableReader dr = dt.CreateDataReader())
            {
                while (dr.Read())
                {
                    if (dr[Environment.TransactionData.IDField] != null &&
                        !dr[Environment.TransactionData.IDField].Equals(DBNull.Value))
                    {
                        Visible = true;
                        string labelText = "";

                        //получаем коды транзакции
                        var id = (int)dr[Environment.TransactionData.IDField];
                        // Проставляем текст транзакции
                        labelText = dr[Environment.TransactionData.NameField].ToString();
                        // добавляем готовый элемент в коллекцию
                        CreateLabel(labelText, id);
                    }
                }
                dr.Close();
                dr.Dispose();
                dt.Dispose();
            }
            SuspendLayout();
            AddingLabels((System.Windows.Forms.Control[])linkArray.ToArray(typeof(System.Windows.Forms.Control)));
            if (Width < maxWidth)
            {
                Height = curHeigth + 17;
            }
            else
            {
                Height = curHeigth;
            }
            ResumeLayout(false);
            if (curHeigth < curLabelHeigth)
            {
                AutoScroll = true;
            }
            Refresh();
        }
Esempio n. 13
0
        public IHttpActionResult Authenticate(LoginRequest login)
        {
            if (login == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            Conexion            _conexion   = new Conexion();
            List <SqlParameter> _Parametros = new List <SqlParameter>();
            DataTableReader     dtr         = null;
            LoginRequest        p           = null;

            _conexion.Conectar();
            _conexion.PrepararProcedimiento("LoginUser", _Parametros);
            _Parametros.Add(new SqlParameter("@User", login.Username));
            dtr = _conexion.EjecutarTableReader();
            while (dtr.Read())
            {
                p          = new LoginRequest();
                p.Password = dtr["Password"].ToString();
            }
            _conexion.Desconectar();
            _conexion = null;
            if (dtr != null)
            {
                dtr.Close(); dtr.Dispose();
            }


            bool isCredentialValid = (login.Password == p.Password);

            if (isCredentialValid)
            {
                var token = TokenGenerator.GenerateTokenJwt(login.Username);
                return(Ok(token));
            }
            else
            {
                return(Unauthorized());
            }
        }
        public int LoadDocLinks(int docID)
        {
            int returnCount = 0;

            using (DataTable dt = Environment.DocLinksData.GetLinksDocs(docID, false, true))
                using (DataTableReader dr = dt.CreateDataReader())
                {
                    while (dr.Read())
                    {
                        var documentID = (int)dr[Environment.DocLinksData.DocumentIDField];
                        if (AddDoc(documentID, true, true))
                        {
                            returnCount++;
                        }
                    }
                    dr.Close();
                    dr.Dispose();
                    dt.Dispose();
                }

            using (DataTable dt = Environment.DocLinksData.GetLinksDocs(docID, false, false))
                using (DataTableReader dr = dt.CreateDataReader())
                {
                    while (dr.Read())
                    {
                        var documentID = (int)dr[Environment.DocLinksData.DocumentIDField];
                        if (AddDoc(documentID, false, true))
                        {
                            returnCount++;
                        }
                    }
                    dr.Close();
                    dr.Dispose();
                    dt.Dispose();
                }
            return(returnCount);
        }
        public XmlSearchForm(int docID) : this()
        {
            try
            {
                DocID = docID;

                using (DataTable dt = Environment.DocData.GetDocPersonsLite(docID, false))
                    using (DataTableReader dr = dt.CreateDataReader())
                    {
                        if (dr.HasRows)
                        {
                            XmlElement child = xml.CreateElement("Option");
                            if (xml.DocumentElement != null)
                            {
                                xml.DocumentElement.AppendChild(child);
                            }
                            string temp = "";
                            while (dr.Read())
                            {
                                temp += (temp.Length > 0 ? "," : "") + dr[Environment.PersonData.IDField];
                            }

                            child.SetAttribute("name", "ЛицаКонтрагенты");
                            child.SetAttribute("value", temp);
                            child.SetAttribute("mode", "and");
                        }
                        dr.Close();
                        dr.Dispose();
                        dt.Dispose();
                    }
            }
            catch (Exception ex)
            {
                Lib.Win.Data.Env.WriteToLog(ex);
            }
        }
Esempio n. 16
0
        private void OpenDoc()
        {
            if (!docGrid.IsFine)
            {
                return;
            }

            buttonOpenDoc.Enabled = false;
            buttonOK.Enabled      = false;

            Thread.CurrentThread.CurrentUICulture = Environment.CurCultureInfo;
            if (docGrid.IsSingle && docGrid.CurrentRow != null)
            {
                object obj = docGrid.GetCurID();
                if (obj is int)
                {
                    var testdocID = (int)obj;
                    if (testdocID >= 0 && testdocID != DocID)
                    {
                        DocID = testdocID;
                        docControl.DocumentID = DocID;
                        buttonOK.Enabled      = (DocID > 0) && (DocID != curDocID);
                        buttonOpenDoc.Enabled = (DocID > 0) && (DocID != curDocID);
                        listPersons.Items.Clear();
                        using (DataTable dt = Environment.DocData.GetDocPersons(DocID))
                            using (DataTableReader dr = dt.CreateDataReader())
                            {
                                while (dr.Read())
                                {
                                    var    personID = (int)dr[Environment.PersonData.IDField];
                                    string person   = dr[Environment.PersonData.NameField].ToString();
                                    int    position = (byte)dr[Environment.DocData.PersonPositionField];
                                    bool   isValid  = 0 < (int)dr[Environment.DocData.PersonIsValidField];

                                    if (person != null)
                                    {
                                        var item = new Document.Items.PersonListItem(personID, person, Environment.PersonURL + personID.ToString(), position, isValid);
                                        listPersons.Items.Add(item);
                                    }
                                }
                                dr.Close();
                                dr.Dispose();
                                dt.Dispose();
                            }

                        // update link tree
                        linkList.DocID = DocID;
                        return;
                    }
                    else
                    {
                        if (testdocID == DocID)
                        {
                            buttonOK.Enabled      = (DocID > 0) && (DocID != curDocID);
                            buttonOpenDoc.Enabled = (DocID > 0) && (DocID != curDocID);
                            return;
                        }
                    }
                }
                buttonOpenDoc.Enabled = false;
                buttonOK.Enabled      = false;
            }
            else if (docGrid.IsMultiple)
            {
                buttonOK.Enabled      = true;
                buttonOpenDoc.Enabled = true;
            }
            docControl.FileName = null;
            DocID = 0;
            listPersons.Items.Clear();
            linkList.DocID        = DocID;
            docControl.DocumentID = DocID;
        }
Esempio n. 17
0
 public void Dispose()
 {
     _reader.Dispose();
 }
        /// <summary>
        ///   Инициализация формы, вывод ин-ии по сотруднику
        /// </summary>
        private void CreateForm()
        {
            const int x         = 5;
            int       y         = 5;
            var       phoneList = new ArrayList();

            using (DataTable dt = Environment.EmpData.GetContacts(emp.ID))
                using (DataTableReader dr = dt.CreateDataReader())
                {
                    while (dr.Read())
                    {
                        if ((dr["dial"].ToString().Equals(string.Empty)) || (phoneList.Contains(dr["view"].ToString())) ||
                            (!dr["type"].Equals(20) &&
                             !dr["type"].Equals(21) &&
                             !dr["type"].Equals(22) &&
                             !dr["type"].Equals(0)))
                        {
                            continue;
                        }
                        try
                        {
                            phoneList.Add(dr["view"].ToString());
                            PictureBox pb = CreateContactIcon(x, y, Convert.ToInt32(dr["type"]));
                            pb.Tag = dr["dial"];

                            Label lab = CreateContactLabel(pb.Location.X + pb.Width + 10, y, dr["view"].ToString(),
                                                           Convert.ToInt32(dr["type"]));
                            lab.Tag = dr["dial"];

                            MainPanel.Controls.Add(pb);
                            MainPanel.Controls.Add(lab);
                            y += pb.Height + 5;
                        }
                        catch (Exception ex)
                        {
                            Data.Env.WriteToLog(ex);
                        }
                    }
                    dr.Close();
                    dr.Dispose();
                    dt.Dispose();
                }
            PictureBox pBox = CreateContactIcon(x, y, 1);

            toolTip1.SetToolTip(pBox, "Email");

            Label l = CreateContactLabel(pBox.Location.X + pBox.Width + 10, y, emp.EmpEMail, 1);

            toolTip1.SetToolTip(l, "Email");

            MainPanel.Controls.Add(pBox);
            MainPanel.Controls.Add(l);
            y += pBox.Height + 5;

            pBox = CreateContactIcon(x, y, 2);
            toolTip1.SetToolTip(pBox, "Messanger");
            l = CreateContactLabel(pBox.Location.X + pBox.Width + 10, y, emp.EmpEMail, 2);
            toolTip1.SetToolTip(l, "Messanger");
            MainPanel.Controls.Add(pBox);
            MainPanel.Controls.Add(l);

            Height = l.Location.Y + l.Height + 10;
            if (MainPanel.Height > 500)
            {
                MainPanel.AutoScroll = true;
                Height = 500;
            }
        }
Esempio n. 19
0
        public override ContextMenu BuildContextMenu()
        {
            var contextMenu = new ContextMenu();

            if (grid.IsSingle)
            {
                contextMenu.MenuItems.AddRange(new[] { scanCurrentDocument, addImageCurrentDoc, linkEFormItem, separator.CloneMenu(), savePartItem, saveSelectedItem, separator.CloneMenu(), newEFormItem, separator.CloneMenu(), sendMessageItem, createAnswerItem, separator.CloneMenu() });

                if (grid.MainForm != null)
                {
                    saveSelectedItem.Enabled = grid.MainForm.docControl.RectDrawn() && grid.MainForm.docControl.CanSendOut;
                }
                if (Environment.CmdManager.Commands.Contains("SavePart"))
                {
                    savePartItem.Enabled = grid.MainForm.docControl.CompliteLoading && Environment.CmdManager.Commands["SavePart"].Enabled;
                }

                int docID     = grid.GetCurID();
                var docTypeID = (int)grid.GetCurValue(Environment.DocData.DocTypeIDField);

                newEFormItem.Enabled = (!Environment.DocDataData.IsDataPresent(docID) && Environment.DocTypeData.GetDocBoolField(Environment.DocTypeData.FormPresentField, docTypeID));

                linkEFormItem.MenuItems.Clear();

                createAnswerItem.Enabled = Environment.DocTypeData.GetDocBoolField(Environment.DocTypeData.AnswerFormField, docTypeID);

                DataRow dar = null;
                using (DataTable typesTable = Environment.DocTypeLinkData.GetLinkedTypes(docTypeID))
                {
                    for (int j = 0; j < typesTable.Rows.Count; j++)
                    {
                        dar = typesTable.Rows[j];
                        IDMenuItem it = new IDMenuItem((int)dar[Environment.DocTypeLinkData.ChildTypeIDFeild]);
                        it.Text   = dar[Environment.DocTypeLinkData.NameField] + ((DBNull.Value.Equals(dar[Environment.FieldData.NameField]) ? "" : ("(" + Environment.StringResources.GetString("OnField") + " " + dar[Environment.FieldData.NameField]) + ")"));
                        it.Tag    = dar;
                        it.Click += linkEFormItem_Click;
                        linkEFormItem.MenuItems.Add(it);
                    }
                }

                linkEFormItem.Enabled = (linkEFormItem.MenuItems.Count > 0);

                toPersonItem.MenuItems.Clear();

                // есть ли в группировке лица?
                if (Environment.UserSettings.GroupOrder.Contains(CatalogNode.PersonInitial))
                {
                    using (DataTable personTable = Environment.DocData.GetDocPersonsLite(docID, false))
                        using (DataTableReader dr = personTable.CreateDataReader())
                        {
                            Dictionary <int, IDMenuItem> dic = new Dictionary <int, IDMenuItem>();

                            while (dr.Read())
                            {
                                var personID = (int)dr[Environment.PersonData.IDField];
                                if (Environment.UserSettings.PersonID != personID || personTable.Rows.Count == 1)
                                {
                                    if (dic.ContainsKey(personID))
                                    {
                                        continue;
                                    }
                                    IDMenuItem item = new IDMenuItem(personID);
                                    item.Text = dr[Environment.PersonData.NameField] as string ??
                                                Environment.StringResources.GetString("MainForm.MainFormDialog.menuDoc_Popup.Message1");
                                    item.Click += toPerson_Click;
                                    dic.Add(personID, item);
                                }
                            }
                            dr.Close();
                            dr.Dispose();
                            personTable.Dispose();
                            if (dic.Count > 0)
                            {
                                toPersonItem.MenuItems.AddRange(dic.Values.ToArray());
                            }
                            dic.Clear();
                        }
                }

                contextMenu = AddOwnMenu(contextMenu);

                int empID = (grid.MainForm != null) ? grid.MainForm.curEmpID : Environment.CurEmp.ID;

                if (!Environment.WorkDocData.IsInWork(docID, empID))
                {
                    contextMenu.MenuItems.Add(toWorkItem);
                }
                else
                {
                    contextMenu.MenuItems.AddRange(new[] { moveItem, separator.CloneMenu(), endWorkItem });
                }

                contextMenu.MenuItems.AddRange(new[] { separator.CloneMenu(), toPersonItem, openInNewWindowItem, separator.CloneMenu(), deleteItem, separator.CloneMenu(), refreshItem, separator.CloneMenu(), propertiesItem });

                toPersonItem.Enabled = (toPersonItem.MenuItems.Count > 0);

                deleteItem.Enabled = (Environment.EmpData.IsDocDeleter() || !Environment.DocImageData.DocHasImages(docID, true));
            }
            else if (grid.IsMultiple)
            {
                contextMenu = AddOwnMenu(contextMenu);

                contextMenu.MenuItems.AddRange(new[] { separator.CloneMenu(), sendMessageItem, separator.CloneMenu() });

                if (grid.IsInWork())
                {
                    contextMenu.MenuItems.AddRange(new[] { moveItem, separator.CloneMenu(), endWorkItem });
                }
                else
                {
                    contextMenu.MenuItems.Add(toWorkItem);
                }

                contextMenu.MenuItems.AddRange(new[] { separator.CloneMenu(), openInNewWindowItem });
            }
            else if (grid.SelectedRows.Count > 500)
            {
                MessageBox.Show(Environment.CurCultureInfo.Name.Equals("ru") ? "¬ыделено слишком много документов! ¬ыберите, пожалуйста, чуть меньше документов дл¤ работы." : "Too many rows have been selected!");
            }

            return(contextMenu.MenuItems.Count > 0 ? contextMenu : null);
        }
        private void LoadImages()
        {
            RefreshStatus();
            if (listViewImages.Items.Count > 0)
            {
                listViewImages.Clear();
            }
            if (!isLoad)
            {
                return;
            }
            if (docID > 0)
            {
                ListItem selecteditem = null; // индекс текущего изображения
                int      mainImageID  = 0;
                bool     hasImage     = false;
                // получаем изображения
                using (DataTable dt = Environment.DocImageData.GetDocImages(docID, false))
                {
                    hasImage = (dt.Rows.Count > 0);
                    if (hasImage)
                    {
                        // получаем основное изображение
                        mainImageID = Environment.DocData.GetDocIntField(Environment.DocData.MainImageIDField, docID);
                    }
                    using (DataTableReader dr = dt.CreateDataReader())
                    {
                        while (dr.Read())
                        {
                            var imgId = (int)dr[Environment.DocImageData.IDField];
                            if (imgId == OldImageID)
                            {
                                hasImage = (dt.Rows.Count > 1);
                                continue;
                            }
                            var createDate = (DateTime)dr[Environment.DocImageData.CreateDateField];
                            var editedDate = (DateTime)dr[Environment.DocImageData.EditedField];
                            var archiveID  = (int)dr[Environment.DocImageData.ArchiveIDField];
                            var item       = new VariantListItem(
                                imgId,
                                VariantType.Image,
                                createDate.ToLocalTime().ToString("dd.MM.yyyy"))
                            {
                                CreateTime = createDate, EditedTime = editedDate
                            };
                            int printed = (dr[Environment.DocImageData.PrintedField] is DBNull)
                                              ? 0
                                              : Convert.ToInt32(dr[Environment.DocImageData.PrintedField]);
                            item.Printed = printed > 0;

                            item.ImageType = dr[Environment.DocImageData.ImageTypeField].ToString();

                            if (item.Printed)
                            {
                                object a1 = Environment.PrintData.GetField(Environment.PrintData.NameField, printed);
                                if (a1 != null)
                                {
                                    item.Text = a1.ToString();
                                }
                            }
                            if (imgId == mainImageID)
                            {
                                if (archiveID != 0)
                                {
                                    if (printed > 0)
                                    {
                                        item.ImageIndex = (int)VariantType.MainImageOriginalPrinted;
                                        item.Type       = VariantType.MainImageOriginalPrinted;
                                    }
                                    else
                                    {
                                        item.ImageIndex = item.IsPDF() ? 20 : (int)VariantType.MainImageOriginal;
                                        item.Type       = VariantType.MainImageOriginal;
                                    }
                                }
                                else
                                {
                                    if (printed > 0)
                                    {
                                        item.ImageIndex = (int)VariantType.MainImagePrinted;
                                        item.Type       = VariantType.MainImagePrinted;
                                    }
                                    else
                                    {
                                        item.ImageIndex = item.IsPDF() ? 18 : (int)VariantType.MainImage;
                                        item.Type       = VariantType.MainImage;
                                    }
                                }
                            }
                            else
                            {
                                if (archiveID != 0)
                                {
                                    if (printed > 0)
                                    {
                                        item.ImageIndex = (int)VariantType.ImageOriginalPrinted;
                                        item.Type       = VariantType.ImageOriginalPrinted;
                                    }
                                    else
                                    {
                                        item.ImageIndex = item.IsPDF() ? 19 : (int)VariantType.ImageOriginal;
                                        item.Type       = VariantType.ImageOriginal;
                                    }
                                }
                                else
                                {
                                    if (printed > 0)
                                    {
                                        item.ImageIndex = (int)VariantType.ImagePrinted;
                                        item.Type       = VariantType.ImagePrinted;
                                    }
                                    else
                                    {
                                        item.ImageIndex = item.IsPDF() ? 17 : (int)VariantType.Image;
                                    }
                                }
                            }
                            listViewImages.Items.Add(item);
                            if (mainImageID == imgId)
                            {
                                selecteditem = item;
                            }
                        }
                        dr.Close();
                        dr.Dispose();
                        dt.Dispose();
                    }
                }
                if (!hasImage)
                {
                    ImageID = 0;
                    if (
                        MessageBox.Show(Environment.StringResources.GetString("Select_SelectImageDialog_Message1"),
                                        Environment.StringResources.GetString("Conformation"), MessageBoxButtons.YesNoCancel) ==
                        DialogResult.Yes)
                    {
                        DialogResult = DialogResult.OK;
                    }
                    Close();
                }
            }
            else
            {
                Close();
            }
        }
        private void PropertiesDocImageDialog_Load(object sender, EventArgs e)
        {
            date             = DateTime.Now;
            archive.ReadOnly = true;

            if (ImageID != 0)
            {
                Text += (Environment.CurCultureInfo.TwoLetterISOLanguageName.Equals("ru") ? " (код " : " ( image ID ") + ImageID + ")";

                labelDoc.Text = DBDocString.Format(docID);

                DataRow docImageRow = Environment.DocImageData.GetDocImage(ImageID);
                if (docImageRow == null)
                {
                    MessageBox.Show(Environment.StringResources.GetString("Properties_PropertiesDocImageDialog_PropertiesDocImageDialog_Load_Message1") + " " +
                                    ImageID + " " + Environment.StringResources.GetString("Properties_PropertiesDocImageDialog_PropertiesDocImageDialog_Load_Message2"));
                    Close();
                }
                else
                {
                    docID = (int)docImageRow[Environment.DocImageData.DocIDField];
                    date  = (DateTime)docImageRow[Environment.DocImageData.CreateDateField];

                    labelDate.Text += " " + date.ToLocalTime().ToString("dd.MM.yyyy HH:mm:ss");

                    labelEdit.Text    += " " + ((DateTime)docImageRow[Environment.DocImageData.EditedField]).ToLocalTime().ToString("dd.MM.yyyy HH:mm:ss");
                    linkEditor.Url     = Environment.UsersURL + (int)docImageRow[Environment.DocImageData.EditorField];
                    linkEditor.Text    = Environment.EmpData.GetEmployee((int)docImageRow[Environment.DocImageData.EditorField], false);
                    linkEditor.Caption = string.Format("№{0} {1}", (int)docImageRow[Environment.DocImageData.EditorField], linkEditor.Text);

                    linkCreator.Url     = Environment.UsersURL + (int)docImageRow[Environment.DocImageData.CreatorField];
                    linkCreator.Text    = Environment.EmpData.GetEmployee((int)docImageRow[Environment.DocImageData.CreatorField], false);
                    linkCreator.Caption = string.Format("№{0} {1}", (int)docImageRow[Environment.DocImageData.CreatorField], linkCreator.Text);

                    printedID = 0;
                    if (docImageRow[Environment.DocImageData.PrintedField] is int)
                    {
                        printedID = (int)docImageRow[Environment.DocImageData.PrintedField];
                    }
                    if (printedID > 0)
                    {
                        object a1 = Environment.PrintData.GetField(Environment.PrintData.NameField, printedID);
                        Text = Environment.StringResources.GetString("PrintedImageProperties") + ((a1 != null) ? " \"" + a1 + "\"" : "") + (Environment.CurCultureInfo.TwoLetterISOLanguageName.Equals("ru") ? " (код " : " ( image ID ") + ImageID + ")";
                        groupBoxMainImage.Text = Environment.StringResources.GetString("Properties_PropertiesDocImageDialog_PropertiesDocImageDialog_Load_Message7");
                    }

                    archiveID = (int)docImageRow[Environment.DocImageData.ArchiveIDField];

                    _originalArchiveId = archiveID;

                    if (archiveID != 0)
                    {
                        archive.Text     = Environment.ArchiveData.GetArchive(archiveID);
                        original.Checked = true;
                    }

                    var eId = (int)docImageRow[Environment.DocImageData.ArchiveEditorField];
                    if (eId > 0)
                    {
                        archiveEditLabel.Text    += " " + ((DateTime)docImageRow[Environment.DocImageData.ArchiveEditField]).ToLocalTime().ToString("dd.MM.yyyy HH:mm:ss");
                        linkArchiveEditor.Url     = Environment.UsersURL + eId;
                        linkArchiveEditor.Text    = Environment.EmpData.GetEmployee(eId, false);
                        linkArchiveEditor.Caption = string.Format("№{0} {1}", eId, linkArchiveEditor.Text);
                    }

                    // основное ли изображение
                    mainImage = (Environment.DocData.GetDocIntField(Environment.DocData.MainImageIDField, docID) == ImageID);

                    imageType = docImageRow[Environment.DocImageData.ImageTypeField].ToString();

                    labelDoc.Text += System.Environment.NewLine + Environment.StringResources.GetString("Properties_PropertiesDocImageDialog_ImageType_Title") +
                                     (imageType.ToUpper() == "PDF" ? "Adobe Acrobat Document" : "Microsoft Office Document Imaging File") + " (" + imageType.ToUpper() + ")";
                    labelDoc.Text += System.Environment.NewLine + Environment.StringResources.GetString("FileSize") + ": " + ((int)docImageRow[Environment.DocImageData.FileSizeField]).ToString("N0") + " " + Environment.StringResources.GetString("Byte")
                                     + "      " + Environment.StringResources.GetString("Pages") + ": " + docImageRow[Environment.DocImageData.PageCountField].ToString();
                }

                // loading servers
                servers.Columns.Add(Environment.StringResources.GetString("Archive"), servers.Width - 80, HorizontalAlignment.Left);
                servers.Columns.Add(Environment.StringResources.GetString("Place"), 70, HorizontalAlignment.Left);

                using (DataTable dt = Environment.DocImageData.GetDocImageServers(ImageID))
                    using (DataTableReader dr = dt.CreateDataReader())
                    {
                        var      fields = new string[3];
                        FileInfo fi     = null;

                        while (dr.Read())
                        {
                            fields[0] = (string)dr[Environment.DocImageData.ServerField];
                            var local = (int)dr[Environment.DocImageData.LocalField];

                            if (local != 0)
                            {
                                if (string.IsNullOrEmpty(fileName))
                                {
                                    fileName = dr[Environment.DocImageData.NetworkPathField] + "\\" + Environment.GetFileNameFromID(ImageID) +
                                               "." + imageType.ToLower();
                                }

                                fields[1] = Environment.StringResources.GetString("Local");
                                fi        = new FileInfo(dr[Environment.DocImageData.NetworkPathField] + "\\" + Environment.GetFileNameFromID(ImageID) + "." + imageType.ToLower());
                            }
                            else
                            {
                                fields[1] = Environment.StringResources.GetString("External");
                                fi        = new FileInfo(dr[Environment.DocImageData.NetworkPathField] + "\\" + Environment.GetFileNameFromID(ImageID) + "." + imageType.ToLower());
                            }
                            var item = new ListViewItem(fields);
                            item.ToolTipText = item.Text;
                            servers.Items.Add(item);
                        }
                        dr.Close(); dr.Dispose(); dt.Dispose();
                    }

                sended.Columns.Add(Environment.StringResources.GetString("Sender"), 110, HorizontalAlignment.Left);
                sended.Columns.Add(Environment.StringResources.GetString("Receiver"), 110, HorizontalAlignment.Left);
                sended.Columns.Add(Environment.StringResources.GetString("Contact"), sended.Width - 350, HorizontalAlignment.Left);
                sended.Columns.Add(Environment.StringResources.GetString("SendTime"), 110, HorizontalAlignment.Left);

                using (DataTable dt = Environment.DocImageData.GetLogForImage(ImageID))
                    using (DataTableReader dr = dt.CreateDataReader())
                    {
                        while (dr.Read())
                        {
                            var direction = (int)dr[Environment.DocImageData.DirectionField];

                            if (direction == 1)
                            {
                                var    sb      = new StringBuilder();
                                string testStr = dr[Environment.DocImageData.SenderField].ToString();
                                if (testStr.Length > 0)
                                {
                                    sb.Append(System.Environment.NewLine);
                                    sb.Append(Environment.StringResources.GetString("Properties_PropertiesDocImageDialog_PropertiesDocImageDialog_Load_Message3"));
                                    sb.Append(" ");
                                    sb.Append(testStr);
                                }
                                sb.Append(System.Environment.NewLine);
                                testStr = dr[Environment.DocImageData.SenderAddressField].ToString();
                                if (testStr.Length > 0)
                                {
                                    sb.Append(Environment.StringResources.GetString("Properties_PropertiesDocImageDialog_PropertiesDocImageDialog_Load_Message4"));
                                    sb.Append(" ");
                                    sb.Append(testStr);
                                    sb.Append("      ");
                                }
                                testStr = dr[Environment.DocImageData.RecipientField].ToString();
                                if (testStr.Length > 0)
                                {
                                    sb.Append(Environment.StringResources.GetString("Properties_PropertiesDocImageDialog_PropertiesDocImageDialog_Load_Message5"));
                                    sb.Append(" ");
                                    sb.Append(testStr);
                                    testStr = dr[Environment.DocImageData.RecipientAddressField].ToString();
                                    if (testStr.Length > 0)
                                    {
                                        sb.Append(" (");
                                        sb.Append(testStr);
                                        sb.Append(")");
                                    }
                                }
                                else
                                {
                                    testStr = dr[Environment.DocImageData.RecipientAddressField].ToString();
                                    if (testStr.Length > 0)
                                    {
                                        sb.Append(testStr);
                                    }
                                }
                                labelDate.AutoSize = true;
                                int oldheight = labelDate.Height;
                                labelDate.Text += sb.ToString();
                                if (labelDate.Height - oldheight > 0)
                                {
                                    Height += labelDate.Height - oldheight;
                                }
                            }
                            else
                            {
                                var fields = new string[4];
                                fields[0] = dr[Environment.DocImageData.SenderField].ToString();
                                fields[1] = dr[Environment.DocImageData.RecipientField].ToString();
                                fields[2] = dr[Environment.DocImageData.RecipientAddressField].ToString();
                                fields[3] = (dr[Environment.DocImageData.SendTimeField] == null) ? "" : ((DateTime)dr[Environment.DocImageData.SendTimeField]).ToLocalTime().ToString("dd.MM.yyyy HH:mm:ss");

                                sended.Items.Add(new ListViewItem(fields)
                                {
                                    ToolTipText = fields[2]
                                });
                            }
                        }
                        dr.Close(); dr.Dispose(); dt.Dispose();
                    }
            }
            else
            {
                if (docID == 0)
                {
                    MessageBox.Show("Properties.PropertiesDocImageDialog.PropertiesDocImageDialog_Load.Error1");
                    Close();
                }
                else
                {
                    Text = Environment.StringResources.GetString("Properties_PropertiesDocImageDialog_PropertiesDocImageDialog_Load_Title1");

                    if (!string.IsNullOrEmpty(fileName))
                    {
                        var      f    = new FileInfo(fileName);
                        ScanInfo info = TextProcessor.ParseScanInfo(f);
                        if (info != null)
                        {
                            date            = info.Date;
                            labelDate.Text += date.ToString();
                        }
                    }
                    else
                    {
                        MessageBox.Show(Environment.StringResources.GetString("Properties_PropertiesDocImageDialog_PropertiesDocImageDialog_Load_Message6"));
                        Close();
                    }
                }
            }
            UpdateControls();
        }
        private void WriteDataSetToExcelFile(DataSet ds, String ExcelFile)
        {
            DataTableReader dtr = null;

            System.Data.DataTable dt  = null;
            DataTableReader       dsr = null;
            Application           excelApplication = null;
            Workbook  excelWorkbook  = null;
            Worksheet excelWorksheet = null;

            try
            {
                dtr = ds.CreateDataReader();
                dt  = dtr.GetSchemaTable();
                dsr = dt.CreateDataReader();
                Int32    ColumnSize  = dtr.VisibleFieldCount;
                String[] ColumnNames = new String[ColumnSize];
                Int32    index       = 0;
                while (dsr.Read())
                {
                    ColumnNames[index] = dsr.GetString(0);
                    index++;
                }
                excelApplication = new Application();
                excelApplication.DisplayAlerts = false;
                //excelApplication.Visible = true;
                excelWorkbook  = excelApplication.Workbooks.Add(Type.Missing);
                excelWorksheet = (Worksheet)excelWorkbook.Sheets[1];
                excelApplication.Calculation = XlCalculation.xlCalculationManual;

                Int32 ColIdx = 1;
                Int32 RowIdx = 1;

                foreach (String ColumnName in ColumnNames)
                {
                    excelWorksheet.Cells[RowIdx, ColIdx] = ColumnName;
                    ColIdx++;
                }
                ColIdx = 1;
                RowIdx = 2;
                Int32 Maxrows = ds.Tables[0].Rows.Count;
                if (dtr.Read())
                {
                    for (ColIdx = 1; ColIdx <= ColumnSize; ColIdx++)
                    {
                        if (dtr.GetFieldType(ColIdx - 1) == typeof(String))
                        {
                            ((Range)excelWorksheet.Cells[RowIdx, ColIdx]).EntireColumn.NumberFormat = "@";
                        }
                        else if (dtr.GetFieldType(ColIdx - 1) == typeof(Decimal))
                        {
                            ((Range)excelWorksheet.Cells[RowIdx, ColIdx]).EntireColumn.NumberFormat = "#,##0.00_);(#,##0.00)";
                        }
                        else if (dtr.GetFieldType(ColIdx - 1) == typeof(DateTime))
                        {
                            ((Range)excelWorksheet.Cells[RowIdx, ColIdx]).EntireColumn.NumberFormat = "m/d/yyyy";
                        }
                        else
                        {
                            ((Range)excelWorksheet.Cells[RowIdx, ColIdx]).EntireColumn.NumberFormat = "General";
                        }
                        excelWorksheet.Cells[RowIdx, ColIdx] = dtr.GetValue(ColIdx - 1);
                    }
                    RowIdx++;
                }
                while (dtr.Read())
                {
                    for (ColIdx = 1; ColIdx <= ColumnSize; ColIdx++)
                    {
                        excelWorksheet.Cells[RowIdx, ColIdx] = dtr.GetValue(ColIdx - 1);
                    }
                    RowIdx++;
                }
                excelApplication.Calculation = XlCalculation.xlCalculationAutomatic;
                excelWorkbook.SaveAs(ExcelFile, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlShared, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (excelWorkbook != null)
                {
                    excelWorkbook.Close(Type.Missing, Type.Missing, Type.Missing);
                    excelWorkbook = null;
                }
                if (excelApplication != null)
                {
                    excelApplication.DisplayAlerts = true;
                    excelApplication.Quit();
                    excelApplication = null;
                }
                if (dsr != null)
                {
                    dsr.Close();
                    dsr.Dispose();
                    dsr = null;
                }
                if (dt != null)
                {
                    dt.Dispose();
                    dt = null;
                }
                if (dtr != null)
                {
                    dtr.Close();
                    dtr.Dispose();
                    dtr = null;
                }
            }
        }
Esempio n. 23
0
        private void PrintDoc(int docID)
        {
            if (printerObject != null)
            {
                printerObject.Clear();
            }
            poindex = 0;
            if (docID < 1)
            {
                OnPrintDoc();
                return;
            }
            if (printImage && !cancel)
            {
                Console.WriteLine("{0}: printed ID: {1}", DateTime.Now.ToString("HH:mm:ss fff"), docID);
                if (mainOnly)
                {
                    object obj = Environment.DocData.GetField(Environment.DocData.MainImageIDField, docID);
                    if (obj != null && obj is int && !cancel)
                    {
                        int  mainImageID = (int)obj;
                        bool isPDF       = "pdf".Equals(Environment.DocImageData.GetField(Environment.DocImageData.ImageTypeField, mainImageID).ToString(), StringComparison.CurrentCultureIgnoreCase);
                        PrintImage(docID, mainImageID, isPDF);
                    }
                }
                else
                {
                    using (DataTable dt = Environment.DocImageData.GetDocImages(docID))
                        using (DataTableReader dr = dt.CreateDataReader())
                        {
                            while (dr.Read())
                            {
                                var imgId = (int)dr[Environment.DocImageData.IDField];
                                if (imgId > 0 && !cancel)
                                {
                                    bool isPDF = "pdf".Equals(dr[Environment.DocImageData.ImageTypeField].ToString(), StringComparison.CurrentCultureIgnoreCase);
                                    PrintImage(docID, imgId, isPDF);
                                }
                            }
                            dr.Close();
                            dr.Dispose();
                            dt.Dispose();
                        }
                }
            }

            // есть ли данные у документа
            if (eForm && Environment.DocDataData.IsDataPresent(docID))
            {
                object obj = Environment.DocData.GetField(Environment.DocData.DocTypeIDField, docID);
                if (!obj.Equals(DBNull.Value))
                {
                    var docTypeID = (int)obj;
                    if (eFormSelection == null)
                    {
                        eFormSelection = new Hashtable();
                    }

                    if (eFormSelection.ContainsKey(docTypeID))
                    {
                        var list = eFormSelection[docTypeID] as List <PrinterObjectClass>;

                        bool show = false;
                        using (DataTable dt = Environment.PrintData.GetEFormPrintTypeData(docTypeID, docID))
                        {
                            foreach (PrinterObjectClass t in list)
                            {
                                show = !dt.Rows.Cast <DataRow>().Any(x => x[Environment.PrintData.IDField].Equals(t.TypeID));
                                if (show)
                                {
                                    break;
                                }
                            }
                            if (show || list.Count == 0)
                            {
                                using (var dialog = new PrintEFormSelectDialog(docTypeID, docID))
                                {
                                    if (dialog.ShowDialog() == DialogResult.OK)
                                    {
                                        list = dialog.PrinterObjectList;
                                        eFormSelection[docTypeID] = list;
                                    }
                                }
                            }
                            dt.Dispose();
                        }
                        if (list != null)
                        {
                            poindex       = 0;
                            printerObject = new List <PrinterObjectClass>(list);
                            StartSwitchPrintEform();
                        }
                    }
                    else
                    {
                        if (Environment.PrintData.CanPrintEForm(docTypeID))
                        {
                            block = true;
                            try
                            {
                                panelBrowser.Visible = false;
                                panelImg.Visible     = false;
                                using (var dialog = new PrintEFormSelectDialog(docTypeID, docID))
                                {
                                    if (dialog.ShowDialog() == DialogResult.OK)
                                    {
                                        List <PrinterObjectClass> list = dialog.PrinterObjectList;
                                        eFormSelection.Add(docTypeID, list);

                                        if (list != null)
                                        {
                                            poindex       = 0;
                                            printerObject = new List <PrinterObjectClass>(list);
                                            StartSwitchPrintEform();
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Data.Env.WriteToLog(ex);
                                MessageForm.Show(ex.Message, Environment.StringResources.GetString("Error"));
                            }
                        }
                        else
                        {
                            OnPrintDoc();
                        }
                    }
                }
            }
            else
            {
                OnPrintDoc();
            }
        }