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;
 }
 private void getLicense_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (e.RowIndex >= 0)
         {
             if (e.ColumnIndex == this.LicencesTable.Columns["action"].Index)
             {
                 try
                 {
                     object name = this.LicencesTable.Rows[e.RowIndex].Cells["Licencja"].Value;
                     string filepath = this.path + "\\Licenses\\" + name.ToString();
                     this.wait.setWaitPanel("Trwa autozapis protokołu", "Prosimy czekać");
                     this.wait.setVisible(true);
                     this.saves(4);
                     this.wait.setWaitPanel("Trwa przygotowanie do podpisania protokołu", "Prosimy czekać");
                     this.wait.setVisible(true);
                     string xmlTMP = this.generateSaves(0);
                     Commit com = new Commit(filepath, this, xmlTMP);
                     com.ShowDialog();
                     if (this.goodcertificate)
                     {
                         this.wait.setWaitPanel("Trwa generowanie kodu kreskowego dla protokołu", "Prosimy czekać");
                         this.wait.setVisible(true);
                         string docXml = "";
                         this.currentStep = 0;
                         string xml = xmlTMP;
                         this.save.LoadXml(xml);
                         XmlNode header = this.save.SelectSingleNode("/save/header");
                         if (header != null)
                         {
                             docXml += header.OuterXml;
                         }
                         XmlNode step = this.save.SelectSingleNode("/save/step");
                         if (step != null)
                         {
                             docXml += step.OuterXml;
                         }
                         XmlNode form = this.save.SelectSingleNode("/save/form");
                         if (form != null)
                         {
                             docXml += form.OuterXml;
                         }
                         XmlNode komisja_sklad = this.save.SelectSingleNode("/save/komisja_sklad");
                         if (komisja_sklad != null)
                         {
                             docXml += komisja_sklad.OuterXml;
                         }
                         XmlNode hardWarningCode = this.save.SelectSingleNode("/save/hardWarningCode");
                         if (hardWarningCode != null)
                         {
                             docXml += hardWarningCode.OuterXml;
                         }
                         XmlNode softError = this.save.SelectSingleNode("/save/softError");
                         if (softError != null)
                         {
                             docXml += softError.OuterXml;
                         }
                         XmlNode hardError = this.save.SelectSingleNode("/save/hardError");
                         if (hardError != null)
                         {
                             docXml += hardError.OuterXml;
                         }
                         XmlNode hardWarning = this.save.SelectSingleNode("/save/hardWarning");
                         if (hardWarning != null)
                         {
                             docXml += hardWarning.OuterXml;
                         }
                         ClassMd5 i = new ClassMd5();
                         string controlSum = i.CreateMD5Hash(docXml);
                         codeBar code = new codeBar();
                         code.generateCode(controlSum);
                         this.codeBarCode = code.getCode();
                         this.codeBarText = code.getTextReadable();
                         this.wait.setWaitPanel("Trwa podpisywanie protokołu", "Prosimy czekać");
                         this.wait.setVisible(true);
                         xml = this.generateSaves(this.currentStep);
                         try
                         {
                             Certificate cer = new Certificate();
                             cer.SignXmlText(xml, this.savePath, this.password, filepath);
                         }
                         catch (System.Exception ex)
                         {
                             MessageBox.Show("Sign: " + ex.Message, "Uwaga");
                         }
                         try
                         {
                             this.komSend = "";
                             Connection con = new Connection();
                             if (con.IsAvailableNetworkActive())
                             {
                                 this.wait.setWaitPanel("Trwa wysyłanie protokołu", "Prosimy czekać");
                                 this.wait.setVisible(true);
                                 this.goodcertificate = false;
                                 this.error = false;
                                 Eksport ex2 = new Eksport(this.savePath, true, this, filepath, this.password);
                                 try
                                 {
                                     ex2.ShowDialog();
                                 }
                                 catch (System.Exception)
                                 {
                                 }
                                 if (this.goodcertificate)
                                 {
                                     try
                                     {
                                         System.IO.StreamReader sr = new System.IO.StreamReader(this.savePath);
                                         string file = sr.ReadToEnd();
                                         sr.Close();
                                         file = file.Replace("<status>podpisany</status>", "<status>wysłany</status>");
                                         System.IO.StreamWriter sw = new System.IO.StreamWriter(this.savePath, false);
                                         sw.Write(file);
                                         sw.Close();
                                     }
                                     catch (System.Exception ex3)
                                     {
                                         MessageBox.Show("Protokół został wysłany, ale nie można zmienić jego statusu. " + ex3.Message, "Uwaga");
                                     }
                                 }
                                 if (!this.goodcertificate && this.error)
                                 {
                                     this.codeBarCode = "";
                                     this.codeBarText = "";
                                     this.saves(4);
                                 }
                             }
                             else
                             {
                                 this.komSend = "Protokół nie został wysłany na serwer z powodu braku internetu. Z poziomu listy protokołów bedzie można ponowić operacje.";
                             }
                             this.password = "";
                         }
                         catch (System.Exception ex)
                         {
                             MessageBox.Show("Send: " + ex.Message, "Uwaga");
                         }
                         try
                         {
                             this.wait.setWaitPanel("Trwa zapisywanie protokołu na dysk", "Prosimy czekać");
                             this.wait.setVisible(true);
                             SaveProtocol saveP = new SaveProtocol(this.komSend, this.savePath);
                             saveP.ShowDialog();
                         }
                         catch (System.Exception ex)
                         {
                             MessageBox.Show("Save: " + ex.Message, "Uwaga");
                         }
                         try
                         {
                             this.wait.setWaitPanel("Trwa przygotowanie protokołu do druku", "Prosimy czekać");
                             this.wait.setVisible(true);
                             this.drukToolStripMenuItem_Click(sender, e);
                             this.wait.setVisible(false);
                         }
                         catch (System.Exception ex)
                         {
                             MessageBox.Show("Print: " + ex.Message, "Uwaga");
                         }
                     }
                 }
                 catch (System.ArgumentOutOfRangeException ex_5C5)
                 {
                 }
             }
         }
     }
     catch (System.Exception ex)
     {
     }
 }
 private void send_Click(object sender, System.EventArgs e)
 {
     this.obwodList_Validated(this.obwodList, e);
     this.currentLwyb_Validated(this.currentLwyb, e);
     this.attendanceHour_Validated(this.attendanceHour, e);
     this.number_Validated(this.attendanceValue, e);
     if ((!this.errorValue.Visible && !this.errorHour.Visible && !this.errorOBW.Visible && !this.errorCurrentLwyb.Visible) || (!this.errorValue.Visible && !this.errorHour.Visible && !this.errorOBW.Visible && this.errorCurrentLwyb.Visible && this.errorCurrentLwyb.Text == "Liczba wyborców uprawnionych do głosowania jest mniejsza od 110% i większa od 90% szacowanej liczby wyborców (" + (this.obwodList.SelectedItem as AttendanceOBWItem).getLwyb().ToString() + ")."))
     {
         WaitPanel p = new WaitPanel("Wait_04", base.Size.Width, base.Size.Height);
         p.setWaitPanel("Trwa importowanie danych", "Proszę czekać");
         p.setSize(this.FormPanel.Size);
         p.setLocation(this.FormPanel.Location);
         base.Controls.Add(p.getPanel());
         base.Controls[p.getName()].BringToFront();
         p.setVisible(true);
         string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
         xml += "<save>";
         string hour = "";
         try
         {
             if (this.attendanceHour.SelectedItem != null)
             {
                 hour = (this.attendanceHour.SelectedItem as AttendanceItem).getName();
             }
         }
         catch (System.Exception ex)
         {
         }
         string value = "";
         try
         {
             if (this.attendanceValue.Text != null)
             {
                 value = this.attendanceValue.Text;
             }
         }
         catch (System.Exception ex)
         {
         }
         string text = xml;
         xml = string.Concat(new string[]
         {
             text,
             "<attendance><attendanceHour>",
             hour,
             "</attendanceHour><attendanceValue>",
             value,
             "</attendanceValue><currentLwyb>",
             this.currentLwyb.Text,
             "</currentLwyb></attendance>"
         });
         xml += "<header>";
         xml += this.getHeader(this.header);
         xml += "</header>";
         xml += "</save>";
         Commit c = new Commit(this.licensePath, this);
         c.ShowDialog();
         if (this.logged)
         {
             try
             {
                 Certificate cer = new Certificate();
                 cer.SignXmlText(xml, System.IO.Path.GetTempPath() + "KBW\\tmp\\attendance.xml", this.password, this.licensePath);
                 System.IO.StreamReader sr = new System.IO.StreamReader(System.IO.Path.GetTempPath() + "KBW\\tmp\\attendance.xml");
                 xml = sr.ReadToEnd();
                 sr.Close();
                 string uri = "attendances/readval/" + HttpUtility.UrlEncode((this.attendanceHour.SelectedItem as AttendanceItem).getName());
                 string post = "xml=" + HttpUtility.UrlEncode(xml);
                 Connection con = new Connection();
                 Code res = con.postReq(uri, post, 0);
                 MessageBox.Show(res.getText(), "Komunikat");
             }
             catch (System.Exception ex)
             {
                 MessageBox.Show("Błąd utworzenia wiadomości: " + ex.Message, "Uwaga");
             }
         }
         p.setVisible(false);
     }
 }
