Advertisement
csaki

Kérdőív kitöltő v1.0

Aug 24th, 2013
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 24.96 KB | None | 0 0
  1. // Form1.cs
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.IO;
  9. using System.Net;
  10. using System.Text;
  11. using System.Windows.Forms;
  12. //using Excel = Microsoft.Office.Interop.Excel;
  13.  
  14. namespace KerdoivKitolto
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         public string[] sorok;
  19.         public int lastPos;
  20.         public Kerdoiv kerdoiv;
  21.         public Button keszButton;
  22.         public string fajlnev;
  23.         public List<int> IDLista;
  24.         public int[] inttemp;
  25.         public string[] temp;
  26.         bool voltmar;
  27.  
  28.  
  29.         public Form1()
  30.         {
  31.             InitializeComponent();
  32.             listBox1.SelectedIndexChanged += listBox1_SelectedIndexChanged;
  33.             listBox1.MouseDoubleClick += listBox1_MouseDoubleClick;
  34.         }
  35.  
  36.         void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
  37.         {
  38.             if (listBox1.SelectedIndex >= 0)
  39.             {
  40.                 button1_Click(sender, e);
  41.             }
  42.         }
  43.  
  44.         void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  45.         {
  46.             if (listBox1.SelectedIndex >= 0)
  47.                 button1.Enabled = true;
  48.         }
  49.  
  50.         private void megnyitásToolStripMenuItem_Click(object sender, EventArgs e)
  51.         {
  52.             try
  53.             {
  54.                 mezőkVisszaállításaToolStripMenuItem.Enabled = false;
  55.                 this.Enabled = false;
  56.                 if (voltmar)
  57.                 {
  58.                     Controls.Clear();
  59.                     InitializeComponent();
  60.                     Refresh();
  61.                     listBox1.SelectedIndexChanged += listBox1_SelectedIndexChanged;
  62.                     listBox1.MouseDoubleClick += listBox1_MouseDoubleClick;
  63.                 }
  64.  
  65.                 IDLista = new List<int>(); // dirContent!
  66.                 button1.Enabled = false;
  67.                 temp = FTP.GetDirectoryContent("");
  68.  
  69.                 foreach (var x in temp)
  70.                 {
  71.                     if (x.Contains(".txt"))
  72.                     {
  73.                         IDLista.Add(int.Parse(x.Split('.')[0]));
  74.                     }
  75.                 }
  76.                 FTP.GetIDContent();
  77.                 temp = FTP.IDContent.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
  78.                 inttemp = new int[temp.Length];
  79.                 for (int i = 0; i < temp.Length; i++)
  80.                 {
  81.                     inttemp[i] = int.Parse(temp[i].Split('|')[0]);
  82.                     temp[i] = temp[i].Split('|')[1];
  83.                 }
  84.  
  85.                 for (int i = 0; i < IDLista.Count; i++)
  86.                 {
  87.                     for (int j = 0; j < inttemp.Length; j++)
  88.                     {
  89.                         if (IDLista[i] == inttemp[j])
  90.                         {
  91.                             listBox1.Items.Add(temp[i]);
  92.                         }
  93.                     }
  94.                 }
  95.             }
  96.             catch (Exception ex)
  97.             {
  98.                 MessageBox.Show(ex.Message + '\n' + ex.ToString().Substring(ex.ToString().LastIndexOf(':') + 1));
  99.             }
  100.             finally
  101.             {
  102.                 this.Enabled = true;
  103.             }
  104.         }
  105.  
  106.         private void button1_Click(object sender, EventArgs e)
  107.         {
  108.             if (listBox1.SelectedIndex < 0)
  109.                 MessageBox.Show("Válassz egy kérdőívet a listából!");
  110.             else
  111.             {
  112.                 try
  113.                 {
  114.                     label2.Enabled = false;
  115.                     label2.Visible = false;
  116.                     mezőkVisszaállításaToolStripMenuItem.Enabled = true;
  117.                     Refresh();
  118.                     fajlnev = IDLista[listBox1.SelectedIndex] + ".txt";
  119.                     //FTP.ID = IDLista[listBox1.SelectedIndex];
  120.                     sorok = FTP.DownloadFile("", fajlnev);
  121.  
  122.                     KerdoivPeldanyositas();
  123.                     Kirajzolas();
  124.  
  125.                     megnyitásToolStripMenuItem.Enabled = true;
  126.                     listBox1.Visible = false;
  127.                     listBox1.Enabled = false;
  128.                     button1.Enabled = false;
  129.                     button1.Visible = false;
  130.                 }
  131.                 catch (Exception ex)
  132.                 {
  133.                     MessageBox.Show(ex.Message + '\n' + ex.ToString().Substring(ex.ToString().LastIndexOf(':')));
  134.                 }
  135.             }
  136.         }
  137.  
  138.         private void Kirajzolas()
  139.         {
  140.             int tabindex = 0;
  141.             voltmar = true;
  142.             lastPos = 35;
  143.             ClientSize = new System.Drawing.Size(500, 530);
  144.             Label cim = new Label();
  145.             cim.TabIndex = tabindex;
  146.             tabindex++;
  147.             cim.Text = kerdoiv.cim;
  148.             cim.AutoSize = true;
  149.             cim.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  150.             cim.Location = new System.Drawing.Point(48, lastPos);
  151.             this.Controls.Add(cim);
  152.             lastPos += 25;
  153.  
  154.             label2.Visible = false;
  155.             label1.Visible = true;
  156.  
  157.             foreach (var k in kerdoiv.kerdesLista)
  158.             {
  159.                 int _last = 20;
  160.                 GroupBox box = new GroupBox();
  161.                 box.TabStop = true;
  162.                 box.TabIndex = tabindex;
  163.                 tabindex++;
  164.                 box.Location = new System.Drawing.Point(15, lastPos);
  165.                 box.Size = new System.Drawing.Size(431, k.hanykerdes * 35);
  166.                 box.Text = k.kerdes;
  167.                 this.Controls.Add(box);
  168.                 lastPos += 5;
  169.  
  170.                 if (k.tobblehetoseg)
  171.                 {
  172.                     for (int i = 0; i < k.hanykerdes; i++)
  173.                     {
  174.                         k.checks[i] = new CheckBox();
  175.                         k.checks[i].TabIndex = tabindex;
  176.                         tabindex++;
  177.                         k.checks[i].TabStop = true;
  178.                         k.checks[i].Text = k.valaszok[i];
  179.                         k.checks[i].Location = new System.Drawing.Point(10, _last);
  180.                         _last += 25;
  181.                         box.Controls.Add(k.checks[i]);
  182.                     }
  183.                 }
  184.                 else
  185.                 {
  186.                     for (int i = 0; i < k.hanykerdes; i++)
  187.                     {
  188.                         k.radios[i] = new RadioButton();
  189.                         k.radios[i].TabIndex = tabindex;
  190.                         tabindex++;
  191.                         k.radios[i].TabStop = true;
  192.                         k.radios[i].Text = k.valaszok[i];
  193.                         k.radios[i].Location = new System.Drawing.Point(10, _last);
  194.                         _last += 25;
  195.                         box.Controls.Add(k.radios[i]);
  196.                     }
  197.                 }
  198.  
  199.                 lastPos += k.hanykerdes * 40;
  200.             }
  201.  
  202.             keszButton = new Button();
  203.             keszButton.Text = "Kész!";
  204.             keszButton.Size = new System.Drawing.Size(150, 40);
  205.             keszButton.Location = new System.Drawing.Point((this.ClientRectangle.Width / 2) - keszButton.Size.Width / 2 - 20, lastPos + 10);
  206.             keszButton.AutoSize = true;
  207.             keszButton.TabIndex = tabindex;
  208.             tabindex++;
  209.             this.Controls.Add(keszButton);
  210.             keszButton.Click += keszButton_Click;
  211.  
  212.         }
  213.  
  214.         // private void ExcelMentes()
  215.         //{
  216.         //    Excel.Application xlApp;
  217.         //    Excel.Workbook xlWorkBook;
  218.         //    Excel.Worksheet xlWorkSheet;
  219.         //    object misValue = System.Reflection.Missing.Value;
  220.  
  221.         //    xlApp = new Excel.Application();
  222.         //    xlWorkBook = xlApp.Workbooks.Add(misValue);
  223.         //    xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
  224.  
  225.         //    xlWorkSheet.Cells[1, 1] = kerdoiv.cim;
  226.         //    for (int i = 0; i < kerdoiv.kerdesLista.Count; i++)
  227.         //    {
  228.         //        xlWorkSheet.Cells[i + 2, 1] = kerdoiv.kerdesLista[i].kerdes;
  229.  
  230.         //        if (kerdoiv.kerdesLista[i].tobblehetoseg)
  231.         //        {
  232.         //            int vissza = 0;
  233.         //            for (int j = 0; j < kerdoiv.kerdesLista[i].hanykerdes; j++)
  234.         //            {
  235.         //                if (kerdoiv.kerdesLista[i].tobbvalasz[j])
  236.         //                {
  237.         //                    xlWorkSheet.Cells[i + 2, j + 2 - vissza] = kerdoiv.kerdesLista[i].valaszok[j];
  238.         //                }
  239.         //                else
  240.         //                {
  241.         //                    vissza++;
  242.         //                    continue;
  243.         //                }
  244.         //            }
  245.         //        }
  246.         //        else
  247.         //        {
  248.         //            xlWorkSheet.Cells[i + 2, 2] = kerdoiv.kerdesLista[i].valaszok[kerdoiv.kerdesLista[i].valasz];
  249.         //        }
  250.         //    }
  251.         //    try
  252.         //    {
  253.         //        fajlnev = fajlnev.Split('.')[0];
  254.         //        xlWorkBook.SaveAs(fajlnev + ".xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
  255.  
  256.         //        MessageBox.Show("Az Excel fájl elkészült:\n\n " + fajlnev);
  257.         //    }
  258.         //    catch (Exception ex)
  259.         //    {
  260.         //        MessageBox.Show(ex.Message + '\n' + ex.ToString().Substring(ex.ToString().LastIndexOf(':') + 1));
  261.         //    }
  262.         //    finally
  263.         //    {
  264.         //        xlWorkBook.Close(true, misValue, misValue);
  265.         //        xlApp.Quit();
  266.  
  267.         //        releaseObject(xlWorkSheet);
  268.         //        releaseObject(xlWorkBook);
  269.         //        releaseObject(xlApp);
  270.         //    }
  271.         //}
  272.  
  273.         private void releaseObject(object obj)
  274.         {
  275.             try
  276.             {
  277.                 System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
  278.                 obj = null;
  279.             }
  280.             catch (Exception ex)
  281.             {
  282.                 obj = null;
  283.                 MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
  284.             }
  285.             finally
  286.             {
  287.                 GC.Collect();
  288.             }
  289.         }
  290.  
  291.         public void KerdoivPeldanyositas()
  292.         {
  293.             kerdoiv.kerdesLista = new List<Kerdes>();
  294.             kerdoiv.cim = sorok[0];
  295.             Kerdes k = new Kerdes();
  296.             string[] temp;
  297.             for (int i = 2; i < sorok.Length; i++)
  298.             {
  299.                 if (sorok[i] == "--")
  300.                 {
  301.                     k = new Kerdes();
  302.                     continue;
  303.                 }
  304.  
  305.                 temp = sorok[i].Split(':');
  306.                 k.hanyadik = Convert.ToInt32(temp[0]);
  307.                 k.kerdes = temp[1];
  308.                 i++;
  309.                 k.valaszok[0] = sorok[i];
  310.                 i++;
  311.                 k.valaszok[1] = sorok[i];
  312.                 i++;
  313.                 k.valaszok[2] = sorok[i];
  314.                 i++;
  315.                 k.valaszok[3] = sorok[i];
  316.                 i++;
  317.                 k.hanykerdes = Convert.ToInt32(sorok[i]);
  318.                 i++;
  319.                 k.tobblehetoseg = Convert.ToBoolean(sorok[i]);
  320.  
  321.                 kerdoiv.kerdesLista.Add(k);
  322.             }
  323.         }
  324.  
  325.         private void kilépésToolStripMenuItem_Click(object sender, EventArgs e)
  326.         {
  327.             if (MessageBox.Show("Biztosan szeretné zárni a kérdőív kitöltőt?", "Biztos?", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.OK)
  328.             {
  329.                 Environment.Exit(-1);
  330.             }
  331.         }
  332.  
  333.         private void mezőkVisszaállításaToolStripMenuItem_Click(object sender, EventArgs e)
  334.         {
  335.             Controls.Clear();
  336.             this.Controls.Add(this.label2);
  337.             this.Controls.Add(this.label1);
  338.             this.Controls.Add(this.menuStrip1);
  339.             this.ResumeLayout(false);
  340.             Kirajzolas();
  341.         }
  342.  
  343.         void keszButton_Click(object sender, EventArgs e)
  344.         {
  345.             if (!MindenholVaneValasz())
  346.             {
  347.                 MessageBox.Show("Kötelező mindenhol megjelölni egy választ!", "Figyelem!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  348.                 return;
  349.             }
  350.  
  351.             int index = 0;
  352.             try
  353.             {
  354.                 this.Enabled = false;
  355.                 ValaszokMentese(); // Kérdésekben eltárolva a válasz //
  356.  
  357.                 List<string> eredmenyLista = new List<string>();
  358.                 eredmenyLista.Add(kerdoiv.cim);
  359.                 foreach (var k in kerdoiv.kerdesLista)
  360.                 {
  361.                     eredmenyLista.Add("--");
  362.                     eredmenyLista.Add(k.kerdes);
  363.                     if (!k.tobblehetoseg) // radio
  364.                     {
  365.                         for (int i = 0; i < k.radios.Length; i++)
  366.                         {
  367.                             if (i == k.valasz)
  368.                                 eredmenyLista.Add("1");
  369.                             else eredmenyLista.Add("0");
  370.                         }
  371.                     }
  372.                     else // check
  373.                     {
  374.                         for (int i = 0; i < k.checks.Length; i++)
  375.                         {
  376.                             if (k.tobbvalasz[i]) eredmenyLista.Add("1");
  377.                             else eredmenyLista.Add("0");
  378.                         }
  379.                     }
  380.                 }
  381.                 string eredmeny;
  382.                 bool letezik = false;
  383.                 temp = FTP.GetDirectoryContent("stat");
  384.                 foreach (var x in temp)
  385.                 {
  386.                     if (x.Contains(fajlnev))
  387.                     {
  388.                         letezik = true;
  389.                         break;
  390.                     }
  391.                 }
  392.                 if (!letezik)
  393.                 {
  394.                     eredmeny = string.Join("\n", eredmenyLista);
  395.                     FTP.SaveFile(eredmeny, fajlnev, "stat");
  396.                 }
  397.                 else
  398.                 {
  399.                     string[] statfile = FTP.DownloadFile("stat", fajlnev);
  400.                     if (statfile[0] == eredmenyLista[0])
  401.                     {
  402.                         int szam = 0;
  403.  
  404.                         for (int i = 1; i < statfile.Length; i++)
  405.                         {
  406.                             if (eredmenyLista[i] == "--")
  407.                             {
  408.                                 i++;
  409.                                 continue;
  410.                             }
  411.                             else
  412.                             {
  413.                                 i++;
  414.                                 index = i;
  415.                                 szam = Convert.ToInt32(statfile[i]) + Convert.ToInt32(eredmenyLista[i]);
  416.                                 eredmenyLista[i] = szam.ToString();
  417.                             }
  418.                         }
  419.                         eredmeny = string.Join("\n", eredmenyLista);
  420.                         FTP.SaveFile(eredmeny, fajlnev, "stat");
  421.                     }
  422.                 }
  423.                 MessageBox.Show("Sikeres mentés!", "Juhé!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  424.             }
  425.             catch (Exception ex)
  426.             {
  427.                 MessageBox.Show(ex.Message + " -- INDEX IS " + index + "\n" + ex.ToString().Substring(ex.ToString().LastIndexOf(':') + 1));
  428.             }
  429.             finally
  430.             {
  431.                 this.Enabled = true;
  432.             }
  433.         }
  434.  
  435.         public bool MindenholVaneValasz()
  436.         {
  437.             int count;
  438.             foreach (var k in kerdoiv.kerdesLista)
  439.             {
  440.                 count = 0;
  441.                 if (!k.tobblehetoseg)
  442.                 {
  443.                     for (int i = 0; i < k.hanykerdes; i++)
  444.                     {
  445.                         if (!k.radios[i].Checked) count++;
  446.                     }
  447.                 }
  448.                 else
  449.                 {
  450.                     for (int i = 0; i < k.hanykerdes; i++)
  451.                     {
  452.                         if (!k.checks[i].Checked) count++;
  453.                     }
  454.                 }
  455.                 if (count == k.hanykerdes) return false;
  456.             }
  457.             return true;
  458.         }
  459.  
  460.         private void ValaszokMentese()
  461.         {
  462.             foreach (var k in kerdoiv.kerdesLista)
  463.             {
  464.                 if (!k.tobblehetoseg) // radio
  465.                 {
  466.                     for (int i = 0; i < k.radios.Length; i++)
  467.                     {
  468.                         if (k.radios[i] != null)
  469.                         {
  470.                             if (k.radios[i].Checked)
  471.                                 k.valasz = i;
  472.                         }
  473.                     }
  474.                 }
  475.                 else // checkbox
  476.                 {
  477.                     for (int i = 0; i < k.checks.Length; i++)
  478.                     {
  479.                         if (k.checks[i] != null)
  480.                         {
  481.                             if (k.checks[i].Checked) k.tobbvalasz[i] = true;
  482.                         }
  483.                     }
  484.                 }
  485.             }
  486.         }
  487.     }
  488. }
  489.  
  490.  
  491.  
  492. // FTP.cs:
  493.  
  494. using System.IO;
  495. using System.Net;
  496. using System.Text;
  497. using System.Threading.Tasks;
  498. using System;
  499. using System.Windows.Forms;
  500.  
  501. namespace KerdoivKitolto
  502. {
  503.     public static class FTP
  504.     {
  505.         static StreamReader reader;
  506.         static FtpWebResponse response;
  507.         public static int ID;
  508.         public static string IDContent;
  509.         static string dirContent;
  510.  
  511.         public static string[] GetDirectoryContent(string directory)
  512.         {
  513.             var request = (FtpWebRequest)WebRequest.Create
  514.     (Path.Combine("ftp://185.27.134.8/htdocs/data/", directory));
  515.             request.Credentials = new NetworkCredential("b11_13574135", "csaki123");
  516.             request.Method = WebRequestMethods.Ftp.ListDirectory;
  517.             response = (FtpWebResponse)request.GetResponse();
  518.             Stream responseStream = response.GetResponseStream();
  519.             reader = new StreamReader(responseStream);
  520.             dirContent = reader.ReadToEnd();
  521.             reader.Close();
  522.             response.Close();
  523.             return dirContent.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
  524.  
  525.         }
  526.  
  527.         public static void SaveFile(string Content, string Filename, string directory)
  528.         {
  529.             try
  530.             {
  531.                 Uri requestUri = new Uri(Path.Combine("ftp://185.27.134.8/htdocs/data/", directory, Filename));
  532.                 FtpWebRequest request = (FtpWebRequest)WebRequest.Create(requestUri);
  533.                 request.Credentials = new NetworkCredential("b11_13574135", "csaki123");
  534.                 request.KeepAlive = false;
  535.                 request.Method = "STOR";
  536.                 request.UseBinary = true;
  537.                 request.ContentLength = Content.Length;
  538.                 request.Proxy = null;
  539.                 using (Stream stream = request.GetRequestStream())
  540.                 {
  541.                     byte[] bytes = new UTF8Encoding().GetBytes(Content);
  542.                     //stream.Write(bytes, 0, bytes.Length);
  543.                     for (int i = 0; i < bytes.Length; i++)
  544.                     {
  545.                         stream.WriteByte(bytes[i]);
  546.                     }
  547.                 }
  548.                 request.GetResponse();
  549.             }
  550.             catch (Exception ex)
  551.             {
  552.                 MessageBox.Show("Hiba történt a fájl mentése során!\n\n" + ex.Message + '\n' + ex.ToString().Substring(ex.ToString().LastIndexOf(':') + 1), "Hiba", MessageBoxButtons.OK, MessageBoxIcon.Error);
  553.             }
  554.         }
  555.  
  556.         public static void SelectID()
  557.         {
  558.             CheckIDFileExists();
  559.             GetIDContent();
  560.  
  561.             if (IDContent == null) throw new FileNotFoundException();
  562.             if (IDContent == String.Empty || IDContent == "")
  563.             {
  564.                 ID = -1;
  565.             }
  566.             else
  567.             {
  568.                 string[] tmp = IDContent.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
  569.                 ID = Convert.ToInt32(tmp[tmp.Length - 1].Split('|')[0]);
  570.             }
  571.             ID++;
  572.         }
  573.  
  574.         public static void GetIDContent()
  575.         {
  576.             var request = (FtpWebRequest)WebRequest.Create
  577.     ("ftp://185.27.134.8/htdocs/data/ID/_ID.txt");
  578.             request.Credentials = new NetworkCredential("b11_13574135", "csaki123");
  579.             request.Method = WebRequestMethods.Ftp.DownloadFile;
  580.             response = (FtpWebResponse)request.GetResponse();
  581.             Stream responseStream = response.GetResponseStream();
  582.             reader = new StreamReader(responseStream);
  583.             IDContent = reader.ReadToEnd();
  584.         }
  585.  
  586.         public static bool CheckFileExists(string directory, string filenameWithExtension)
  587.         {
  588.             var request = (FtpWebRequest)WebRequest.Create(Path.Combine("ftp://185.27.134.8/htdocs/data/", directory, filenameWithExtension));
  589.             request.Credentials = new NetworkCredential("b11_13574135", "csaki123");
  590.             request.Method = WebRequestMethods.Ftp.GetDateTimestamp;
  591.  
  592.             try
  593.             {
  594.                 response = (FtpWebResponse)request.GetResponse();
  595.             }
  596.             catch (WebException ex)
  597.             {
  598.                 response = (FtpWebResponse)ex.Response;
  599.                 if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
  600.                 {
  601.                     return false;
  602.                 }
  603.             }
  604.             return true;
  605.         }
  606.  
  607.         public static void CheckIDFileExists()
  608.         {
  609.             if (!CheckFileExists("ID", "_ID.txt"))
  610.             {
  611.                 CreateIDFile();
  612.             }
  613.         }
  614.  
  615.         private static void CreateIDFile()
  616.         {
  617.             var request = (FtpWebRequest)WebRequest.Create
  618. ("ftp://185.27.134.8/htdocs/data/ID/_ID.txt");
  619.  
  620.             request.Credentials = new NetworkCredential("b11_13574135", "csaki123");
  621.             request.KeepAlive = false;
  622.             request.Method = "STOR";
  623.             request.UseBinary = true;
  624.             request.ContentLength = 0;
  625.             request.Proxy = null;
  626.             using (Stream stream = request.GetRequestStream())
  627.             {
  628.                 byte[] bytes = new UnicodeEncoding().GetBytes("");
  629.                 stream.Write(bytes, 0, bytes.Length);
  630.             }
  631.         }
  632.  
  633.         public static void CreateFile(string uri)
  634.         {
  635.             try
  636.             {
  637.  
  638.             }
  639.             catch (Exception ex)
  640.             {
  641.                 MessageBox.Show(ex.Message + '\n' + ex.ToString().Substring(ex.ToString().LastIndexOf(':') + 1));
  642.             }
  643.         }
  644.  
  645.         public static string[] DownloadFile(string directory, string filenameWithExtension)
  646.         {
  647.             var request = (FtpWebRequest)WebRequest.Create
  648.     (Path.Combine("ftp://185.27.134.8/htdocs/data/", directory, filenameWithExtension));
  649.             request.Credentials = new NetworkCredential("b11_13574135", "csaki123");
  650.             request.Method = WebRequestMethods.Ftp.DownloadFile;
  651.             response = (FtpWebResponse)request.GetResponse();
  652.             Stream responseStream = response.GetResponseStream();
  653.             reader = new StreamReader(responseStream);
  654.             string temp = reader.ReadToEnd();
  655.             return temp.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
  656.         }
  657.     }
  658. }
  659.  
  660.  
  661.  
  662. // Kerdes.cs:
  663.  
  664. using System;
  665. using System.Collections.Generic;
  666. using System.Linq;
  667. using System.Text;
  668. using System.Windows.Forms;
  669. using System.Threading.Tasks;
  670.  
  671. namespace KerdoivKitolto
  672. {
  673.     public class Kerdes
  674.     {
  675.         public string kerdes;
  676.         public string[] valaszok = new string[4];
  677.         public bool tobblehetoseg;
  678.         public int hanykerdes;
  679.         public int hanyadik;
  680.         public int valasz;
  681.         public bool[] tobbvalasz = new bool[4];
  682.  
  683.         public RadioButton[] radios = new RadioButton[4];
  684.         public CheckBox[] checks = new CheckBox[4];
  685.  
  686.         public Kerdes(string kerdes, string elso, string masodik, string harmadik, string negyedik, bool tobblehetoseg, int hanykerdes)
  687.         {
  688.             this.kerdes = kerdes;
  689.             this.valaszok[0] = elso;
  690.             this.valaszok[1] = masodik;
  691.             this.valaszok[2] = harmadik;
  692.             this.valaszok[3] = negyedik;
  693.             this.tobblehetoseg = tobblehetoseg;
  694.             this.hanykerdes = hanykerdes;
  695.         }
  696.  
  697.         public Kerdes()
  698.         {
  699.  
  700.         }
  701.     }
  702. }
  703.  
  704.  
  705.  
  706. // Kerdoiv.cs:
  707.  
  708. using System;
  709. using System.Collections.Generic;
  710. using System.Linq;
  711. using System.Text;
  712. using System.Threading.Tasks;
  713.  
  714. namespace KerdoivKitolto
  715. {
  716.     public struct Kerdoiv
  717.     {
  718.         public List<Kerdes> kerdesLista;
  719.         public string cim;
  720.     }
  721. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement