private void PopulateListView() { this.Buy_Items_List.Items.Clear(); this.Buy_Items_List.BeginUpdate(); using (MuhasebeEntities m_Context = new MuhasebeEntities()) { this.StockMovement.Nodes.All(delegate(StockMovementNode m_Node) { m_Node.Item = m_Context.Items.Where(q => q.ID == m_Node.ItemID).FirstOrDefault(); ListViewItem m_ViewItem = new ListViewItem(); m_ViewItem.Tag = m_Node.ItemID; m_ViewItem.Text = m_Node.Item.Product.Barcode; m_ViewItem.SubItems.Add(m_Node.Item.OrderCode); m_ViewItem.SubItems.Add(m_Node.Item.Product.Name); m_ViewItem.SubItems.Add(ItemHelper.GetFormattedAmount(m_Node.Item.Amount, m_Node.Item.UnitType.DecimalPlaces, m_Node.Item.UnitType.Abbreviation)); m_ViewItem.SubItems.Add(ItemHelper.GetFormattedAmount(m_Node.Amount, m_Node.Item.UnitType.DecimalPlaces, m_Node.Item.UnitType.Abbreviation)); m_ViewItem.SubItems.Add(ItemHelper.GetFormattedPrice(m_Node.BasePrice.Value)); m_ViewItem.SubItems.Add(ItemHelper.GetFormattedPrice(m_Node.BasePrice.Value * m_Node.Amount)); this.Buy_Items_List.Items.Add(m_ViewItem); return(true); }); decimal expectedSummary = this.StockMovement.Nodes.Sum(q => q.BasePrice.Value * q.Amount); this.SubTotal_Label.Text = ItemHelper.GetFormattedPrice(expectedSummary); decimal totalSummary = expectedSummary; if (this.StockMovement.Discount.HasValue) { if (totalSummary > this.StockMovement.Discount.Value) { totalSummary -= this.StockMovement.Discount.Value; } else { this.StockMovement.Discount = 0; this.Discount_Num.Value = 0; } } this.Total_Label.Text = ItemHelper.GetFormattedPrice(totalSummary); } this.Buy_Items_List.EndUpdate(); }
private void PopulateListView() { this.Edit_Offer_List.Items.Clear(); using (MuhasebeEntities m_Context = new MuhasebeEntities()) { this.Offer.Nodes.All(delegate(OfferNode m_Node) { m_Node.Item = m_Context.Items.Where(q => q.ID == m_Node.ItemID).FirstOrDefault(); m_Node.FinalPrice = m_Node.BasePrice * m_Node.Amount; ListViewItem m_Item = new ListViewItem(); m_Item.Tag = m_Node.ItemID; string imageResult = ""; if (!string.IsNullOrEmpty(m_Node.Item.LocalImagePath) && File.Exists(m_Node.Item.LocalImagePath)) { imageResult = "Var"; } else { imageResult = "Yok"; } m_Item.Text = imageResult; m_Item.SubItems.Add(m_Node.Item.Product.Barcode); m_Item.SubItems.Add(m_Node.Item.Product.Name); m_Item.SubItems.Add(ItemHelper.GetFormattedAmount(m_Node.Amount, m_Node.Item.UnitType.DecimalPlaces, m_Node.Item.UnitType.Abbreviation)); m_Item.SubItems.Add(ItemHelper.GetFormattedPrice(m_Node.BasePrice)); m_Item.SubItems.Add(ItemHelper.GetFormattedPrice(m_Node.FinalPrice)); m_Item.SubItems.Add(m_Node.Description); this.Edit_Offer_List.Items.Add(m_Item); return(true); }); } }
private void PopulateListView() { using (MuhasebeEntities m_Context = new MuhasebeEntities()) { this.Edit_Sale_List.Items.Clear(); var m_Nodes = this.Invoice.Nodes; decimal m_Subtotal = 0; decimal m_Tax = 0; decimal m_Total = 0; int i = 0; Color m_Shaded = Color.FromArgb(240, 240, 240); m_Nodes.All(delegate(InvoiceNode m_Node) { m_Node.Invoice = this.Invoice; m_Node.InvoiceID = this.Invoice.ID; if (m_Node.ItemID > 0) { m_Node.Item = m_Context.Items.Where(q => q.ID == m_Node.ItemID).FirstOrDefault(); } if (m_Node.Item != null || m_Node.ItemID < 0) { ListViewItem m_ViewItem = new ListViewItem(); m_ViewItem.Tag = m_Node.ItemID; if (m_Node.UseCustomPrice == null) { m_Node.UseCustomPrice = false; } m_ViewItem.Text = m_Node.Item != null ? m_Node.Item.Product.Barcode : "Kayıt Dışı"; if (m_Node.Item == null && m_Node.Description.Length > 0) { m_ViewItem.SubItems.Add(m_Node.Description); } else { m_ViewItem.SubItems.Add(m_Node.Item.Product.Name); } if (m_Node.Item != null) { m_ViewItem.SubItems.Add(ItemHelper.GetFormattedAmount(m_Node.Amount.Value, m_Node.Item.UnitType.DecimalPlaces, null)); } else { m_ViewItem.SubItems.Add(m_Node.Amount.Value.ToString()); } m_ViewItem.SubItems.Add(m_Node.Item != null ? m_Node.Item.UnitType.Name : "-"); m_ViewItem.SubItems.Add(string.Format("%{0}", m_Node.Item != null ? m_Node.Item.Tax.Value.ToString() : m_Node.Tax.Value.ToString())); decimal basePrice = 0.00m; decimal finalPrice = 0.00m; if (m_Node.Item != null && this.Invoice.PaymentTypeID.HasValue && this.Invoice.PaymentTypeID == 3 && m_Node.Item.TermedPrice.HasValue && m_Node.Item.TermedPrice.Value > m_Node.Item.FinalPrice && m_Node.UseCustomPrice == false && this.UseTermedPrice_Check.Checked ) { basePrice = m_Node.Item.TermedPrice.Value; finalPrice = basePrice * m_Node.Amount.Value; } else { if (m_Node.UseCustomPrice == false && m_Node.Item != null) { basePrice = m_Node.Item.FinalPrice.Value; finalPrice = basePrice * m_Node.Amount.Value; } else { basePrice = m_Node.BasePrice.Value; finalPrice = basePrice * m_Node.Amount.Value; } } m_ViewItem.SubItems.Add(ItemHelper.GetFormattedPrice(basePrice)); m_ViewItem.SubItems.Add(ItemHelper.GetFormattedPrice(finalPrice)); // format shit if (i++ % 2 == 1) { m_ViewItem.BackColor = m_Shaded; m_ViewItem.UseItemStyleForSubItems = true; } m_Subtotal += m_Node.Item != null ? m_Node.Item.BasePrice.Value * m_Node.Amount.Value : m_Node.BasePrice.Value * m_Node.Amount.Value; m_Tax += (finalPrice * ((decimal)m_Node.Tax.Value / 100)); m_Total += finalPrice; m_Node.BasePrice = basePrice; m_Node.FinalPrice = finalPrice; this.Edit_Sale_List.Items.Add(m_ViewItem); } return(true); }); if (this.Invoice.Discount.HasValue) { if (m_Total > this.Invoice.Discount.Value) { m_Total = m_Total - this.Invoice.Discount.Value; } else { this.Invoice.Discount = 0; this.Discount_Num.Value = 0; this.Discount_Label.Text = ItemHelper.GetFormattedPrice(this.Invoice.Discount.Value); } } this.Subtotal_Label.Text = string.Format("{0:0.00} TL", m_Subtotal); this.Tax_Label.Text = string.Format("{0:0.00} TL", m_Tax); this.Total_Label.Text = string.Format("{0:0.00} TL", m_Total); } }
private void seçiliİşlemleriPDFyeAktarToolStripMenuItem_Click(object sender, EventArgs e) { this.seçiliİşlemleriPDFyeAktarToolStripMenuItem.Enabled = false; this.BeginInvoke((MethodInvoker) delegate() { using (MuhasebeEntities m_Context = new MuhasebeEntities()) { List <AccountMovement> m_List = new List <AccountMovement>(); foreach (ListViewItem m_Item in this.Account_History_View.SelectedItems) { int m_MovementID = Convert.ToInt32(m_Item.Tag); AccountMovement m_Movement = m_Context.AccountMovements.Where(q => q.ID == m_MovementID).FirstOrDefault(); m_List.Add(m_Movement); } m_List = m_List.OrderBy(q => q.CreatedAt).ToList(); Account m_Account = m_List.FirstOrDefault().Account; AccountSummary m_Summary = m_Account.GetSummary(m_List); string m_Data = ""; string m_SummaryTemplate = "Yukarıdaki işlemler sonucunda firmamız <strong>{0}</strong>"; string m_BaseTemplate = "<tr class=\"movement\">" + "<td class=\"id\">{0}</td>" + "<td class=\"mtype\">{1}</td>" + "<td class=\"date\">{2}</td>" + "<td class=\"author\">{3}</td>" + "<td class=\"payment\">{4}</td>" + "<td class=\"desc\">{5}</td> " + "<td class=\"price\">{6}</td>" + "</tr>"; m_List.All(delegate(AccountMovement movement) { string m_Description = ""; if (movement.MovementTypeID != 3) // ürün tedariğinde yorum yok { if (movement.MovementTypeID == 1 && movement.PaymentTypeID != 3) // Vadeli satış değilse { Income m_Income = m_Context.Incomes.Where(q => q.InvoiceID == movement.ContractID).FirstOrDefault(); if (m_Income != null) { m_Description = m_Income.Description; } } else if (movement.MovementTypeID == 2) // Alacak tahsilatı, gelir { Income m_Income = m_Context.Incomes.Where(q => q.ID == movement.ContractID).FirstOrDefault(); if (m_Income != null) { m_Description = m_Income.Description; } } else if (movement.MovementTypeID == 4) // Borç ödemesi, gider { Expenditure m_Expenditure = m_Context.Expenditures.Where(q => q.ID == movement.ContractID).FirstOrDefault(); if (m_Expenditure != null) { m_Description = m_Expenditure.Description; } } } string m_Formatted = string.Format(m_BaseTemplate, movement.ID, movement.MovementType.Name, movement.CreatedAt.ToString("dd/MM/yyyy"), movement.Author.FullName, movement.PaymentType.Name, m_Description, ItemHelper.GetFormattedPrice(movement.Value)); m_Data += m_Formatted; if (movement.MovementTypeID == 1 || movement.MovementTypeID == 3) // satılan malları veya alınanları listeleyelim { string m_ExTemplate = "<tr>" + "<td colspan=\"7\">" + "<div class=\"columns sale\">" + "<div class=\"order-code col\">Sipariş Kodu</div>" + "<div class=\"name col\">Ürün Adı</div>" + "<div class=\"amount col\">Miktar</div>" + "<div class=\"base-price col\">Birim</div>" + "<div class=\"total-price col\">Toplam</div>" + "</div>" + "{0}" + "</td>" + "</tr>"; string m_ExItemTemplate = "<div class=\"item\">" + "<div class=\"order-code col\">{0}</div>" + "<div class=\"name col\">{1}</div>" + "<div class=\"amount col\">{2}</div>" + "<div class=\"base-price col\">{3}</div>" + "<div class=\"total-price col\">{4}</div>" + "</div>"; if (movement.MovementTypeID == 1) //Mal satışı { Invoice m_Invoice = m_Context.Invoices.Where(q => q.ID == movement.ContractID).FirstOrDefault(); if (m_Invoice != null) { string m_ExItemInfo = ""; m_Invoice.Nodes.All(delegate(InvoiceNode node) { string m_OrderCode = node.Item != null ? node.Item.OrderCode : "-"; string m_Name = node.Item != null ? node.Item.Product.Name : node.Description; string m_Amount = node.Item != null ? ItemHelper.GetFormattedAmount(node.Amount.Value, node.Item.UnitType.DecimalPlaces, node.Item.UnitType.Abbreviation) : ItemHelper.GetFormattedAmount(node.Amount.Value, 0, "Adet"); string m_Base = ItemHelper.GetFormattedPrice(node.BasePrice.Value); string m_Final = ItemHelper.GetFormattedPrice(node.FinalPrice.Value); m_ExItemInfo += string.Format(m_ExItemTemplate, m_OrderCode, m_Name, m_Amount, m_Base, m_Final); return(true); }); m_ExItemInfo = string.Format(m_ExTemplate, m_ExItemInfo); m_Data += m_ExItemInfo; } } else if (movement.MovementTypeID == 3) //Mal alımı { StockMovement m_Stock = m_Context.StockMovements.Where(q => q.ID == movement.ContractID).FirstOrDefault(); if (m_Stock != null) { string m_ExItemInfo = ""; m_Stock.Nodes.All(delegate(StockMovementNode node) { string m_OrderCode = node.Item.OrderCode; string m_Name = node.Item.Product.Name; string m_Amount = ItemHelper.GetFormattedAmount(node.Amount, node.Item.UnitType.DecimalPlaces, node.Item.UnitType.Abbreviation); string m_Base = ItemHelper.GetFormattedPrice(node.BasePrice.Value); string m_Final = ItemHelper.GetFormattedPrice(node.FinalPrice.Value); m_ExItemInfo += string.Format(m_ExItemTemplate, m_OrderCode, m_Name, m_Amount, m_Base, m_Final); return(true); }); m_ExItemInfo = string.Format(m_ExTemplate, m_ExItemInfo); m_Data += m_ExItemInfo; } } } return(true); }); if (m_Summary.Net < 0) { m_SummaryTemplate = string.Format(m_SummaryTemplate, string.Format("sizden {0} alacaklıdır.", ItemHelper.GetFormattedPrice(Math.Abs(m_Summary.Net)))); } else if (m_Summary.Net > 0) { m_SummaryTemplate = string.Format(m_SummaryTemplate, string.Format("size {0} borçludur.", ItemHelper.GetFormattedPrice(Math.Abs(m_Summary.Net)))); } else { this.Net_State_Label.Text = "Herhangi bir alacak/borç bulunmamaktadır."; } this.Save_Dialog.FileName = string.Format("{0} - İşlem Geçmişi.pdf", m_Account.Name); if (this.Save_Dialog.ShowDialog() == DialogResult.OK) { string m_SavePath = this.Save_Dialog.FileName; string html = ""; string m_LocalPath = Application.StartupPath; string m_IndexPath = Path.Combine(m_LocalPath, "View\\AccountMovementsForm\\index.html"); string m_AbsPath = Path.Combine(m_LocalPath, "View\\AccountMovementsForm\\"); using (StreamReader m_Reader = new StreamReader(m_IndexPath, Encoding.UTF8, true)) { html = m_Reader.ReadToEnd(); } html = html.Replace("{PATH}", m_AbsPath); html = html.Replace("{BASEPATH}", m_LocalPath); html = html.Replace("{COMPANY-NAME}", Program.User.WorksAt.Name); html = html.Replace("{TAXID}", Program.User.WorksAt.TaxID); html = html.Replace("{TAXPLACE}", Program.User.WorksAt.TaxDepartment); html = html.Replace("{ADDRESS}", Program.User.WorksAt.Address); html = html.Replace("{DISTRICT}", Program.User.WorksAt.District); html = html.Replace("{PROVINCE}", Program.User.WorksAt.Province); html = html.Replace("{TELEPHONE}", Program.User.WorksAt.Phone); html = html.Replace("{EMAIL}", Program.User.WorksAt.Email); html = html.Replace("{DATA}", m_Data); html = html.Replace("{SUMMARY}", m_SummaryTemplate); html = html.Replace("{ACCOUNT-NAME}", m_Account.Name); html = html.Replace("{ACCOUNT-TAXOFFICE", m_Account.TaxDepartment); html = html.Replace("{ACCOUNT-TAXID}", m_Account.TaxID); html = html.Replace("{ACCOUNT-ADDRESS}", m_Account.Address); html = html.Replace("{ACCOUNT-CITY}", m_Account.City.Name); html = html.Replace("{ACCOUNT-PROVINCE}", m_Account.Province.Name); html = html.Replace("{ACCOUNT-PHONE}", m_Account.Phone); html = html.Replace("{ACCOUNT-GSM}", m_Account.Gsm); html = html.Replace("{ACCOUNT-EMAIL}", m_Account.Email); try { var pdf = Pdf .From(html) .OfSize(PaperSize.A4) .WithTitle("Title") .WithMargins(0.8.Centimeters()) .WithoutOutline() .Portrait() .Comressed() .Content(); FileStream m_Stream = new FileStream(m_SavePath, FileMode.Create); using (BinaryWriter m_Writer = new BinaryWriter(m_Stream)) { m_Writer.Write(pdf, 0, pdf.Length); } m_Stream.Close(); m_Stream.Dispose(); MessageBox.Show("Pdf dosyası oluşturuldu.", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { Logger.Enqueue(ex); MessageBox.Show("Oluşan bir hata nedeniyle pdf dosyası yazılamadı. Lütfen tekrar deneyin.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }); this.seçiliİşlemleriPDFyeAktarToolStripMenuItem.Enabled = true; }
private void Export_Pdf_Button_Click(object sender, EventArgs e) { this.Export_Pdf_Button.Enabled = false; this.BeginInvoke((MethodInvoker) delegate() { using (MuhasebeEntities m_Context = new MuhasebeEntities()) { ListViewItem m_Item = this.Offers_List.SelectedItems[0]; int m_OfferID = Convert.ToInt32(m_Item.Tag); Offer m_Offer = m_Context.Offers.Where(q => q.ID == m_OfferID).FirstOrDefault(); this.Save_Dialog.FileName = string.Format("Teklif - {0}.pdf", m_OfferID); if (m_Offer != null && this.Save_Dialog.ShowDialog() == DialogResult.OK) { string m_SavePath = this.Save_Dialog.FileName; string html = ""; string m_LocalPath = Application.StartupPath; string m_IndexPath = Path.Combine(m_LocalPath, "View\\OfferForm\\index.html"); string m_AbsPath = Path.Combine(m_LocalPath, "View\\OfferForm\\"); using (StreamReader m_Reader = new StreamReader(m_IndexPath, Encoding.UTF8, true)) { html = m_Reader.ReadToEnd(); } html = html.Replace("{PATH}", m_AbsPath); html = html.Replace("{BASEPATH}", m_LocalPath); html = html.Replace("{COMPANY-NAME}", Program.User.WorksAt.Name); html = html.Replace("{TAXID}", Program.User.WorksAt.TaxID); html = html.Replace("{TAXPLACE}", Program.User.WorksAt.TaxDepartment); html = html.Replace("{ADDRESS}", Program.User.WorksAt.Address); html = html.Replace("{DISTRICT}", Program.User.WorksAt.District); html = html.Replace("{PROVINCE}", Program.User.WorksAt.Province); html = html.Replace("{TELEPHONE}", Program.User.WorksAt.Phone); html = html.Replace("{EMAIL}", Program.User.WorksAt.Email); html = html.Replace("{ATTN-NAME}", m_Offer.Account != null ? m_Offer.Account.Name : "Yetkili"); html = html.Replace("{AUTHOR-NAME}", Program.User.FullName); html = html.Replace("{AUTHOR-POSITION}", Program.User.Position.Name); html = html.Replace("{AUTHOR-EMAIL}", Program.User.Email); html = html.Replace("{AUTHOR-GSM}", Program.User.WorksAt.Gsm); html = html.Replace("{ORDER-ID}", m_Offer.ID.ToString()); html = html.Replace("{ATTN-NOTE}", m_Offer.Note); string m_Template = "<tr class=\"item\">" + "<td class=\"pro-img\"><img src=\"{0}\" /></td>" + "<td class=\"pro-code\">{1}</td>" + "<td class=\"pro-name\">{2}</td>" + "<td class=\"pro-quantity\">{3}</td>" + "<td class=\"pro-base\">{4}</td>" + "<td class=\"pro-total\">{5}</td>" + "<td class=\"pro-desc\">{6}</td>" + "</tr>"; string m_Data = ""; m_Offer.Nodes.All(delegate(OfferNode node) { if (node.Item == null) { return(true); } string m_ProImgPath = Path.Combine(m_LocalPath, node.Item.LocalImagePath); m_Data += string.Format(m_Template, File.Exists(m_ProImgPath) ? m_ProImgPath : "", node.Item.Product.Barcode, node.Item.Product.Name, ItemHelper.GetFormattedAmount(node.Amount, node.Item.UnitType.DecimalPlaces, node.Item.UnitType.Name), ItemHelper.GetFormattedPrice(node.BasePrice), ItemHelper.GetFormattedPrice(node.FinalPrice), node.Description); return(true); }); html = html.Replace("{DATA}", m_Data); try { var pdf = Pdf .From(html) .OfSize(PaperSize.A4) .WithTitle("Title") .WithMargins(0.8.Centimeters()) .WithoutOutline() .Portrait() .Comressed() .Content(); FileStream m_Stream = new FileStream(m_SavePath, FileMode.Create); using (BinaryWriter m_Writer = new BinaryWriter(m_Stream)) { m_Writer.Write(pdf, 0, pdf.Length); } m_Stream.Close(); m_Stream.Dispose(); MessageBox.Show("Pdf dosyası oluşturuldu.", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { Logger.Enqueue(ex); MessageBox.Show("Oluşan bir hata nedeniyle pdf dosyası yazılamadı. Lütfen tekrar deneyin.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }); this.Export_Pdf_Button.Enabled = true; }