예제 #1
0
        private void btnSacuvaj_Click(object sender, EventArgs e)
        {
            string tip = Tip == "KUF" ? "1" : "2";

            BrojSlogova = 0;

            // Slog zaglavlja http://www.new.uino.gov.ba/get/10399

            string zaglavlje = new SlogZaglavlje(
                "1",
                PDV,
                Period,
                tip,
                "01").ToCSV();

            var stavke = new StringBuilder();


            // Slogovi stavki
            try
            {
                foreach (DataGridViewRow row in dataGrid.Rows)
                {
                    // Null check
                    bool nullCheckFail = false;
                    foreach (DataGridViewCell cell in row.Cells)
                    {
                        if (cell.Value == null && cell.ColumnIndex != dataGrid.Columns["PDVbroj"].Index)
                        {
                            nullCheckFail = true;
                            break;
                        }
                    }

                    if (nullCheckFail)
                    {
                        continue;
                    }

                    if (Tip == "KUF")
                    {
                        stavke.AppendLine(new SlogNabavka(
                                              "2",
                                              Period,
                                              row.Cells["redniBroj"].Value.ToString().Remove(row.Cells["redniBroj"].Value.ToString().Length - 1), // Uklanjanje tacke
                                              "01",
                                              row.Cells["brojFakture"].Value.ToString(),
                                              row.Cells["datumFakture"].Value.ToString(),
                                              row.Cells["datumFakture"].Value.ToString(),
                                              row.Cells["nazivDobavljaca"].Value.ToString(),
                                              row.Cells["sjedisteDobavljaca"].Value.ToString(),
                                              String.IsNullOrEmpty(row.Cells["PDVbroj"].Value?.ToString()) ? null : row.Cells["PDVbroj"].Value.ToString(),
                                              row.Cells["iznosBezPDV"].Value.ToString(),
                                              row.Cells["iznosSaPDV"].Value.ToString(),
                                              row.Cells["iznosPDV"].Value.ToString()).ToCSV());
                    }
                    else
                    {
                        stavke.AppendLine(new SlogIsporuka(
                                              "2",
                                              Period,
                                              row.Cells["redniBroj"].Value.ToString().Remove(row.Cells["redniBroj"].Value.ToString().Length - 1), // Uklanjanje tacke
                                              "01",
                                              row.Cells["brojFakture"].Value.ToString(),
                                              row.Cells["datumFakture"].Value.ToString(),
                                              row.Cells["nazivDobavljaca"].Value.ToString(),
                                              row.Cells["sjedisteDobavljaca"].Value.ToString(),
                                              String.IsNullOrEmpty(row.Cells["PDVbroj"].Value?.ToString()) ? null : row.Cells["PDVbroj"].Value.ToString(),
                                              row.Cells["iznosSaPDV"].Value.ToString(),
                                              row.Cells["iznosBezPDV"].Value.ToString(),
                                              row.Cells["iznosPDV"].Value.ToString()).ToCSV());
                    }

                    BrojSlogova++;
                }
            }
            catch (Exception)
            {
                //MessageBox.Show(ex.Message);
            }

            string prateciSlog;

            if (Tip == "KUF")
            {
                prateciSlog = new SlogPrateci(
                    "3",
                    UkupnoBezPdv,
                    UkupnoSaPdv,
                    UkupnoPdv,
                    BrojSlogova.ToString()).ToCSV();
            }
            else
            {
                string osnovicaNeregistrovan;
                string pdvNeregistrovan;
                string osnovicaRegistrovan;
                string pdvRegistrovan;


                double sumaOsnovicaNeregistrovan = 0;
                double sumaPdvNeregistrovan      = 0;
                double sumaOsnovicaRegistrovan   = 0;
                double sumaPdvRegistrovan        = 0;

                foreach (DataGridViewRow row in dataGrid.Rows)
                {
                    try
                    {
                        if (String.IsNullOrEmpty((string)row.Cells["PDVbroj"].Value) && row.Cells[0] != null)     // Neregistrovan korisnik
                        {
                            if (row.Cells["iznosBezPDV"].Value != null)
                            {
                                sumaOsnovicaNeregistrovan += Double.Parse(row.Cells["iznosBezPDV"].Value.ToString());
                            }
                            if (row.Cells["iznosPDV"].Value != null)
                            {
                                sumaPdvNeregistrovan += Double.Parse(row.Cells["iznosPDV"].Value.ToString());
                            }
                        }
                        if (!String.IsNullOrEmpty((string)row.Cells["PDVbroj"].Value))
                        {
                            if (row.Cells["iznosBezPDV"].Value != null)
                            {
                                sumaOsnovicaRegistrovan += Double.Parse(row.Cells["iznosBezPDV"].Value.ToString());
                            }
                            if (row.Cells["iznosPDV"].Value != null)
                            {
                                sumaPdvRegistrovan += Double.Parse(row.Cells["iznosPDV"].Value.ToString());
                            }
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                osnovicaNeregistrovan = String.Format("{0:0.00}", sumaOsnovicaNeregistrovan);
                pdvNeregistrovan      = String.Format("{0:0.00}", sumaPdvNeregistrovan);
                osnovicaRegistrovan   = String.Format("{0:0.00}", sumaOsnovicaRegistrovan);
                pdvRegistrovan        = String.Format("{0:0.00}", sumaPdvRegistrovan);


                prateciSlog = new SlogPrateciIsporuka(
                    "3",
                    UkupnoSaPdv,
                    osnovicaRegistrovan,
                    pdvRegistrovan,
                    osnovicaNeregistrovan,
                    pdvNeregistrovan,
                    BrojSlogova.ToString()).ToCSV();
            }


            // Sacuvaj csv fajl
            Stream         myStream;
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter           = "CSV fajlovi (*.csv)|*.csv";
            saveFileDialog1.FilterIndex      = 1;
            saveFileDialog1.RestoreDirectory = true;
            saveFileDialog1.FileName         = $"{PDV}_{Period}_{(Tip == "KIF" ? "2" : "1")}_01.csv";

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = saveFileDialog1.OpenFile()) != null)
                {
                    StreamWriter streamWriter = new StreamWriter(myStream);

                    streamWriter.WriteLine(zaglavlje);
                    streamWriter.Write(stavke);
                    streamWriter.WriteLine(prateciSlog);
                    streamWriter.Flush();

                    myStream.Close();
                }
            }
        }