Exemple #4
0
 private void sendPetition_Click(object sender, System.EventArgs e)
 {
     WaitPanel p = new WaitPanel("Wait_04", base.Size.Width, base.Size.Height);
     p.setWaitPanel("Trwa generowanie wniosku", "Proszę czekać");
     p.setSize(this.passwordPanel.Size);
     p.setLocation(this.passwordPanel.Location);
     base.Controls.Add(p.getPanel());
     base.Controls[p.getName()].BringToFront();
     p.setVisible(true);
     string uri = "certificates/csrwrite";
     Certificate certificate = new Certificate();
     certificate.generateCSR(this.ou, this.user, this.passwordCert1.Text);
     string postData = "csr=" + HttpUtility.UrlEncode(certificate.getCSR()) + "&token=" + HttpUtility.UrlEncode(this.token);
     p.setWaitPanel("Trwa wysyłanie wniosku", "Proszę czekać");
     Code res = this.con.postReq(uri, postData, 0);
     if (res.getcode() == 0)
     {
         MessageBox.Show("Wniosek o licencje został wysłany", "Uwaga");
     }
     else
     {
         MessageBox.Show(res.getText(), "Uwaga");
     }
     p.setVisible(false);
     base.Close();
 }
Exemple #5
0
 private void waitLicenses_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (e.RowIndex >= 0)
         {
             if (e.ColumnIndex == this.waitLicenses.Columns["action"].Index)
             {
                 this.wait.setWaitPanel("Trwa sprawdzanie licencji", "Proszę czekać");
                 this.wait.setVisible(true);
                 try
                 {
                     string licenceName = this.waitLicenses.Rows[e.RowIndex].Cells["Licencja"].Value.ToString();
                     try
                     {
                         Certificate c = new Certificate();
                         if (System.IO.Directory.Exists(this.path + "\\Licenses"))
                         {
                             System.IO.StreamReader s = new System.IO.StreamReader(this.path + "\\Licenses\\" + licenceName);
                             string csr = s.ReadToEnd();
                             s.Close();
                             string uri = "certificates/crtget";
                             string post = "csr=" + HttpUtility.UrlEncode(csr);
                             IsLicense res = this.con.postCheckLicense(uri, post, 0);
                             string file = "";
                             if (res.getCode().getcode() == 12)
                             {
                                 if (!System.IO.Directory.Exists(this.path + "\\Licenses\\Anulowane"))
                                 {
                                     try
                                     {
                                         System.IO.Directory.CreateDirectory(this.path + "\\Licenses\\Anulowane");
                                     }
                                     catch (System.ArgumentNullException)
                                     {
                                         MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"Anulowane\"", "Error");
                                     }
                                     catch (System.ArgumentException)
                                     {
                                         MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"Anulowane\"", "Error");
                                     }
                                     catch (System.UnauthorizedAccessException)
                                     {
                                         MessageBox.Show("Nie masz uprawnień do tworzenia katalogów. Otwórz aplikacje jako adnimistrator.", "Uwaga");
                                     }
                                     catch (System.IO.PathTooLongException)
                                     {
                                         MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"Anulowane\"", "Error");
                                     }
                                     catch (System.IO.DirectoryNotFoundException)
                                     {
                                         MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"Anulowane\"", "Error");
                                     }
                                     catch (System.NotSupportedException)
                                     {
                                         MessageBox.Show("Nieprawidłowy format ścieżki. Nie można utworzyć katalogu \"Anulowane\"", "Error");
                                     }
                                     catch (System.IO.IOException)
                                     {
                                         MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"Anulowane\"", "Error");
                                     }
                                 }
                                 if (System.IO.Directory.Exists(this.path + "\\Licenses\\Anulowane"))
                                 {
                                     try
                                     {
                                         System.IO.File.Move(this.path + "\\Licenses\\" + licenceName, this.path + "\\Licenses\\Anulowane\\" + licenceName);
                                         System.IO.File.Move(this.path + "\\Licenses\\" + licenceName.Replace(".csr", ".key"), this.path + "\\Licenses\\Anulowane\\" + licenceName.Replace(".csr", ".key"));
                                     }
                                     catch (System.ArgumentNullException)
                                     {
                                         MessageBox.Show("Sprawdzana licencja nie istnieje", "Uwaga");
                                     }
                                     catch (System.ArgumentException)
                                     {
                                         MessageBox.Show("Sprawdzana licencja nie istnieje", "Uwaga");
                                     }
                                     catch (System.UnauthorizedAccessException)
                                     {
                                         MessageBox.Show("Nie masz uprawnień do przeniesiena licenji do anulowanych. Otwórz aplikacje jako adnimistrator.", "Uwaga");
                                     }
                                     catch (System.IO.PathTooLongException)
                                     {
                                         MessageBox.Show("Nieprawidłowa ścieżka do licencji", "Uwaga");
                                     }
                                     catch (System.IO.DirectoryNotFoundException)
                                     {
                                         MessageBox.Show("Nieprawidłowa ścieżka do licencji", "Uwaga");
                                     }
                                     catch (System.NotSupportedException)
                                     {
                                         MessageBox.Show("Nieprawidłowy format ścieżki do licencji", "Uwaga");
                                     }
                                     catch (System.IO.IOException)
                                     {
                                         try
                                         {
                                             string[] nameFilePart = licenceName.Replace(".csr", "").Split(new char[]
                                             {
                                                 ' '
                                             });
                                             int num = System.IO.Directory.GetFiles(this.path + "\\Licenses\\Anulowane\\", nameFilePart[0] + "*.csr").Length + 1;
                                             string namefile;
                                             if (num > 1)
                                             {
                                                 namefile = nameFilePart[0] + " " + num.ToString() + ".csr";
                                             }
                                             else
                                             {
                                                 namefile = nameFilePart[0] + ".csr";
                                             }
                                             System.IO.File.Move(this.path + "\\Licenses\\" + licenceName, this.path + "\\Licenses\\Anulowane\\" + namefile);
                                             System.IO.File.Move(this.path + "\\Licenses\\" + licenceName.Replace(".csr", ".key"), this.path + "\\Licenses\\Anulowane\\" + namefile.Replace(".csr", ".key"));
                                         }
                                         catch (System.ArgumentNullException)
                                         {
                                             MessageBox.Show("Sprawdzana licencja nie istnieje", "Uwaga");
                                         }
                                         catch (System.ArgumentException)
                                         {
                                             MessageBox.Show("Sprawdzana licencja nie istnieje", "Uwaga");
                                         }
                                         catch (System.UnauthorizedAccessException)
                                         {
                                             MessageBox.Show("Nie masz uprawnień do przeniesiena licenji do anulowanych.", "Uwaga");
                                         }
                                         catch (System.IO.PathTooLongException)
                                         {
                                             MessageBox.Show("Nieprawidłowa ścieżka do licencji", "Uwaga");
                                         }
                                         catch (System.IO.DirectoryNotFoundException)
                                         {
                                             MessageBox.Show("Nieprawidłowa ścieżka do licencji", "Uwaga");
                                         }
                                         catch (System.NotSupportedException)
                                         {
                                             MessageBox.Show("Nieprawidłowy format ścieżki do licencji", "Uwaga");
                                         }
                                         catch (System.IO.IOException)
                                         {
                                             MessageBox.Show("Nie można odnaleźć licencji", "Uwaga");
                                         }
                                     }
                                     this.getOtherLicense();
                                 }
                             }
                             if (res.getCode().getcode() == 0 && res.getCrt() != "")
                             {
                                 file = res.getCrt();
                             }
                             if (file != "")
                             {
                                 if (!System.IO.Directory.Exists(this.path + "\\Licenses"))
                                 {
                                     try
                                     {
                                         System.IO.Directory.CreateDirectory(this.path + "\\Licenses");
                                     }
                                     catch (System.ArgumentNullException)
                                     {
                                         MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"Licenses\"", "Error");
                                     }
                                     catch (System.ArgumentException)
                                     {
                                         MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"Licenses\"", "Error");
                                     }
                                     catch (System.UnauthorizedAccessException)
                                     {
                                         MessageBox.Show("Nie masz uprawnień do tworzenia katalogów. Otwórz aplikacje jako adnimistrator.", "Uwaga");
                                     }
                                     catch (System.IO.PathTooLongException)
                                     {
                                         MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"Licenses\"", "Error");
                                     }
                                     catch (System.IO.DirectoryNotFoundException)
                                     {
                                         MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"Licenses\"", "Error");
                                     }
                                     catch (System.NotSupportedException)
                                     {
                                         MessageBox.Show("Nieprawidłowy format ścieżki. Nie można utworzyć katalogu \"Licenses\"", "Error");
                                     }
                                     catch (System.IO.IOException)
                                     {
                                         MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"Licenses\"", "Error");
                                     }
                                 }
                                 if (System.IO.Directory.Exists(this.path + "\\Licenses"))
                                 {
                                     try
                                     {
                                         System.IO.StreamReader swk = new System.IO.StreamReader(this.path + "\\Licenses\\" + licenceName.Replace(".csr", ".key"));
                                         string key = swk.ReadToEnd();
                                         swk.Close();
                                         string[] nameFilePart = licenceName.Replace(".csr", "").Split(new char[]
                                         {
                                             ' '
                                         });
                                         int num = System.IO.Directory.GetFiles(this.path + "\\Licenses\\", nameFilePart[0] + "*.pem").Length + 1;
                                         string namefile;
                                         if (num > 1)
                                         {
                                             namefile = nameFilePart[0] + " " + num.ToString() + ".pem";
                                         }
                                         else
                                         {
                                             namefile = nameFilePart[0] + ".pem";
                                         }
                                         file = file + '\n'.ToString() + key;
                                         System.IO.StreamWriter sw = new System.IO.StreamWriter(this.path + "\\Licenses\\" + namefile, false);
                                         sw.Write(file);
                                         sw.Close();
                                         try
                                         {
                                             System.Security.Cryptography.X509Certificates.X509Certificate a = new System.Security.Cryptography.X509Certificates.X509Certificate(this.path + "\\Licenses\\" + namefile);
                                             System.IO.File.Delete(this.path + "\\Licenses\\" + licenceName);
                                             System.IO.File.Delete(this.path + "\\Licenses\\" + licenceName.Replace(".csr", ".key"));
                                         }
                                         catch (System.Security.Cryptography.CryptographicException)
                                         {
                                             MessageBox.Show("Przesłany certyfikat jest nie prawidłowy", "Error");
                                         }
                                         catch (System.ArgumentException)
                                         {
                                         }
                                     }
                                     catch (System.ArgumentNullException)
                                     {
                                         MessageBox.Show("Nie można zapisać licencji. Nieprawidłowa ścieżka ", "Error");
                                     }
                                     catch (System.ArgumentException)
                                     {
                                         MessageBox.Show("Nie można zapisać licencji. Nieprawidłowa ścieżka ", "Error");
                                     }
                                     catch (System.UnauthorizedAccessException)
                                     {
                                         MessageBox.Show("Nie masz uprawnień zapisania licencji. Otwórz aplikacje jako adnimistrator.", "Uwaga");
                                     }
                                     catch (System.IO.PathTooLongException)
                                     {
                                         MessageBox.Show("Nie można zapisać licencji. Nieprawidłowa ścieżka ", "Error");
                                     }
                                     catch (System.IO.DirectoryNotFoundException)
                                     {
                                         MessageBox.Show("Nie można zapisać licencji. Nieprawidłowa ścieżka ", "Error");
                                     }
                                     catch (System.NotSupportedException)
                                     {
                                         MessageBox.Show("Nie można zapisać licencji. Nieprawidłowa ścieżka ", "Error");
                                     }
                                     catch (System.IO.IOException)
                                     {
                                         MessageBox.Show("Nie można zapisać licencji. Nieprawidłowa ścieżka ", "Error");
                                     }
                                     catch (System.ObjectDisposedException)
                                     {
                                         MessageBox.Show("Nie można zapisać licencji (ObjectDisposedException)", "Error");
                                     }
                                     this.getActiveLicense();
                                     this.getOtherLicense();
                                 }
                             }
                             if (res.getCode().getcode() != 0 && res.getCode().getcode() != 11 && res.getCode().getcode() != 12)
                             {
                                 MessageBox.Show(res.getCode().getText(), "Uwaga");
                             }
                             this.getOtherLicense();
                             this.getActiveLicense();
                         }
                     }
                     finally
                     {
                     }
                 }
                 catch (System.ArgumentOutOfRangeException)
                 {
                 }
                 this.wait.setVisible(false);
             }
             if (e.ColumnIndex == this.waitLicenses.Columns["remove"].Index)
             {
                 try
                 {
                     DialogResult result = MessageBox.Show("Czy napewno usunąć licencje " + this.waitLicenses.Rows[e.RowIndex].Cells["Licencja"].Value.ToString() + "?", "Usuwanie", MessageBoxButtons.YesNo);
                     if (result == DialogResult.Yes)
                     {
                         try
                         {
                             if (!System.IO.Directory.Exists(this.path + "\\Licenses"))
                             {
                                 System.IO.Directory.CreateDirectory(this.path + "\\Licenses");
                             }
                             if (this.waitLicenses.Rows[e.RowIndex].Cells["Status"].Value.ToString() == "Anulowana")
                             {
                                 if (!System.IO.Directory.Exists(this.path + "\\Licenses\\Anulowane"))
                                 {
                                     System.IO.Directory.CreateDirectory(this.path + "\\Licenses\\Anulowane");
                                 }
                                 string a2 = this.path + "\\Licenses\\Anulowane\\" + this.waitLicenses.Rows[e.RowIndex].Cells["Licencja"].Value.ToString();
                                 System.IO.File.Delete(this.path + "\\Licenses\\Anulowane\\" + this.waitLicenses.Rows[e.RowIndex].Cells["Licencja"].Value.ToString());
                                 System.IO.File.Delete(this.path + "\\Licenses\\Anulowane\\" + this.waitLicenses.Rows[e.RowIndex].Cells["Licencja"].Value.ToString().Replace(".csr", ".key"));
                             }
                             if (this.waitLicenses.Rows[e.RowIndex].Cells["Status"].Value.ToString() == "Nie aktywna")
                             {
                                 string a2 = this.path + "\\Licenses\\" + this.waitLicenses.Rows[e.RowIndex].Cells["Licencja"].Value.ToString();
                                 System.IO.File.Delete(this.path + "\\Licenses\\" + this.waitLicenses.Rows[e.RowIndex].Cells["Licencja"].Value.ToString());
                                 System.IO.File.Delete(this.path + "\\Licenses\\" + this.waitLicenses.Rows[e.RowIndex].Cells["Licencja"].Value.ToString().Replace(".crt", ".key"));
                             }
                             if (this.waitLicenses.Rows[e.RowIndex].Cells["Status"].Value.ToString() == "Oczekująca")
                             {
                                 string a2 = this.path + "\\Licenses\\" + this.waitLicenses.Rows[e.RowIndex].Cells["Licencja"].Value.ToString();
                                 System.IO.File.Delete(this.path + "\\Licenses\\" + this.waitLicenses.Rows[e.RowIndex].Cells["Licencja"].Value.ToString());
                                 System.IO.File.Delete(this.path + "\\Licenses\\" + this.waitLicenses.Rows[e.RowIndex].Cells["Licencja"].Value.ToString().Replace(".csr", ".key"));
                             }
                             this.waitLicenses.Rows.Remove(this.waitLicenses.Rows[e.RowIndex]);
                         }
                         catch (System.ArgumentNullException)
                         {
                             MessageBox.Show("Błędna scieżka do licencji", "Error");
                         }
                         catch (System.ArgumentException)
                         {
                             MessageBox.Show("Błędna scieżka do licencji", "Error");
                         }
                         catch (System.IO.DirectoryNotFoundException)
                         {
                             MessageBox.Show("Błąd znalezienia pliku licencji", "Error");
                         }
                         catch (System.IO.PathTooLongException)
                         {
                             MessageBox.Show("Zbyt długa scieżka do licencji", "Error");
                         }
                         catch (System.IO.IOException)
                         {
                             MessageBox.Show("Nie można usunąć licencji. Jeden z jej plików jest obecnie używany.", "Error");
                         }
                         catch (System.NotSupportedException)
                         {
                             MessageBox.Show("Błędna scieżka do licencji", "Error");
                         }
                         catch (System.UnauthorizedAccessException)
                         {
                             MessageBox.Show("Program nie posiada uprawnień do usuwania plików", "Error");
                         }
                     }
                     this.getActiveLicense();
                     this.getOtherLicense();
                 }
                 catch (System.ArgumentOutOfRangeException)
                 {
                 }
             }
         }
     }
     catch (System.Exception)
     {
     }
 }
