private void Copy2NyFakturaToolStripButton_Click(object sender, EventArgs e) { bool bVareforbrug = true; tblactebisfaktura recActebisfaktura = bsTblactebisfaktura.Current as tblactebisfaktura; if (recActebisfaktura.leveringsadresse.ToUpper().Contains("HAFSJOLD")) { DialogResult result = DotNetPerls.BetterDialog.ShowDialog( "Trans2Summa3060", //titleString " JA: Dette er en Hafsjold Data ApS anskaffelse.\nNEJ: Dette et vareforbrug.", //bigString null, //smallString "JA", //leftButton == OK "NEJ", //rightButton == Cancel global::Trans2Summa3060.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.tblactebisordres) { 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.tblwfaklins.Add(recWfaklin); } FrmMain frmMain = this.ParentForm as FrmMain; try { FrmNyfaktura frmNyfaktura = frmMain.GetChild("Ny faktura") as FrmNyfaktura; frmNyfaktura.AddNyActebisFaktura(recWfak); } catch { Program.dbDataTransSumma.tblwfaks.InsertOnSubmit(recWfak); Program.dbDataTransSumma.SubmitChanges(); } }
public void Open() { FileStream fs = new FileStream(m_kartotek_dat, FileMode.Open, FileAccess.Read, FileShare.None); IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(fs); excelReader.IsFirstRowAsColumnNames = false; tblwfak recwFak = new tblwfak { sk = "S", dato = DateTime.Today, konto = 100032, }; while (excelReader.Read()) { tblwfaklin recwfaklin = new tblwfaklin { varenr = "", tekst = excelReader.GetString(0), konto = 1000, momskode = "S25", antal = 1, enhed = "stk", pris = excelReader.GetDecimal(1), rabat = 0, moms = excelReader.GetDecimal(1) / 4, nettobelob = excelReader.GetDecimal(1), bruttobelob = excelReader.GetDecimal(1) + excelReader.GetDecimal(1) / 4, }; recwFak.tblwfaklins.Add(recwfaklin); } excelReader.Close(); Program.dbDataTransSumma.tblwfaks.InsertOnSubmit(recwFak); Program.dbDataTransSumma.SubmitChanges(); }
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; } } }
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)); } } }