Example #1
0
        private void f_SignXml()
        {
            if (isValidated)
            {
                var receipts = new receiptsType();
                receipts.receipt = Receipt;
                Receipt.id = "1";

                System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(receipts.GetType());

                using (StringWriter textWriter = new StringWriter())
                        {

                    serializer.Serialize(textWriter, receipts);

                    XmlDocument doc = new XmlDocument();

                    doc.InnerXml = textWriter.ToString();

                    Signer signer = new Signer(doc.InnerXml.ToString());
                    signedXml = signer.SignXml();

                    string file = DateTime.Now.ToString("dd.MM.yyyy_hhmmss") + "-" + Receipt.provider.companyregnum+ "_signed";
                    DialogResult result = fbdSelectSavingPlace.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        file = fbdSelectSavingPlace.SelectedPath + "\\" + file + ".xml";
                        File.WriteAllText(file, signedXml = signer.SignXml());

                    }
                }
            }
            else
                MessageBox.Show("Pred podpísaním prosím validujte formulár stlačením tlačidla 'Validuj'.", "Chyba validácie!", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Example #2
0
        private void f_SaveAs(string format)
        {
            if (isValidated)
            {
                var receipts = new receiptsType();
                receipts.receipt = Receipt;
                Receipt.id = "1";

                string file = DateTime.Now.ToString("dd.MM.yyyy_hhmmss") + "-" + Receipt.provider.companyregnum;
                DialogResult result = fbdSelectSavingPlace.ShowDialog();
                if (result == DialogResult.OK)
                {
                    file = fbdSelectSavingPlace.SelectedPath + "\\" + file + "." + format.ToLower();
                    System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(receipts.GetType());

                    if (format.ToLower() == "xml")
                    {
                        Stream writer = new FileStream(file, FileMode.Create);
                        serializer.Serialize(writer, receipts);
                        writer.Close();

                    }
                    else if (format.ToLower() == "txt")
                    {
                        XmlToTxtTransformation transformation;
                        using (StringWriter textWriter = new StringWriter())
                        {
                            serializer.Serialize(textWriter, receipts);

                            transformation = new XmlToTxtTransformation(textWriter.ToString(), Resources.XML_to_TXT_XSLT);
                        }
                        File.WriteAllText(file, transformation.f_TransformXml());
                    }

                }
                else if (result == DialogResult.Cancel)
                {

                }
                else
                    MessageBox.Show("Nastala chyba pri výbere miesta uloženia. Prosím opakujte.", "Chyba výberu miesta uloženia!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
                MessageBox.Show("Pred uložením prosím validujte formulár stlačením tlačidla 'Validuj'.", "Chyba validácie!", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }