private void Copy2NyFakturaToolStripButton_Click(object sender, EventArgs e)
        {
            bool bVareforbrug = true;
            Tblactebisfaktura recActebisfaktura = tblactebisfakturaBindingSource.Current as Tblactebisfaktura;

            if (recActebisfaktura.Leveringsadresse.ToUpper().Contains("HAFSJOLD"))
            {
                DialogResult result = DotNetPerls.BetterDialog.ShowDialog(
                    "TransSumma",                                                                  //titleString
                    " JA: Dette er en Hafsjold Data ApS anskaffelse.\nNEJ: Dette et vareforbrug.", //bigString
                    null,                                                                          //smallString
                    "JA",                                                                          //leftButton == OK
                    "NEJ",                                                                         //rightButton == Cancel
                    global::nsPuls3060.Properties.Resources.Message_info);                         //iconSet

                if (result == DialogResult.OK)
                {
                    bVareforbrug = false;
                }
            }
            Tblwfak recWfak = new Tblwfak
            {
                Sk               = "K",
                Dato             = recActebisfaktura.Ordredato,
                Konto            = 200064,
                Kreditorbilagsnr = recActebisfaktura.Fakturanr
            };

            foreach (Tblactebisordre recActebisordre in recActebisfaktura.Tblactebisordre)
            {
                Tblwfaklin recWfaklin = new Tblwfaklin
                {
                    Antal      = recActebisordre.Antal,
                    Enhed      = "stk",
                    Pris       = recActebisordre.Stkpris,
                    Varenr     = recActebisordre.Varenr.ToString(),
                    Nettobelob = recActebisordre.Antal * recActebisordre.Stkpris,
                    Tekst      = getVaretekst(recActebisfaktura, recActebisordre, bVareforbrug),
                    Konto      = getVarenrKonto(recActebisordre.Varenr, bVareforbrug),
                    Momskode   = KarKontoplan.getMomskode(getVarenrKonto(recActebisordre.Varenr, bVareforbrug))
                };
                recWfak.Tblwfaklin.Add(recWfaklin);
            }

            FrmMain frmMain = this.ParentForm as FrmMain;

            try
            {
                FrmNyfaktura frmNyfaktura = frmMain.GetChild("Ny faktura") as FrmNyfaktura;
                frmNyfaktura.AddNyActebisFaktura(recWfak);
            }
            catch
            {
                Program.dbDataTransSumma.Tblwfak.InsertOnSubmit(recWfak);
                Program.dbDataTransSumma.SubmitChanges();
            }
        }
