Пример #1
0
 private void LicencesTable_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (e.RowIndex >= 0)
         {
             if (e.ColumnIndex == this.LicencesTable.Columns["action"].Index)
             {
                 try
                 {
                     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");
                         }
                     }
                     object name = this.LicencesTable.Rows[e.RowIndex].Cells["Licencja"].Value;
                     string filepath = this.path + "\\Licenses\\" + name.ToString();
                     Commit com = new Commit(filepath, this);
                     com.ShowDialog();
                     if (this.logged)
                     {
                         this.logged = false;
                         string[] ou = this.readOU(filepath).Split(new char[]
                         {
                             '-'
                         });
                         if (ou[2] == "P" || ou[2] == "O" || ou[2] == "Z")
                         {
                             this.wait.setWaitPanel("Trwa przygotowanie listy protokołów", "Proszę czekać");
                             this.wait.setVisible(true);
                             ProtocolsList startprotocols = new ProtocolsList(filepath, this, filepath, Kalkulator1.instalClass.Version.getVersion());
                             startprotocols.ShowDialog();
                         }
                         if (ou[2] == "A")
                         {
                             this.jns = "";
                             bool powiat = false;
                             string jnsTMP = ou[1];
                             if (jnsTMP.Length < 6)
                             {
                                 while (jnsTMP.Length < 6)
                                 {
                                     jnsTMP = "0" + jnsTMP;
                                 }
                             }
                             if (jnsTMP[4] == '0' && jnsTMP[5] == '0')
                             {
                                 powiat = true;
                                 RegionList rl = new RegionList(this, filepath, ou[1]);
                                 try
                                 {
                                     rl.ShowDialog();
                                 }
                                 catch (System.Exception)
                                 {
                                 }
                             }
                             else
                             {
                                 this.jns = ou[1];
                             }
                             if (this.jns != null && this.jns != "")
                             {
                                 ProtocolsList startprotocols = new ProtocolsList(filepath, this, filepath, Kalkulator1.instalClass.Version.getVersion(), this.jns, powiat);
                                 startprotocols.ShowDialog();
                             }
                             this.jns = "";
                         }
                     }
                 }
                 catch (System.ArgumentOutOfRangeException)
                 {
                 }
                 catch (System.Exception ex)
                 {
                     MessageBox.Show("Operacja nie powiodła się. Spróbuj jeszcze raz. Orginal error: " + ex.Message, "Uwaga");
                 }
             }
             if (e.ColumnIndex == this.LicencesTable.Columns["remove"].Index)
             {
                 try
                 {
                     DialogResult result = MessageBox.Show("Czy napewno usunąć licencje " + this.LicencesTable.Rows[e.RowIndex].Cells["Licencja"].Value.ToString() + "?", "Usuwanie", MessageBoxButtons.YesNo);
                     if (result == DialogResult.Yes)
                     {
                         try
                         {
                             System.IO.File.Delete(this.path + "\\Licenses\\" + this.LicencesTable.Rows[e.RowIndex].Cells["Licencja"].Value.ToString());
                             System.IO.File.Delete(this.path + "\\Licenses\\" + this.LicencesTable.Rows[e.RowIndex].Cells["Licencja"].Value.ToString().Replace(".crt", ".key"));
                             this.LicencesTable.Rows.Remove(this.LicencesTable.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)
                 {
                 }
             }
             else
             {
                 if (e.ColumnIndex == this.LicencesTable.Columns["save"].Index)
                 {
                     try
                     {
                         System.IO.StreamReader sr = new System.IO.StreamReader(this.path + "\\Licenses\\" + this.LicencesTable.Rows[e.RowIndex].Cells["Licencja"].Value.ToString());
                         string file = sr.ReadToEnd();
                         sr.Close();
                         SaveFileDialog wnd = new SaveFileDialog();
                         wnd.Title = "Zapisywanie licencji";
                         wnd.Filter = "(*.pem)|*.pem";
                         wnd.FileName = this.LicencesTable.Rows[e.RowIndex].Cells["Licencja"].Value.ToString();
                         wnd.ShowDialog();
                         this.wait.setWaitPanel("Trwa zapisywanie licencji", "Proszę czekać");
                         this.wait.setVisible(true);
                         string name2 = wnd.FileName;
                         try
                         {
                             if (name2 != "")
                             {
                                 System.IO.StreamWriter sw = new System.IO.StreamWriter(name2, false);
                                 sw.Write(file);
                                 sw.Close();
                             }
                             this.wait.setVisible(false);
                         }
                         catch (System.UnauthorizedAccessException)
                         {
                             MessageBox.Show("Nie można zapisać pliku. Otwórz aplikacje jako administracje", "Error");
                         }
                         catch (System.Exception ex)
                         {
                             MessageBox.Show("Nie można zapisać pliku. Orginal exception: " + ex.Message, "Error");
                         }
                     }
                     catch (System.ArgumentOutOfRangeException)
                     {
                     }
                 }
             }
         }
     }
     catch (System.Exception)
     {
     }
 }