예제 #2
0
파일: Main.cs 프로젝트: gygasync/eKIFiKUF
        private void btnOtvori_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog()
            {
                Filter = "CSV fajlovi (*.csv)|*.csv",
                Title  = "Otvori CSV fal"
            };

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    var      filePath  = openFileDialog1.FileName;
                    string[] filelines = File.ReadAllLines(filePath);

                    if (filelines.Length > 1)
                    {
                        SlogZaglavlje zaglavlje = SlogZaglavlje.FromCSV(filelines[0]);


                        IList <string[]> polja = new List <string[]>();

                        for (int i = 1; i < filelines.Length - 1; i++)
                        {
                            string[] temp       = new string[9];
                            string[] poljaSplit = filelines[i].Split(';');

                            if (zaglavlje.TipDatoteke == "1") // KUF
                            {
                                temp[0] = poljaSplit[2] + ".";
                                temp[1] = poljaSplit[4];
                                temp[2] = poljaSplit[5];
                                temp[3] = poljaSplit[7];
                                temp[4] = poljaSplit[8];
                                temp[5] = poljaSplit[9];
                                temp[6] = poljaSplit[11];
                                temp[7] = poljaSplit[14];
                                temp[8] = poljaSplit[12];
                            }
                            else // KIF
                            {
                                temp[0] = poljaSplit[2] + ".";
                                temp[1] = poljaSplit[4];
                                temp[2] = poljaSplit[5];
                                temp[3] = poljaSplit[6];
                                temp[4] = poljaSplit[7];
                                temp[5] = poljaSplit[8];
                                temp[6] = String.IsNullOrEmpty(temp[5]) ? poljaSplit[16] : poljaSplit[14];
                                temp[7] = String.IsNullOrEmpty(temp[5]) ? poljaSplit[17] : poljaSplit[15];
                                temp[8] = poljaSplit[10];
                            }

                            polja.Add(temp);
                        }


                        DataForm dataForm = new DataForm(zaglavlje.PDVBroj, zaglavlje.PoreskiPeriod, zaglavlje.TipDatoteke == "2" ? "KIF" : "KUF", polja);
                        dataForm.Show();
                    }
                }
                catch (SecurityException ex)
                {
                    MessageBox.Show($"Security error.\n\nError message: {ex.Message}\n\n" +
                                    $"Details:\n\n{ex.StackTrace}");
                }
                catch (Exception exc)
                {
                    MessageBox.Show($"Fajl je neispravan\n {exc.Message}");
                }
            }
        }