Example #1
0
 public Commit(string filepath, ProtocolForm pf)
 {
     this.InitializeComponent();
     this.filepath = filepath;
     this.form2 = pf;
     this.LoginNext.Click -= new System.EventHandler(this.LoginNext_Click);
     this.LoginNext.Click += new System.EventHandler(this.LoginNext2_Click);
     this.loggin = false;
     string[] filepathpart = filepath.Split(new char[]
     {
         '\\'
     });
     this.label1.Text = filepathpart[filepathpart.Length - 1].Replace(".pem", "");
     this.form2.goodcertificate = false;
     this.codeBarLabel.Visible = false;
 }
 private void getProtocol_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (e.ColumnIndex == this.protocolsTable.Columns["fill"].Index)
         {
             if (e.RowIndex >= 0)
             {
                 try
                 {
                     int result = System.DateTime.Compare(this.electionData, System.DateTime.Now);
                     result = -1;
                     if (result <= 0)
                     {
                         try
                         {
                             object st = this.protocolsTable.Rows[e.RowIndex].Cells["Status"].Value;
                             if (st != null && st.ToString().ToLower() != "podpisany" && st.ToString().ToLower() != "wysłany")
                             {
                                 object protokol = this.protocolsTable.Rows[e.RowIndex].Cells["Protokol"].Value;
                                 object jns = this.protocolsTable.Rows[e.RowIndex].Cells["Gmina"].Value;
                                 object obw = this.protocolsTable.Rows[e.RowIndex].Cells["Obwód"].Value;
                                 object inst = this.protocolsTable.Rows[e.RowIndex].Cells["Instytucja"].Value;
                                 object okr = this.protocolsTable.Rows[e.RowIndex].Cells["Okręg"].Value;
                                 if (jns != null && obw != null && inst != null && okr != null && protokol != null)
                                 {
                                     try
                                     {
                                         string save = "";
                                         string[] protocolpart = protokol.ToString().Split(new char[]
                                         {
                                             '-'
                                         });
                                         string instJNS = protocolpart[4];
                                         string[] okr2 = okr.ToString().Split(new char[]
                                         {
                                             ' '
                                         });
                                         save = this.path + "\\saves\\" + protokol.ToString();
                                         string candidates = string.Concat(new string[]
                                         {
                                             this.path,
                                             "\\ProtocolsDef\\",
                                             this.electoralEampaignSave,
                                             "-",
                                             inst.ToString(),
                                             "-",
                                             instJNS,
                                             "-",
                                             okr2[0],
                                             ".xml"
                                         });
                                         string protocolDefinition = string.Concat(new string[]
                                         {
                                             this.path,
                                             "\\ProtocolsDef\\",
                                             this.electoralEampaignSave,
                                             "-",
                                             inst.ToString(),
                                             ".xml"
                                         });
                                         string committee = string.Concat(new string[]
                                         {
                                             this.path,
                                             "\\ProtocolsDef\\",
                                             this.electoralEampaignSave,
                                             "-",
                                             this.jns,
                                             "-",
                                             obw.ToString(),
                                             ".xml"
                                         });
                                         string validateDefinition = string.Concat(new string[]
                                         {
                                             this.path,
                                             "\\ProtocolsDef\\",
                                             this.electoralEampaignSave,
                                             "-",
                                             inst.ToString(),
                                             "_Walidacja.xml"
                                         });
                                         string OU = "";
                                         if (this.role == "P" || this.role == "Z")
                                         {
                                             OU = string.Concat(new object[]
                                             {
                                                 this.electoralEampaignURL.Trim(new char[]
                                                 {
                                                     ' '
                                                 }),
                                                 "-",
                                                 jns,
                                                 "-",
                                                 this.role,
                                                 "-",
                                                 this.circuit
                                             });
                                         }
                                         if (this.role == "O" || this.role == "A")
                                         {
                                             OU = string.Concat(new object[]
                                             {
                                                 this.electoralEampaignURL.Trim(new char[]
                                                 {
                                                     ' '
                                                 }),
                                                 "-",
                                                 jns,
                                                 "-",
                                                 this.role
                                             });
                                         }
                                         ProtocolForm pf = new ProtocolForm(this, this.header, protocolDefinition, candidates, committee, validateDefinition, save, OU, this.licensepath, this.version);
                                         try
                                         {
                                             pf.ShowDialog();
                                         }
                                         catch (System.Exception ex)
                                         {
                                             this.createProtocols();
                                         }
                                         this.refreshListOfProtocols();
                                     }
                                     catch (XmlException)
                                     {
                                         MessageBox.Show("Nieprawidłowy XML", "Error");
                                     }
                                 }
                             }
                         }
                         catch (System.Exception ex)
                         {
                             MessageBox.Show(ex.Message, "Error");
                         }
                     }
                     else
                     {
                         MessageBox.Show("Protokoły wypełniać można od " + this.electionData.ToShortDateString(), "Komunikat");
                     }
                 }
                 catch (System.Exception ex)
                 {
                     MessageBox.Show("Fill: " + ex.Message, "Error");
                 }
             }
         }
         if (e.ColumnIndex == this.protocolsTable.Columns["new"].Index)
         {
             try
             {
                 if (e.RowIndex >= 0)
                 {
                     object protokol = this.protocolsTable.Rows[e.RowIndex].Cells["Protokol"].Value;
                     object jns = this.protocolsTable.Rows[e.RowIndex].Cells["Gmina"].Value;
                     object obw = this.protocolsTable.Rows[e.RowIndex].Cells["Obwód"].Value;
                     object inst = this.protocolsTable.Rows[e.RowIndex].Cells["Instytucja"].Value;
                     object okr = this.protocolsTable.Rows[e.RowIndex].Cells["Okręg"].Value;
                     object status = this.protocolsTable.Rows[e.RowIndex].Cells["Status"].Value;
                     if (jns != null && obw != null && inst != null && okr != null)
                     {
                         try
                         {
                             if (protokol != null && status != null && (status.ToString().ToLower() == "podpisany" || status.ToString().ToLower() == "wysłany"))
                             {
                                 DialogResult dr = MessageBox.Show("Utworzenie nowego protokołu spowoduje nadpisanie wcześniej zachowanych danych. Czy kontynuować?", "Nowy protokół", MessageBoxButtons.YesNo);
                                 DialogResult dialogResult = dr;
                                 if (dialogResult == DialogResult.No)
                                 {
                                     return;
                                 }
                                 string protokolname = protokol.ToString();
                                 string[] partname = protokol.ToString().Split(new char[]
                                 {
                                     ' '
                                 });
                                 if (partname.Length >= 2)
                                 {
                                     protokolname = partname[0];
                                 }
                                 int num = System.IO.Directory.GetFiles(this.path + "\\saves", protokolname + "*.xml").Length;
                                 string namefile = protokolname.Replace(".xml", "");
                                 namefile = namefile + " " + (num + 1).ToString();
                                 System.IO.File.Move(this.path + "\\saves\\" + protokol.ToString(), this.path + "\\saves\\" + namefile + ".xml");
                             }
                             System.IO.StreamWriter sw = new System.IO.StreamWriter(this.path + "\\saves\\" + protokol.ToString(), false);
                             sw.Write("<?xml version=\"1.0\"?><save><status>niewypełniony</status></save>");
                             sw.Close();
                             this.getProtocols(false);
                             if (jns != null && obw != null && inst != null && okr != null)
                             {
                                 try
                                 {
                                     string save = "";
                                     string[] protocolpart = protokol.ToString().Split(new char[]
                                     {
                                         '-'
                                     });
                                     string instJNS = protocolpart[4];
                                     string[] okr2 = okr.ToString().Split(new char[]
                                     {
                                         ' '
                                     });
                                     save = this.path + "\\saves\\" + protokol.ToString();
                                     string candidates = string.Concat(new string[]
                                     {
                                         this.path,
                                         "\\ProtocolsDef\\",
                                         this.electoralEampaignSave,
                                         "-",
                                         inst.ToString(),
                                         "-",
                                         instJNS,
                                         "-",
                                         okr2[0],
                                         ".xml"
                                     });
                                     string protocolDefinition = string.Concat(new string[]
                                     {
                                         this.path,
                                         "\\ProtocolsDef\\",
                                         this.electoralEampaignSave,
                                         "-",
                                         inst.ToString(),
                                         ".xml"
                                     });
                                     string committee = string.Concat(new string[]
                                     {
                                         this.path,
                                         "\\ProtocolsDef\\",
                                         this.electoralEampaignSave,
                                         "-",
                                         this.jns,
                                         "-",
                                         obw.ToString(),
                                         ".xml"
                                     });
                                     string validateDefinition = string.Concat(new string[]
                                     {
                                         this.path,
                                         "\\ProtocolsDef\\",
                                         this.electoralEampaignSave,
                                         "-",
                                         inst.ToString(),
                                         "_Walidacja.xml"
                                     });
                                     string OU = "";
                                     if (this.role == "P" || this.role == "Z")
                                     {
                                         OU = string.Concat(new object[]
                                         {
                                             this.electoralEampaignURL.Trim(new char[]
                                             {
                                                 ' '
                                             }),
                                             "-",
                                             jns,
                                             "-",
                                             this.role,
                                             "-",
                                             this.circuit
                                         });
                                     }
                                     if (this.role == "O")
                                     {
                                         OU = string.Concat(new object[]
                                         {
                                             this.electoralEampaignURL.Trim(new char[]
                                             {
                                                 ' '
                                             }),
                                             "-",
                                             jns,
                                             "-",
                                             this.role
                                         });
                                     }
                                     ProtocolForm pf = new ProtocolForm(this, this.header, protocolDefinition, candidates, committee, validateDefinition, save, OU, this.licensepath, this.version);
                                     try
                                     {
                                         pf.ShowDialog();
                                     }
                                     catch (System.Exception)
                                     {
                                         this.createProtocols();
                                     }
                                     this.refreshListOfProtocols();
                                 }
                                 catch (XmlException)
                                 {
                                     MessageBox.Show("Nieprawidłowy XML", "Error");
                                 }
                             }
                         }
                         catch (XmlException)
                         {
                             MessageBox.Show("Nieprawidłowy XML", "Error");
                         }
                     }
                 }
             }
             catch (System.Exception ex)
             {
                 MessageBox.Show(ex.Message, "Error");
             }
         }
         if (e.ColumnIndex == this.protocolsTable.Columns["print"].Index | e.ColumnIndex == this.protocolsTable.Columns["pdf"].Index)
         {
             try
             {
                 if (e.RowIndex >= 0)
                 {
                     object protokol = this.protocolsTable.Rows[e.RowIndex].Cells["Protokol"].Value;
                     object jns = this.protocolsTable.Rows[e.RowIndex].Cells["Gmina"].Value;
                     object obw = this.protocolsTable.Rows[e.RowIndex].Cells["Obwód"].Value;
                     object inst = this.protocolsTable.Rows[e.RowIndex].Cells["Instytucja"].Value;
                     object okr = this.protocolsTable.Rows[e.RowIndex].Cells["Okręg"].Value;
                     if (jns != null && obw != null && inst != null && okr != null && protokol != null)
                     {
                         this.wait.setWaitPanel("Trwa przygotowanie do druku", "Druk");
                         if (e.ColumnIndex == this.protocolsTable.Columns["pdf"].Index)
                         {
                             this.wait.setWaitPanel("Trwa generowanie PDF", "PDF");
                         }
                         this.wait.setVisible(true);
                         try
                         {
                             string save = "";
                             string[] protocolpart = protokol.ToString().Split(new char[]
                             {
                                 '-'
                             });
                             string instJNS = protocolpart[4];
                             string[] okr2 = okr.ToString().Split(new char[]
                             {
                                 ' '
                             });
                             save = this.path + "\\saves\\" + protokol.ToString();
                             string candidates = string.Concat(new string[]
                             {
                                 this.path,
                                 "\\ProtocolsDef\\",
                                 this.electoralEampaignSave,
                                 "-",
                                 inst.ToString(),
                                 "-",
                                 instJNS,
                                 "-",
                                 okr2[0],
                                 ".xml"
                             });
                             string protocolDefinition = string.Concat(new string[]
                             {
                                 this.path,
                                 "\\ProtocolsDef\\",
                                 this.electoralEampaignSave,
                                 "-",
                                 inst.ToString(),
                                 ".xml"
                             });
                             string docDefinition = protocolDefinition.Replace(".xml", ".docx");
                             XmlDocument protocolDefinition2 = new XmlDocument();
                             XmlDocument save2 = new XmlDocument();
                             XmlDocument candidates2 = new XmlDocument();
                             protocolDefinition2.Load(protocolDefinition);
                             save2.Load(save);
                             candidates2.Load(candidates);
                             string controlSum = "";
                             XmlNode saveStep = save2.SelectSingleNode("/save/step");
                             if (saveStep != null && saveStep.InnerText == "0")
                             {
                                 string docXml = "";
                                 XmlNode header = save2.SelectSingleNode("/save/header");
                                 if (header != null)
                                 {
                                     docXml += header.OuterXml;
                                 }
                                 XmlNode step = save2.SelectSingleNode("/save/step");
                                 if (step != null)
                                 {
                                     docXml += step.OuterXml;
                                 }
                                 XmlNode form = save2.SelectSingleNode("/save/form");
                                 if (form != null)
                                 {
                                     docXml += form.OuterXml;
                                 }
                                 XmlNode komisja_sklad = save2.SelectSingleNode("/save/komisja_sklad");
                                 if (komisja_sklad != null)
                                 {
                                     docXml += komisja_sklad.OuterXml;
                                 }
                                 XmlNode hardWarningCode = save2.SelectSingleNode("/save/hardWarningCode");
                                 if (hardWarningCode != null)
                                 {
                                     docXml += hardWarningCode.OuterXml;
                                 }
                                 XmlNode softError = save2.SelectSingleNode("/save/softError");
                                 if (softError != null)
                                 {
                                     docXml += softError.OuterXml;
                                 }
                                 XmlNode hardError = save2.SelectSingleNode("/save/hardError");
                                 if (hardError != null)
                                 {
                                     docXml += hardError.OuterXml;
                                 }
                                 XmlNode hardWarning = save2.SelectSingleNode("/save/hardWarning");
                                 if (hardWarning != null)
                                 {
                                     docXml += hardWarning.OuterXml;
                                 }
                                 ClassMd5 i = new ClassMd5();
                                 controlSum = i.CreateMD5Hash(docXml);
                             }
                             printProtocolNew p = new printProtocolNew();
                             if (e.ColumnIndex == this.protocolsTable.Columns["print"].Index)
                             {
                                 p.ProtocolPrint(this.header, save2, candidates2, docDefinition, controlSum, false, obw.ToString(), inst.ToString(), okr.ToString(), candidates, instJNS);
                             }
                             else
                             {
                                 p.ProtocolPrint(this.header, save2, candidates2, docDefinition, controlSum, true, obw.ToString(), inst.ToString(), okr.ToString(), candidates, instJNS);
                             }
                         }
                         catch (XmlException)
                         {
                             MessageBox.Show("Nieprawidłowy XML", "Error");
                         }
                     }
                     this.wait.setVisible(false);
                 }
             }
             catch (System.Exception ex)
             {
                 MessageBox.Show("Print: " + ex.Message, "Error");
             }
         }
         if (e.ColumnIndex == this.protocolsTable.Columns["send"].Index)
         {
             try
             {
                 if (e.RowIndex >= 0)
                 {
                     object st = this.protocolsTable.Rows[e.RowIndex].Cells["Status"].Value;
                     if (st != null && (st.ToString().ToLower() == "podpisany" || st.ToString().ToLower() == "wysłany"))
                     {
                         object protokol = this.protocolsTable.Rows[e.RowIndex].Cells["Protokol"].Value;
                         object jns = this.protocolsTable.Rows[e.RowIndex].Cells["Gmina"].Value;
                         object obw = this.protocolsTable.Rows[e.RowIndex].Cells["Obwód"].Value;
                         object inst = this.protocolsTable.Rows[e.RowIndex].Cells["Instytucja"].Value;
                         object okr = this.protocolsTable.Rows[e.RowIndex].Cells["Okręg"].Value;
                         if (jns != null && obw != null && inst != null && okr != null && protokol != null)
                         {
                             try
                             {
                                 string save = "";
                                 string[] okr2 = okr.ToString().Split(new char[]
                                 {
                                     ' '
                                 });
                                 save = this.path + "\\saves\\" + protokol.ToString();
                                 System.IO.StreamReader sr = new System.IO.StreamReader(save);
                                 string fileXML = sr.ReadToEnd();
                                 sr.Close();
                                 fileXML = fileXML.Replace("<status>wysłany</status>", "<status>podpisany</status>");
                                 if (this.con.IsAvailableNetworkActive())
                                 {
                                     this.erros = false;
                                     this.send = false;
                                     Eksport ex2 = new Eksport(fileXML, true, this);
                                     try
                                     {
                                         ex2.ShowDialog();
                                     }
                                     catch (System.Exception)
                                     {
                                     }
                                     if (this.send)
                                     {
                                         this.send = false;
                                         fileXML = fileXML.Replace("<status>podpisany</status>", "<status>wysłany</status>");
                                         System.IO.StreamWriter sw = new System.IO.StreamWriter(save);
                                         sw.Write(fileXML);
                                         sw.Close();
                                         this.refreshListOfProtocols();
                                     }
                                     if (!this.send && this.erros)
                                     {
                                         XmlDocument saveTmp = new XmlDocument();
                                         fileXML = fileXML.Replace("<status>podpisany</status>", "<status>roboczy</status>");
                                         fileXML = fileXML.Replace("<status>wysłany</status>", "<status>roboczy</status>");
                                         saveTmp.LoadXml(fileXML);
                                         XmlNode root = saveTmp.DocumentElement;
                                         try
                                         {
                                             root.RemoveChild(root.SelectSingleNode("/save/codeBar"));
                                         }
                                         catch (System.Exception)
                                         {
                                         }
                                         try
                                         {
                                             root.RemoveChild(root.SelectSingleNode("/save/Signature"));
                                         }
                                         catch (System.Exception)
                                         {
                                         }
                                         saveTmp.Save(save);
                                         this.refreshListOfProtocols();
                                     }
                                 }
                                 else
                                 {
                                     MessageBox.Show("Protokół nie został wysłany z powodu braku Internetu.");
                                 }
                             }
                             catch (XmlException)
                             {
                                 MessageBox.Show("Nieprawidłowy XML", "Error");
                             }
                             catch (System.NullReferenceException)
                             {
                                 MessageBox.Show("Podanno inny xml niz header", "Error");
                             }
                         }
                     }
                     if (st != null && (st.ToString().ToLower() == "roboczy" || (st != null && st.ToString().ToLower() == "niewypełniony")))
                     {
                         MessageBox.Show("Nie można wysłać protokołu o statusie: \"" + st.ToString().ToLower() + "\"", "Komunikat");
                     }
                 }
             }
             catch (System.Exception ex)
             {
                 MessageBox.Show(ex.Message, "Error");
             }
         }
         if (e.ColumnIndex == this.protocolsTable.Columns["save1"].Index)
         {
             if (e.RowIndex >= 0)
             {
                 object protokol = this.protocolsTable.Rows[e.RowIndex].Cells["Protokol"].Value;
                 string savePath = this.path + "\\saves\\" + protokol.ToString();
                 System.IO.StreamReader sr = new System.IO.StreamReader(savePath);
                 string file = sr.ReadToEnd();
                 sr.Close();
                 string[] nameFile = savePath.Split(new char[]
                 {
                     '\\'
                 });
                 SaveFileDialog wnd = new SaveFileDialog();
                 wnd.Filter = "(*.xml)|*.xml";
                 wnd.FileName = nameFile[nameFile.Length - 1];
                 if (wnd.ShowDialog() != DialogResult.Cancel)
                 {
                     this.wait.setWaitPanel("Trwa eksportowanie protokołu", "Proszę czekać");
                     this.wait.setVisible(true);
                     if (wnd.CheckPathExists)
                     {
                         string name = wnd.FileName;
                         try
                         {
                             if (name != null && name != "" && name != nameFile[nameFile.Length - 1])
                             {
                                 System.IO.StreamWriter sw = new System.IO.StreamWriter(name, false);
                                 sw.Write(file);
                                 sw.Close();
                             }
                             this.wait.setVisible(false);
                         }
                         catch (System.UnauthorizedAccessException)
                         {
                             MessageBox.Show("Nie jestes uprawniony do zapisania pliku we wskazanym miejscu", "Uwaga");
                         }
                     }
                 }
             }
         }
     }
     catch (System.ArgumentOutOfRangeException ex_17A7)
     {
     }
     catch (System.Exception ex)
     {
     }
 }