Exemple #2
0
        private void pasteCsv(IDataObject dataObject)
        {
            object lDataObjectGetData = dataObject.GetData(DataFormats.CommaSeparatedValue);
            string csv = lDataObjectGetData as string;

            if (csv == null)
            {
                System.IO.MemoryStream stream = lDataObjectGetData as System.IO.MemoryStream;
                if (stream != null)
                {
                    csv = new System.IO.StreamReader(stream).ReadToEnd();
                }
            }
            if (csv == null)
            {
                return;
            }

            Regex regexCommaCvs     = new Regex(@"""(.*?)"",|([^,]*),|(.*)$");
            Regex regexSimicolonCvs = new Regex(@"""(.*?)"";|([^;]*);|(.*)$");

            string[] sep        = { "\r\n", "\n" };
            string[] lines      = csv.TrimEnd('\0').Split(sep, StringSplitOptions.RemoveEmptyEntries);
            int      row        = tblwfaklinDataGridView.NewRowIndex;
            Tblwfak  recWfak    = (Tblwfak)tblwfakBindingSource.Current;
            String   TargetType = recWfak.Sk;

            foreach (string line in lines)
            {
                if (line.Length > 0)
                {
                    try
                    {
                        int      i     = 0;
                        int      iMax  = 12;
                        string[] value = new string[iMax];
                        foreach (Match m in regexCommaCvs.Matches(line + ",,"))
                        {
                            for (int j = 1; j <= 3; j++)
                            {
                                if (m.Groups[j].Success)
                                {
                                    if (i < iMax)
                                    {
                                        value[i++] = m.Groups[j].ToString();
                                        break;
                                    }
                                }
                            }
                        }

                        if (value[3] == null) //konto
                        {
                            i     = 0;
                            value = new string[iMax];
                            foreach (Match m in regexSimicolonCvs.Matches(line + ";;"))
                            {
                                for (int j = 1; j <= 3; j++)
                                {
                                    if (m.Groups[j].Success)
                                    {
                                        if (i < iMax)
                                        {
                                            value[i++] = m.Groups[j].ToString();
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        if (value[3] != null) //konto
                        {
                            Tblwfaklin recWfaklin;
                            decimal?   Omkostbelob;
                            if (Program.karRegnskab.MomsPeriode() == 2)
                            {
                                recWfaklin = new Tblwfaklin
                                {
                                    Varenr      = value[1],
                                    Tekst       = value[2],
                                    Konto       = Microsoft.VisualBasic.Information.IsNumeric(value[3]) ? int.Parse(value[3]) : (int?)null,
                                    Momskode    = "",
                                    Antal       = Microsoft.VisualBasic.Information.IsNumeric(value[4]) ? decimal.Parse(value[4]) : (decimal?)null,
                                    Enhed       = value[5],
                                    Pris        = Microsoft.VisualBasic.Information.IsNumeric(value[6]) ? decimal.Parse(value[6]) : (decimal?)null,
                                    Moms        = 0,
                                    Nettobelob  = Microsoft.VisualBasic.Information.IsNumeric(value[7]) ? decimal.Parse(value[7]) : (decimal?)null,
                                    Bruttobelob = Microsoft.VisualBasic.Information.IsNumeric(value[7]) ? decimal.Parse(value[7]) : (decimal?)null,
                                };
                                Omkostbelob = Microsoft.VisualBasic.Information.IsNumeric(value[8]) ? decimal.Parse(value[8]) : (decimal?)null;
                                if ((TargetType == "S") && (Omkostbelob != null))
                                {
                                    recWfaklin.Konto = getVaresalgsKonto(recWfaklin.Konto);
                                    decimal momspct = KarMoms.getMomspct(recWfaklin.Momskode) / 100;
                                    recWfaklin.Pris       += decimal.Round((decimal)(Omkostbelob / recWfaklin.Antal), 2);
                                    recWfaklin.Nettobelob  = decimal.Round((decimal)(recWfaklin.Pris * recWfaklin.Antal), 2);
                                    recWfaklin.Moms        = decimal.Round((decimal)(recWfaklin.Nettobelob * momspct), 2);
                                    recWfaklin.Bruttobelob = decimal.Round((decimal)(recWfaklin.Nettobelob + recWfaklin.Moms), 2);
                                }
                            }
                            else
                            {
                                recWfaklin = new Tblwfaklin
                                {
                                    Varenr      = value[1],
                                    Tekst       = value[2],
                                    Konto       = Microsoft.VisualBasic.Information.IsNumeric(value[3]) ? int.Parse(value[3]) : (int?)null,
                                    Momskode    = value[4],
                                    Antal       = Microsoft.VisualBasic.Information.IsNumeric(value[5]) ? decimal.Parse(value[5]) : (decimal?)null,
                                    Enhed       = value[6],
                                    Pris        = Microsoft.VisualBasic.Information.IsNumeric(value[7]) ? decimal.Parse(value[7]) : (decimal?)null,
                                    Moms        = Microsoft.VisualBasic.Information.IsNumeric(value[8]) ? decimal.Parse(value[8]) : (decimal?)null,
                                    Nettobelob  = Microsoft.VisualBasic.Information.IsNumeric(value[9]) ? decimal.Parse(value[9]) : (decimal?)null,
                                    Bruttobelob = Microsoft.VisualBasic.Information.IsNumeric(value[10]) ? decimal.Parse(value[10]) : (decimal?)null
                                };
                                Omkostbelob = Microsoft.VisualBasic.Information.IsNumeric(value[11]) ? decimal.Parse(value[11]) : (decimal?)null;
                                if ((TargetType == "S") && (Omkostbelob != null))
                                {
                                    recWfaklin.Konto    = getVaresalgsKonto(recWfaklin.Konto);
                                    recWfaklin.Momskode = "S25";
                                    decimal momspct = KarMoms.getMomspct(recWfaklin.Momskode) / 100;
                                    recWfaklin.Pris       += decimal.Round((decimal)(Omkostbelob / recWfaklin.Antal), 2);
                                    recWfaklin.Nettobelob  = decimal.Round((decimal)(recWfaklin.Pris * recWfaklin.Antal), 2);
                                    recWfaklin.Moms        = decimal.Round((decimal)(recWfaklin.Nettobelob * momspct), 2);
                                    recWfaklin.Bruttobelob = decimal.Round((decimal)(recWfaklin.Nettobelob + recWfaklin.Moms), 2);
                                }
                            }

                            tblwfaklinBindingSource.Insert(row, recWfaklin);
                        }
                        row++;
                    }
                    catch (FormatException)
                    {    //TODO: log exceptions using a nice standard logging library
                        tblwfaklinDataGridView.CancelEdit();
                    }
                }
                else
                {
                    break;
                }
            }
        }
Exemple #3
0
 private void tblwfaklinDataGridView1_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == System.Windows.Forms.MouseButtons.Right)
     {
         DataGridView.HitTestInfo hit = tblwfaklinDataGridView.HitTest(e.X, e.Y);
         int hitcol = hit.ColumnIndex;
         if (hit.Type == DataGridViewHitTestType.Cell && hit.ColumnIndex == 2)
         {
             tblwfaklinDataGridView.ClearSelection();
             DataGridViewCell cellVarenr = tblwfaklinDataGridView.Rows[hit.RowIndex].Cells[hit.ColumnIndex];
             cellVarenr.Selected = true;
             Point       startPoint    = tblwfaklinDataGridView.PointToScreen(new Point(e.X, e.Y));
             FrmVareList m_frmVareList = new FrmVareList(startPoint);
             m_frmVareList.ShowDialog();
             int?selectedVarenr = m_frmVareList.SelectedVarenr;
             m_frmVareList.Close();
             if (selectedVarenr != null)
             {
                 Tblwfak    recWfak    = tblwfakBindingSource.Current as Tblwfak;
                 Tblwfaklin recWfaklin = ((DataGridView)sender).Rows[hit.RowIndex].DataBoundItem as Tblwfaklin;
                 if (recWfaklin != null)
                 {
                     try
                     {
                         recVarer rec = (from k in Program.karVarer where k.Varenr == selectedVarenr select k).First();
                         recWfaklin.Varenr = rec.Varenr.ToString();
                         recWfaklin.Tekst  = rec.Varenavn;
                         recWfaklin.Enhed  = rec.Enhed;
                         if (recWfak.Sk == "S")
                         {
                             recWfaklin.Konto    = rec.Salgskonto;
                             recWfaklin.Momskode = KarKontoplan.getMomskode(rec.Salgskonto);
                             recWfaklin.Pris     = rec.Salgspris;
                         }
                         if (recWfak.Sk == "K")
                         {
                             recWfaklin.Konto    = rec.Kobskonto;
                             recWfaklin.Momskode = KarKontoplan.getMomskode(rec.Kobskonto);
                             recWfaklin.Pris     = rec.Kobspris;
                         }
                     }
                     catch {}
                 }
             }
         }
         else if (hit.Type == DataGridViewHitTestType.Cell && hit.ColumnIndex == 4)
         {
             tblwfaklinDataGridView.ClearSelection();
             tblwfaklinDataGridView.Rows[hit.RowIndex].Cells[hit.ColumnIndex].Selected = true;
             Point            startPoint         = tblwfaklinDataGridView.PointToScreen(new Point(e.X, e.Y));
             FrmKontoplanList m_frmKontoplanList = new FrmKontoplanList(startPoint, KontoType.Drift | KontoType.Status);
             m_frmKontoplanList.ShowDialog();
             int?   selectedKontonr  = m_frmKontoplanList.SelectedKontonr;
             string selectedMomskode = m_frmKontoplanList.SelectedMomskode;
             m_frmKontoplanList.Close();
             if (selectedKontonr != null)
             {
                 Tblwfaklin recWfaklin = ((DataGridView)sender).Rows[hit.RowIndex].DataBoundItem as Tblwfaklin;
                 if (recWfaklin != null)
                 {
                     recWfaklin.Konto    = selectedKontonr;
                     recWfaklin.Momskode = selectedMomskode;
                 }
             }
         }
         else if (hit.Type == DataGridViewHitTestType.RowHeader)
         {
             this.contextMenuLineCopyPaste.Show(this.tblwfaklinDataGridView, new Point(e.X, e.Y));
         }
     }
 }