Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (dost != comboBox2.Text || nrfak != textBox1.Text)
            {
                if (faktury.Exists(x => x.dostawca == comboBox2.Text && x.nr_faktury == textBox1.Text))
                {
                    System.Media.SystemSounds.Exclamation.Play();
                    MessageBox.Show("Faktura tego dostawcy o tym numerze istnieje już w bazie.", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    textBox1.Text = "";
                    textBox1.Select();
                }
                else
                {
                    faktura nowa = new faktura();
                    nowa.data       = dateTimePicker1.Value.Date;
                    nowa.dostawca   = comboBox2.Text;
                    nowa.nr_faktury = textBox1.Text;
                    nowa.wartosc    = wartosc;

                    nowa.przedmioty = new List <rzecz>();

                    foreach (ListViewItem item in listView1.Items)
                    {
                        rzecz p;
                        p.cena   = double.Parse(item.SubItems[2].Text);
                        p.ile    = int.Parse(item.SubItems[3].Text);
                        p.indeks = item.Text;
                        nowa.przedmioty.Add(p);
                    }
                    faktury[nr] = nowa;
                    this.Close();
                }
            }
            else
            {
                faktura nowa = new faktura();
                nowa.data       = dateTimePicker1.Value.Date;
                nowa.dostawca   = comboBox2.Text;
                nowa.nr_faktury = textBox1.Text;
                nowa.wartosc    = wartosc;

                nowa.przedmioty = new List <rzecz>();

                foreach (ListViewItem item in listView1.Items)
                {
                    rzecz p;
                    p.cena   = double.Parse(item.SubItems[2].Text);
                    p.ile    = int.Parse(item.SubItems[3].Text);
                    p.indeks = item.Text;
                    nowa.przedmioty.Add(p);
                }
                faktury[nr] = nowa;
                this.Close();
            }
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length == 0)
            {
                System.Media.SystemSounds.Exclamation.Play();
                MessageBox.Show("Podaj numer faktury!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBox1.Select();
                return;
            }

            if (faktury.Exists(x => x.dostawca == comboBox2.Text && x.nr_faktury == textBox1.Text))
            {
                System.Media.SystemSounds.Exclamation.Play();
                MessageBox.Show("Faktura tego dostawcy o tym numerze istnieje już w bazie.", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBox1.Text = "";
                textBox1.Select();
            }
            else
            {
                faktura nowa = new faktura();
                nowa.data       = dateTimePicker1.Value.Date;
                nowa.dostawca   = comboBox2.Text;
                nowa.nr_faktury = textBox1.Text;
                nowa.wartosc    = wartosc;

                nowa.przedmioty = new List <rzecz>();

                foreach (ListViewItem item in listView1.Items)
                {
                    rzecz p;
                    p.cena   = double.Parse(item.SubItems[2].Text);
                    p.ile    = int.Parse(item.SubItems[3].Text);
                    p.indeks = item.Text;
                    nowa.przedmioty.Add(p);

                    towary[towary.FindIndex(x => x.indeks == p.indeks)].ostatni = p.cena;
                }

                faktury.Add(nowa);

                listView1.Items.Clear();
                textBox1.Clear();
                wartosc       = 0;
                textBox3.Text = wartosc.ToString() + " zł";
                System.Media.SystemSounds.Exclamation.Play();
                MessageBox.Show("Dodano fakturę do bazy.", "Powiadomienie", MessageBoxButtons.OK, MessageBoxIcon.Information);
                textBox1.Select();
            }
        }
Exemple #3
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);
                }
            }
        }