Exemple #6
0
 public Start()
 {
     try
     {
         this.InitializeComponent();
         this.Text = "Kalkulator (" + Kalkulator1.instalClass.Version.getVersion().ToString() + ")";
         Start.listaPlikow.Add("START");
         this.path = System.IO.Path.GetTempPath() + "KBW";
         if (!System.IO.Directory.Exists(this.path))
         {
             try
             {
                 System.IO.Directory.CreateDirectory(this.path);
             }
             catch (System.ArgumentNullException)
             {
                 MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"KBW\"", "Error");
             }
             catch (System.ArgumentException)
             {
                 MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"KBW\"", "Error");
             }
             catch (System.UnauthorizedAccessException)
             {
                 MessageBox.Show("Nie masz uprawnień do tworzenia katalogów. Otwórz aplikacje jako adnimistrator.", "Uwaga");
             }
             catch (System.IO.PathTooLongException)
             {
                 MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"KBW\"", "Error");
             }
             catch (System.IO.DirectoryNotFoundException)
             {
                 MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"KBW\"", "Error");
             }
             catch (System.NotSupportedException)
             {
                 MessageBox.Show("Nieprawidłowy format ścieżki. Nie można utworzyć katalogu \"KBW\"", "Error");
             }
             catch (System.IO.IOException)
             {
                 MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"KBW\"", "Error");
             }
         }
         if (!System.IO.Directory.Exists(this.path + "\\tmp"))
         {
             Instal inst = new Instal(this.path);
         }
         if (System.IO.Directory.Exists(System.IO.Path.GetTempPath() + "KBW\\tmp"))
         {
             if (!System.IO.File.Exists(System.IO.Path.GetTempPath() + "KBW\\tmp\\eksport.xml"))
             {
                 System.IO.File.Create(System.IO.Path.GetTempPath() + "KBW\\tmp\\eksport.xml");
             }
             if (!System.IO.File.Exists(System.IO.Path.GetTempPath() + "KBW\\tmp\\import.xml"))
             {
                 System.IO.File.Create(System.IO.Path.GetTempPath() + "KBW\\tmp\\import.xml");
             }
             if (!System.IO.File.Exists(System.IO.Path.GetTempPath() + "KBW\\tmp\\eksportCode.xml"))
             {
                 System.IO.File.Create(System.IO.Path.GetTempPath() + "KBW\\tmp\\eksportCode.xml");
             }
         }
         this.logged = false;
         this.certificate = new Certificate();
         this.con = new Connection();
         this.LicencesTable.CellClick += new DataGridViewCellEventHandler(this.LicencesTable_CellClick);
         this.waitLicenses.CellClick += new DataGridViewCellEventHandler(this.waitLicenses_CellClick);
         this.wait = new WaitPanel("Wait1", base.Width, base.Height);
         base.Controls.Add(this.wait.getPanel());
         base.Controls[this.wait.getName()].BringToFront();
         this.getActiveLicense();
         this.getOtherLicense();
         if (!Kalkulator1.instalClass.Version.newApp())
         {
             MessageBox.Show("Twoja wersja kalkulatora wyborczego jest nieaktualna.", "Uwaga");
         }
     }
     catch (System.Exception)
     {
     }
 }
