Example #1
0
 private void getSignPage()
 {
     int x = 0;
     int y = 0;
     Label lab = new Label();
     lab.Text = "Wybierz licencję, którą chcesz podpisać protokół";
     lab.AutoSize = true;
     lab.MaximumSize = new System.Drawing.Size(this.signPanel.Size.Width - 20, 0);
     lab.Font = new System.Drawing.Font(this.myfont, 9f, System.Drawing.FontStyle.Bold);
     lab.ForeColor = System.Drawing.Color.Black;
     lab.Padding = new Padding(10, 0, 10, 0);
     lab.Location = new System.Drawing.Point(x, y);
     y += lab.Height + 20;
     this.signPanel.Controls.Add(lab);
     DataTable dt = new DataTable();
     if (System.IO.Directory.Exists(this.path + "\\Licenses"))
     {
         dt.Columns.Add(new DataColumn("lp", typeof(string)));
         dt.Columns.Add(new DataColumn("Użytkownik", typeof(string)));
         dt.Columns.Add(new DataColumn("Funkcja", typeof(string)));
         dt.Columns.Add(new DataColumn("Licencja", typeof(string)));
         char[] zORpChar = this.zORp.ToCharArray();
         try
         {
             string saveJns = "";
             string saveElection = "";
             string saveCircuit = "";
             XmlNode xmlJns = this.save.SelectSingleNode("/save/header/jns_kod");
             if (xmlJns != null && xmlJns.InnerText != "")
             {
                 saveJns = xmlJns.InnerText;
             }
             XmlNode xmlElection = this.save.SelectSingleNode("/save/header/defklk");
             if (xmlElection != null && xmlElection.FirstChild != null)
             {
                 XmlNode xmlElection2 = xmlElection.FirstChild.Attributes.GetNamedItem("name");
                 if (xmlElection2 != null && xmlElection2.Value != "")
                 {
                     string[] saveElectionPart = xmlElection2.Value.Split(new char[]
                     {
                         '-'
                     });
                     saveElection = saveElectionPart[0].Replace("/", "_");
                 }
             }
             XmlNode xmlCircuit = this.save.SelectSingleNode("/save/header/nrObwodu");
             if (xmlCircuit != null && xmlCircuit.InnerText != "")
             {
                 saveCircuit = xmlCircuit.InnerText;
             }
             Certificate certificate = new Certificate();
             foreach (string file in System.IO.Directory.EnumerateFiles(this.path + "\\Licenses", "*.pem"))
             {
                 Certificate c = new Certificate(file);
                 if (c.isActiveLicense())
                 {
                     string[] filename = file.Split(new char[]
                     {
                         '\\'
                     });
                     bool go = false;
                     string paternA = string.Concat(new string[]
                     {
                         "^",
                         saveElection,
                         "-",
                         saveJns,
                         "-A"
                     });
                     for (int i = 0; i < zORpChar.Length; i++)
                     {
                         string patern = string.Concat(new string[]
                         {
                             "^",
                             saveElection,
                             "-",
                             saveJns,
                             "-",
                             zORpChar[i].ToString()
                         });
                         if (zORpChar[i].ToString() == "P" || zORpChar[i].ToString() == "Z")
                         {
                             patern = patern + "-" + saveCircuit;
                         }
                         if (System.Text.RegularExpressions.Regex.IsMatch(filename[filename.Length - 1], patern) || System.Text.RegularExpressions.Regex.IsMatch(filename[filename.Length - 1], paternA))
                         {
                             go = true;
                         }
                     }
                     if (go)
                     {
                         DataRow dr = dt.NewRow();
                         dr[0] = dt.Rows.Count + 1;
                         try
                         {
                             string[] subjectPatrs = c.getSubject().Split(new string[]
                             {
                                 ", "
                             }, System.StringSplitOptions.None);
                             int end = 0;
                             for (int i = 0; i < subjectPatrs.Length; i++)
                             {
                                 if (System.Text.RegularExpressions.Regex.IsMatch(subjectPatrs[i], "^CN="))
                                 {
                                     dr[1] = subjectPatrs[i].Replace("CN=", "");
                                     end++;
                                 }
                                 if (System.Text.RegularExpressions.Regex.IsMatch(subjectPatrs[i], "^OU="))
                                 {
                                     string[] tmp = subjectPatrs[i].Replace("OU=", "").Split(new char[]
                                     {
                                         '-'
                                     });
                                     if (tmp[2] == "O")
                                     {
                                         dr[2] = "Operator";
                                     }
                                     else
                                     {
                                         if (tmp[2] == "P")
                                         {
                                             dr[2] = "Przewodniczący";
                                         }
                                         else
                                         {
                                             if (tmp[2] == "Z")
                                             {
                                                 dr[2] = "Zastępca";
                                             }
                                             else
                                             {
                                                 dr[2] = tmp[2];
                                             }
                                         }
                                     }
                                     end++;
                                 }
                                 if (end >= 2)
                                 {
                                     break;
                                 }
                             }
                         }
                         catch (System.Exception)
                         {
                             dr[1] = "";
                             dr[2] = "";
                         }
                         dr[3] = filename[filename.Length - 1];
                         dt.Rows.Add(dr);
                     }
                 }
             }
         }
         catch (System.Exception ex)
         {
             MessageBox.Show("Nie można wyswietlic licencji do podpisu dla tego protokolu. " + ex.Message, "Error");
         }
         if (dt.Rows.Count > 0)
         {
             this.LicencesTable.DataSource = dt;
             this.LicencesTable.Columns["lp"].DisplayIndex = 0;
             this.LicencesTable.Columns["Użytkownik"].DisplayIndex = 1;
             this.LicencesTable.Columns["Funkcja"].DisplayIndex = 2;
             DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
             btn.HeaderText = "Akcje";
             btn.Text = "przejdź";
             btn.Name = "action";
             btn.UseColumnTextForButtonValue = true;
             if (this.LicencesTable.Columns["action"] == null)
             {
                 this.LicencesTable.Columns.Insert(3, btn);
             }
             else
             {
                 this.LicencesTable.Columns["action"].DisplayIndex = 3;
             }
             this.LicencesTable.Columns["Licencja"].DisplayIndex = 4;
             this.LicencesTable.Columns["Licencja"].Visible = false;
         }
     }
     this.LicencesTable.Visible = true;
     this.LicencesTable.Location = new System.Drawing.Point(x, y);
     this.LicencesTable.MaximumSize = new System.Drawing.Size(this.signPanel.Size.Width - 20, 0);
     this.LicencesTable.Size = new System.Drawing.Size(0, this.LicencesTable.Rows.Count * 20);
     this.LicencesTable.AutoSize = true;
 }
