Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length > 0)
            {
                przedmiot        = new towar();
                przedmiot.indeks = textBox1.Text;
                przedmiot.nazwa  = comboBox1.Text;
                przedmiot.uwagi  = textBox5.Text;

                if (textBox3.Text.Length == 0)
                {
                    przedmiot.netto  = 0;
                    przedmiot.brutto = 0;
                }
                else
                {
                    przedmiot.netto  = float.Parse(textBox3.Text);
                    przedmiot.netto  = Math.Round(przedmiot.netto, 2);
                    przedmiot.brutto = float.Parse(textBox4.Text);
                    przedmiot.brutto = Math.Round(przedmiot.brutto, 2);
                }

                przedmiot.stan = (uint)numericUpDown1.Value;

                towary.Add(przedmiot);

                System.Media.SystemSounds.Exclamation.Play();
                MessageBox.Show("Dodano towar do bazy.", "Powiadomienie", MessageBoxButtons.OK, MessageBoxIcon.Information);

                textBox1.Text        = "";
                comboBox1.Text       = "";
                textBox3.Text        = "";
                textBox4.Text        = "";
                textBox5.Text        = "";
                numericUpDown1.Value = 1;
            }
            else
            {
                System.Media.SystemSounds.Exclamation.Play();
                MessageBox.Show("Podaj indeks towaru.", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBox1.Select();
            }
        }
Exemple #2
0
        private void syncIC(DateTime from, DateTime to, bool isAuto = false)
        {
            int new_invoices = 0;
            int new_wares    = 0;

            try
            {
                if (settings.IC_number == "" || settings.IC_number == null)
                {
                    throw new Exception("Podaj numer klienta Inter Cars w ustawieniach.");
                }
                if (settings.IC_token == "" || settings.IC_token == null)
                {
                    throw new Exception("Podaj numer token uwierzytelniający Inter Cars w ustawieniach.");
                }

                SyncProgress sp = new SyncProgress();
                sp.setUpProgressBar((int)(to - from).TotalDays);
                sp.Show();

                foreach (DateTime startDate in ThreeMonths(from, to))
                {
                    DateTime toDate = startDate.AddMonths(3).AddDays(-1);
                    if (toDate > to)
                    {
                        toDate = to;
                    }
                    sp.setDates(startDate.ToShortDateString() + " - " + toDate.ToShortDateString());
                    var serverUrl = "https://katalog.intercars.com.pl/api/v2/External/GetInvoices?from=" + startDate.Year.ToString("0000") + startDate.Month.ToString("00") + startDate.Day.ToString("00") + "&to=" + toDate.Year.ToString("0000") + toDate.Month.ToString("00") + toDate.Day.ToString("00");
                    var client    = new System.Net.WebClient();
                    client.Headers["kh_kod"] = settings.IC_number;
                    client.Headers["token"]  = settings.IC_token;
                    string response = client.DownloadString(serverUrl);

                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(response);
                    XmlNodeList invoices = xmlDoc.GetElementsByTagName("nag");
                    foreach (XmlElement invoice in invoices)
                    {
                        string   id       = invoice.GetElementsByTagName("id")[0].InnerText;
                        string   number   = invoice.GetElementsByTagName("numer")[0].InnerText;
                        string   data     = invoice.GetElementsByTagName("dat_w")[0].InnerText;
                        DateTime inv_date = new DateTime(int.Parse(data.Substring(0, 4)), int.Parse(data.Substring(4, 2)), int.Parse(data.Substring(6, 2)));

                        sp.setProgress((int)(inv_date - from).TotalDays);

                        if (faktury.Exists(x => x.nr_faktury == number))
                        {
                            sp.appendLog("Faktura " + number + " już istnieje.");
                        }
                        else
                        {
                            faktura nowa_faktura = new faktura();
                            nowa_faktura.nr_faktury = number;
                            nowa_faktura.data       = inv_date;
                            nowa_faktura.dostawca   = "Inter Cars";

                            nowa_faktura.wartosc    = double.Parse(invoice.GetElementsByTagName("war_n")[0].InnerText, CultureInfo.InvariantCulture);
                            nowa_faktura.przedmioty = new List <rzecz>();

                            serverUrl = "https://katalog.intercars.com.pl/api/v2/External/GetInvoice?id=" + id;

                            client = new System.Net.WebClient();
                            client.Headers["kh_kod"] = settings.IC_number;
                            client.Headers["token"]  = settings.IC_token;
                            response = client.DownloadString(serverUrl);

                            XmlDocument xmlDoc2 = new XmlDocument();
                            xmlDoc2.LoadXml(response);
                            XmlNodeList wares = xmlDoc2.GetElementsByTagName("poz");

                            foreach (XmlElement item in wares)
                            {
                                string index = item.GetElementsByTagName("indeks")[0].InnerText;
                                if (!towary.Exists(x => x.indeks == index))
                                {
                                    towar nowy_towar = new towar();
                                    nowy_towar.indeks = index;
                                    nowy_towar.nazwa  = UTF8(item.GetElementsByTagName("nazwa")[0].InnerText);
                                    nowy_towar.uwagi  = UTF8(item.GetElementsByTagName("opis")[0].InnerText);
                                    towary.Add(nowy_towar);
                                    new_wares++;
                                    sp.appendLog("Dodano nowy towar " + index);
                                }
                                rzecz nowa_rzecz = new rzecz();
                                nowa_rzecz.indeks = index;
                                nowa_rzecz.ile    = int.Parse(item.GetElementsByTagName("ilosc")[0].InnerText);
                                nowa_rzecz.cena   = double.Parse(item.GetElementsByTagName("cena")[0].InnerText, CultureInfo.InvariantCulture);
                                nowa_faktura.przedmioty.Add(nowa_rzecz);
                            }
                            faktury.Add(nowa_faktura);
                            new_invoices++;
                            sp.appendLog("Dodano nową fakturę " + number);
                        }
                    }
                }
                sp.setProgress((int)(to - from).TotalDays);
                towary = towary.OrderBy(x => x.indeks).ToList();
                odswiezT();
                faktury = faktury.OrderBy(x => x.dostawca).ToList();
                odswiezF();
                if (IC_lastSync < to)
                {
                    IC_lastSync = to;
                }
                MessageBox.Show("Wczytano z API Inter Cars:\n\nNowe faktury: " + new_invoices + "\nNowe towary: " + new_wares, "Powiadomienie", MessageBoxButtons.OK, MessageBoxIcon.Information);
                sp.Close();
            }
            catch (Exception ex)
            {
                if (MessageBox.Show(ex.Message, "Błąd synchronizacji z Inter Cars", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                {
                    syncIC(from, to, isAuto);
                }
            }
        }