Exemple #7
0
 private void getActiveLicense()
 {
     this.wait.setWaitPanel("Trwa wczytywanie licencji", "Proszę czekać");
     this.wait.setVisible(true);
     if (System.IO.Directory.Exists(this.path + "\\Licenses"))
     {
         DataTable dt = new DataTable();
         this.LicencesTable.DataSource = dt;
         dt.Columns.Add(new DataColumn("lp", typeof(string)));
         dt.Columns.Add(new DataColumn("Licencja", typeof(string)));
         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[]
                 {
                     '\\'
                 });
                 DataRow dr = dt.NewRow();
                 dr[0] = dt.Rows.Count + 1;
                 dr[1] = filename[filename.Length - 1];
                 dt.Rows.Add(dr);
             }
         }
         if (dt.Rows.Count > 0)
         {
             this.LicencesTable.DataSource = dt;
             this.LicencesTable.Columns["lp"].DisplayIndex = 0;
             this.LicencesTable.Columns["lp"].FillWeight = 15f;
             this.LicencesTable.Columns["Licencja"].DisplayIndex = 1;
             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(2, btn);
                 this.LicencesTable.Columns["action"].FillWeight = 23f;
             }
             else
             {
                 this.LicencesTable.Columns["action"].DisplayIndex = 2;
                 this.LicencesTable.Columns["action"].FillWeight = 23f;
             }
             DataGridViewButtonColumn btn2 = new DataGridViewButtonColumn();
             btn2.HeaderText = "";
             btn2.Text = "Zapisz";
             btn2.Name = "save";
             btn2.UseColumnTextForButtonValue = true;
             if (this.LicencesTable.Columns["save"] == null)
             {
                 this.LicencesTable.Columns.Insert(3, btn2);
                 this.LicencesTable.Columns["save"].FillWeight = 23f;
             }
             else
             {
                 this.LicencesTable.Columns["save"].DisplayIndex = 3;
                 this.LicencesTable.Columns["save"].FillWeight = 23f;
             }
             DataGridViewButtonColumn btn3 = new DataGridViewButtonColumn();
             btn3.HeaderText = "";
             btn3.Text = "Usuń";
             btn3.Name = "remove";
             btn3.UseColumnTextForButtonValue = true;
             if (this.LicencesTable.Columns["remove"] == null)
             {
                 this.LicencesTable.Columns.Insert(4, btn3);
                 this.LicencesTable.Columns["remove"].FillWeight = 23f;
             }
             else
             {
                 this.LicencesTable.Columns["remove"].DisplayIndex = 4;
                 this.LicencesTable.Columns["remove"].FillWeight = 23f;
             }
             this.licensesPanel.Visible = true;
         }
     }
     else
     {
         this.licensesPanel.Visible = false;
     }
     this.wait.setVisible(false);
 }
Exemple #8
0
 private void LoginNext_Click(object sender, System.EventArgs e)
 {
     this.error.Visible = false;
     Certificate cert = new Certificate();
     this.form.logged = cert.readKey(this.filepath, this.password.Text);
     if (this.form.logged)
     {
         this.loggin = true;
         this.error.Visible = false;
         base.Close();
     }
     else
     {
         this.error.Visible = true;
     }
 }