Example #2
0
        private void getSignPage()
        {
            int   x   = 0;
            int   y   = 0;
            Label lab = new Label();

            lab.Text        = "Wybierz licencję, którą chcesz podpisać protokół";
            lab.AutoSize    = true;
            lab.MaximumSize = new System.Drawing.Size(this.signPanel.Size.Width - 20, 0);
            lab.Font        = new System.Drawing.Font(this.myfont, 9f, System.Drawing.FontStyle.Bold);
            lab.ForeColor   = System.Drawing.Color.Black;
            lab.Padding     = new Padding(10, 0, 10, 0);
            lab.Location    = new System.Drawing.Point(x, y);
            y += lab.Height + 20;
            this.signPanel.Controls.Add(lab);
            DataTable dt = new DataTable();

            if (System.IO.Directory.Exists(this.path + "\\Licenses"))
            {
                dt.Columns.Add(new DataColumn("lp", typeof(string)));
                dt.Columns.Add(new DataColumn("Użytkownik", typeof(string)));
                dt.Columns.Add(new DataColumn("Funkcja", typeof(string)));
                dt.Columns.Add(new DataColumn("Licencja", typeof(string)));
                char[] zORpChar = this.zORp.ToCharArray();
                try
                {
                    string  saveJns      = "";
                    string  saveElection = "";
                    string  saveCircuit  = "";
                    XmlNode xmlJns       = this.save.SelectSingleNode("/save/header/jns_kod");
                    if (xmlJns != null && xmlJns.InnerText != "")
                    {
                        saveJns = xmlJns.InnerText;
                    }
                    XmlNode xmlElection = this.save.SelectSingleNode("/save/header/defklk");
                    if (xmlElection != null && xmlElection.FirstChild != null)
                    {
                        XmlNode xmlElection2 = xmlElection.FirstChild.Attributes.GetNamedItem("name");
                        if (xmlElection2 != null && xmlElection2.Value != "")
                        {
                            string[] saveElectionPart = xmlElection2.Value.Split(new char[]
                            {
                                '-'
                            });
                            saveElection = saveElectionPart[0].Replace("/", "_");
                        }
                    }
                    XmlNode xmlCircuit = this.save.SelectSingleNode("/save/header/nrObwodu");
                    if (xmlCircuit != null && xmlCircuit.InnerText != "")
                    {
                        saveCircuit = xmlCircuit.InnerText;
                    }
                    Certificate certificate = new Certificate();
                    foreach (string file in System.IO.Directory.EnumerateFiles(this.path + "\\Licenses", "*.pem"))
                    {
                        Certificate c = new Certificate(file);
                        if (c.isActiveLicense())
                        {
                            string[] filename = file.Split(new char[]
                            {
                                '\\'
                            });
                            bool   go      = false;
                            string paternA = string.Concat(new string[]
                            {
                                "^",
                                saveElection,
                                "-",
                                saveJns,
                                "-A"
                            });
                            for (int i = 0; i < zORpChar.Length; i++)
                            {
                                string patern = string.Concat(new string[]
                                {
                                    "^",
                                    saveElection,
                                    "-",
                                    saveJns,
                                    "-",
                                    zORpChar[i].ToString()
                                });
                                if (zORpChar[i].ToString() == "P" || zORpChar[i].ToString() == "Z")
                                {
                                    patern = patern + "-" + saveCircuit;
                                }
                                if (System.Text.RegularExpressions.Regex.IsMatch(filename[filename.Length - 1], patern) || System.Text.RegularExpressions.Regex.IsMatch(filename[filename.Length - 1], paternA))
                                {
                                    go = true;
                                }
                            }
                            if (go)
                            {
                                DataRow dr = dt.NewRow();
                                dr[0] = dt.Rows.Count + 1;
                                try
                                {
                                    string[] subjectPatrs = c.getSubject().Split(new string[]
                                    {
                                        ", "
                                    }, System.StringSplitOptions.None);
                                    int end = 0;
                                    for (int i = 0; i < subjectPatrs.Length; i++)
                                    {
                                        if (System.Text.RegularExpressions.Regex.IsMatch(subjectPatrs[i], "^CN="))
                                        {
                                            dr[1] = subjectPatrs[i].Replace("CN=", "");
                                            end++;
                                        }
                                        if (System.Text.RegularExpressions.Regex.IsMatch(subjectPatrs[i], "^OU="))
                                        {
                                            string[] tmp = subjectPatrs[i].Replace("OU=", "").Split(new char[]
                                            {
                                                '-'
                                            });
                                            if (tmp[2] == "O")
                                            {
                                                dr[2] = "Operator";
                                            }
                                            else
                                            {
                                                if (tmp[2] == "P")
                                                {
                                                    dr[2] = "Przewodniczący";
                                                }
                                                else
                                                {
                                                    if (tmp[2] == "Z")
                                                    {
                                                        dr[2] = "Zastępca";
                                                    }
                                                    else
                                                    {
                                                        dr[2] = tmp[2];
                                                    }
                                                }
                                            }
                                            end++;
                                        }
                                        if (end >= 2)
                                        {
                                            break;
                                        }
                                    }
                                }
                                catch (System.Exception)
                                {
                                    dr[1] = "";
                                    dr[2] = "";
                                }
                                dr[3] = filename[filename.Length - 1];
                                dt.Rows.Add(dr);
                            }
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Nie można wyswietlic licencji do podpisu dla tego protokolu. " + ex.Message, "Error");
                }
                if (dt.Rows.Count > 0)
                {
                    this.LicencesTable.DataSource = dt;
                    this.LicencesTable.Columns["lp"].DisplayIndex         = 0;
                    this.LicencesTable.Columns["Użytkownik"].DisplayIndex = 1;
                    this.LicencesTable.Columns["Funkcja"].DisplayIndex    = 2;
                    DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
                    btn.HeaderText = "Akcje";
                    btn.Text       = "przejdź";
                    btn.Name       = "action";
                    btn.UseColumnTextForButtonValue = true;
                    if (this.LicencesTable.Columns["action"] == null)
                    {
                        this.LicencesTable.Columns.Insert(3, btn);
                    }
                    else
                    {
                        this.LicencesTable.Columns["action"].DisplayIndex = 3;
                    }
                    this.LicencesTable.Columns["Licencja"].DisplayIndex = 4;
                    this.LicencesTable.Columns["Licencja"].Visible      = false;
                }
            }
            this.LicencesTable.Visible     = true;
            this.LicencesTable.Location    = new System.Drawing.Point(x, y);
            this.LicencesTable.MaximumSize = new System.Drawing.Size(this.signPanel.Size.Width - 20, 0);
            this.LicencesTable.Size        = new System.Drawing.Size(0, this.LicencesTable.Rows.Count * 20);
            this.LicencesTable.AutoSize    = true;
        }