Example #1
0
        private void setComboBoxHour(string electoralEampaignSave)
        {
            if (!System.IO.Directory.Exists(this.path + "\\Attendance"))
            {
                try
                {
                    System.IO.Directory.CreateDirectory(this.path + "\\Attendance");
                }
                catch (System.ArgumentNullException)
                {
                    MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"Attendance\"", "Error");
                }
                catch (System.ArgumentException)
                {
                    MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"Attendance\"", "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 \"Attendance\"", "Error");
                }
                catch (System.IO.DirectoryNotFoundException)
                {
                    MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"Attendance\"", "Error");
                }
                catch (System.NotSupportedException)
                {
                    MessageBox.Show("Nieprawidłowy format ścieżki. Nie można utworzyć katalogu \"Attendance\"", "Error");
                }
                catch (System.IO.IOException)
                {
                    MessageBox.Show("Nieprawidłowa ścieżka. Nie można utworzyć katalogu \"Attendance\"", "Error");
                }
            }
            string      uri  = "KALK/freq/" + electoralEampaignSave.Replace('_', '/') + "-freq";
            Connection  con  = new Connection();
            KLKresponse res  = con.getRequestKBWKlk(uri, this.path + "\\Attendance\\frekwencja.xml", 0);
            XmlDocument hour = new XmlDocument();

            hour.Load(this.path + "\\Attendance\\frekwencja.xml");
            XmlNode hourRoot = hour.SelectSingleNode("/frekwencja");

            System.Collections.ArrayList AttendanceTime = new System.Collections.ArrayList();
            AttendanceTime.Add(new AttendanceItem("0", ""));
            foreach (XmlNode item in hourRoot)
            {
                XmlNode id    = item.Attributes.GetNamedItem("id");
                XmlNode value = item.Attributes.GetNamedItem("value");
                if (id != null && value != null)
                {
                    AttendanceTime.Add(new AttendanceItem(id.Value, value.Value));
                }
            }
            this.attendanceHour.DataSource    = AttendanceTime;
            this.attendanceHour.DisplayMember = "LongName";
            this.attendanceHour.ValueMember   = "ShortName";
        }
Example #2
0
        public KLKresponse getRequestKBWKlkDocx(string uri, string savePath, int i)
        {
            int         bytesProcessed = 0;
            KLKresponse res            = new KLKresponse();
            KLKresponse result;

            if (i < this.servers2.Length)
            {
                System.Uri            target = new System.Uri(this.servers2[i] + uri);
                System.Net.WebRequest req    = System.Net.WebRequest.Create(target);
                req.Timeout         = this.timeout;
                req.Method          = "GET";
                req.PreAuthenticate = true;
                req.ContentType     = "application/x-www-form-urlencoded";
                try
                {
                    System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)req.GetResponse();
                    if (System.IO.File.Exists(savePath) && response != null && System.DateTime.Compare(System.IO.File.GetLastWriteTime(savePath), response.LastModified) >= 0)
                    {
                        response.Close();
                        res.setCode(new Code(0));
                        result = res;
                        return(result);
                    }
                    if (response != null)
                    {
                        System.IO.Stream receiveStream = response.GetResponseStream();
                        System.IO.Stream localStream   = System.IO.File.Create(savePath);
                        byte[]           buffer        = new byte[1024];
                        int bytesRead;
                        do
                        {
                            bytesRead = receiveStream.Read(buffer, 0, buffer.Length);
                            localStream.Write(buffer, 0, bytesRead);
                            bytesProcessed += bytesRead;
                        }while (bytesRead > 0);
                        response.Close();
                        localStream.Close();
                    }
                    else
                    {
                        this.getRequestKlk(uri, savePath, i++);
                    }
                }
                catch (System.Net.WebException)
                {
                    i++;
                    result = this.getRequestKBWKlk(uri, savePath, i);
                    return(result);
                }
                result = res;
            }
            else
            {
                result = res;
            }
            return(result);
        }
Example #3
0
        public KLKresponse getRequestKBWKlk(string uri, string savePath, int i)
        {
            KLKresponse res = new KLKresponse();
            KLKresponse result;

            if (i < this.servers2.Length)
            {
                System.Uri            target = new System.Uri(this.servers2[i] + uri);
                System.Net.WebRequest req    = System.Net.WebRequest.Create(target);
                req.Timeout         = this.timeout;
                req.Method          = "GET";
                req.PreAuthenticate = true;
                req.ContentType     = "application/x-www-form-urlencoded";
                try
                {
                    System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)req.GetResponse();
                    if (System.IO.File.Exists(savePath) && response != null && System.DateTime.Compare(System.IO.File.GetLastWriteTime(savePath), response.LastModified) >= 0)
                    {
                        response.Close();
                        res.setCode(new Code(0));
                        result = res;
                        return(result);
                    }
                    if (response != null)
                    {
                        System.IO.Stream       receiveStream = response.GetResponseStream();
                        System.Text.Encoding   encode        = System.Text.Encoding.GetEncoding("utf-8");
                        System.IO.StreamReader readStream    = new System.IO.StreamReader(receiveStream, encode);
                        string a    = "";
                        char[] read = new char[256];
                        for (int count = readStream.Read(read, 0, 256); count > 0; count = readStream.Read(read, 0, 256))
                        {
                            string str = new string(read, 0, count);
                            a += str;
                        }
                        response.Close();
                        readStream.Close();
                        res.setCode(new Code(0));
                        try
                        {
                            System.IO.StreamWriter sw = new System.IO.StreamWriter(savePath, false);
                            sw.Write(a);
                            sw.Close();
                            res.setSaved(true);
                        }
                        catch (System.Exception e)
                        {
                            res.setException(e);
                            result = res;
                            return(result);
                        }
                    }
                    else
                    {
                        this.getRequestKlk(uri, savePath, i++);
                    }
                }
                catch (System.Net.WebException)
                {
                    i++;
                    result = this.getRequestKBWKlk(uri, savePath, i);
                    return(result);
                }
                result = res;
            }
            else
            {
                result = res;
            }
            return(result);
        }