Example #3
0
 public Commit(string filepath, ProtocolForm pf, string xml)
 {
     this.InitializeComponent();
     this.filepath = filepath;
     this.form2 = pf;
     this.LoginNext.Click -= new System.EventHandler(this.LoginNext_Click);
     this.LoginNext.Click += new System.EventHandler(this.LoginNext2_Click);
     this.loggin = false;
     string[] filepathpart = filepath.Split(new char[]
     {
         '\\'
     });
     this.label1.Text = filepathpart[filepathpart.Length - 1].Replace(".pem", "");
     this.form2.goodcertificate = false;
     string docXml = "";
     XmlDocument save = new XmlDocument();
     save.LoadXml(xml);
     XmlNode header = save.SelectSingleNode("/save/header");
     if (header != null)
     {
         docXml += header.OuterXml;
     }
     XmlNode step = save.SelectSingleNode("/save/step");
     if (step != null)
     {
         docXml += step.OuterXml;
     }
     XmlNode form = save.SelectSingleNode("/save/form");
     if (form != null)
     {
         docXml += form.OuterXml;
     }
     XmlNode komisja_sklad = save.SelectSingleNode("/save/komisja_sklad");
     if (komisja_sklad != null)
     {
         docXml += komisja_sklad.OuterXml;
     }
     XmlNode hardWarningCode = save.SelectSingleNode("/save/hardWarningCode");
     if (hardWarningCode != null)
     {
         docXml += hardWarningCode.OuterXml;
     }
     XmlNode softError = save.SelectSingleNode("/save/softError");
     if (softError != null)
     {
         docXml += softError.OuterXml;
     }
     XmlNode hardError = save.SelectSingleNode("/save/hardError");
     if (hardError != null)
     {
         docXml += hardError.OuterXml;
     }
     XmlNode hardWarning = 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.codeBarLabel.Text = "Podpisywanie protokołu o kodzie kreskowym: " + '\n'.ToString() + code.getTextReadable();
     this.codeBarLabel.Visible = true;
 }