public void Create() { //daysTableAdapter.FillByMonth(tDayDataSet.Days, FirstDayOfMonth, LastDayOfMonth); if (!IsCreate()) { profilesTableAdapter.Fill(tDayDataSet.Profiles); foreach (DataRow _profile in tDayDataSet.Profiles) { if ((int)_profile["Category"] < (int)Enums.Category.BoardMember) { BillsItem Item = new BillsItem((int)_profile["ProfileId"], FirstDayOfMonth, LastDayOfMonth); Item.Insert(); } } //billsTableAdapter.DeleteByMonth(FirstDayOfMonth, LastDayOfMonth); //Удаляем все существующие записи за текущий месяц } }
public static void PrintBills(int ItemId) { try { if (File.Exists(System.Windows.Forms.Application.UserAppDataPath + @"\Bill_" + ItemId.ToString() + ".pdf")) { File.Delete(System.Windows.Forms.Application.UserAppDataPath + @"\Bill_" + ItemId.ToString() + ".pdf"); } } catch (IOException) { string Proc = GetFileProcessName("Bill_" + ItemId.ToString() + ".pdf"); if (File.Exists(System.Windows.Forms.Application.UserAppDataPath + @"\Bill_" + ItemId.ToString() + ".pdf")) { File.Delete(System.Windows.Forms.Application.UserAppDataPath + @"\Bill_" + ItemId.ToString() + ".pdf"); } } FileStream FS = new FileStream(System.Windows.Forms.Application.UserAppDataPath + @"\Bill_" + ItemId.ToString() + ".pdf", FileMode.CreateNew); var Doc = new iTextSharp.text.Document(PageSize.A4, 20, 20, 20, 20); PdfWriter.GetInstance(Doc, FS); Doc.Open(); BillsItem Item = new BillsItem(ItemId); PdfPTable table = new PdfPTable(5); table.WidthPercentage = 100; AddPriviewCell(table, TDay.Properties.Settings.Default.PlantString,5); AddPriviewCell(table, String.Format("For Services of {0:MMMM} - {0:yyyy}",Item.Date), 5); AddPriviewCell(table, Item.Profile.Name + "\n" + Item.Profile.Adress.Addres + "\n" + Item.Profile.Adress.City + "\n" + Item.Profile.Adress.PostalCode, 2,4, Element.ALIGN_LEFT); if (Item.PreviousBillPaid==0) { AddPriviewCell(table, "Balance Forward \nOverdue \nNew Charges", 1, 3, Element.ALIGN_LEFT); } else { AddPriviewCell(table, "Balance Forward \nPayments/Credits\nNew Charges", 1,3,Element.ALIGN_LEFT); } if (Item.PreviousBillPaid == 0) { AddPriviewCell(table, "", 1, 3, Element.ALIGN_CENTER); AddPriviewCell(table, Item.PreviousBillTotal.ToString() + "\n" + Item.PreviousBillTotal.ToString() + "\n" + Item.BillTotal.ToString(), 2, 3, Element.ALIGN_CENTER); } else { AddPriviewCell(table, Item.PreviousBillPaidDate.ToShortDateString(), 1, 3, Element.ALIGN_CENTER); AddPriviewCell(table, Item.PreviousBillTotal.ToString() + "\n" + Item.PreviousBillPaid.ToString() + "\n" + Item.BillTotal.ToString(), 2, 3, Element.ALIGN_CENTER); } AddPriviewCell(table, "Balance:", 2,1,Element.ALIGN_LEFT); AddPriviewCell(table, (Item.PreviousBillTotal-Item.PreviousBillPaid+Item.BillTotal).ToString(), 1, 2, Element.ALIGN_CENTER); Doc.Add(table); int TableColums = 0; TDayDataSet TempSet = new TDayDataSet(); TDayDataSetTableAdapters.DaysTableAdapter daysTableAdapter = new TDayDataSetTableAdapters.DaysTableAdapter(); daysTableAdapter.FillByMonth(TempSet.Days, Bill.GetFirstMonthDay(Item.Date), Bill.GetLastMonthDay(Item.Date)); double Misc = 0; double Trans = 0; double Program = 0; double TO = 0; double Lanch = 0; double Van = 0; double BFT = 0; foreach (DataRow Row in TempSet.Days) { if ((int)Row["ProfileId"] == Item.ProfileIdBills) { Misc += Double.Parse(Row["MiscellaneousPrice"].ToString()); Trans += Double.Parse(Row["RoundTripPrice"].ToString()); Program += Double.Parse(Row["ProgramPrice"].ToString()); TO += Double.Parse(Row["TakeOutPrice"].ToString()); Lanch += Double.Parse(Row["LunchPrice"].ToString()); Van += Double.Parse(Row["VanPrice"].ToString()); BFT += Double.Parse(Row["BookOfTickets"].ToString()); } } //Говнокод (((( но к сожалению вообще мозги ничего придумать не могут(((((((((( 3 дня - 2 часа сна........... if (Misc > 0) { TableColums++; } if (Trans > 0) { TableColums++; } if (Program > 0) { TableColums++; } if (TO > 0) { TableColums++; } if (Lanch > 0) { TableColums++; } if (Van > 0) { TableColums++; } if (BFT > 0) { TableColums++; } PdfPTable tablePart = new PdfPTable(TableColums+3); tablePart.WidthPercentage = 100; AddHeader(tablePart, " New Charges", 12, new BaseColor(Color.DimGray), new BaseColor(Color.WhiteSmoke)); AddPriviewCell(tablePart, "Date", 1, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke)); AddPriviewCell(tablePart, "Comments", 2, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke)); if (Lanch > 0) { AddPriviewCell(tablePart, "Lunch", 1, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke)); } if (TO > 0) { AddPriviewCell(tablePart, "TO", 1, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke)); } if (Misc > 0) { AddPriviewCell(tablePart, "Misc", 1, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke)); } if (Program > 0) { AddPriviewCell(tablePart, "Program", 1, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke)); } if (Van > 0) { AddPriviewCell(tablePart, "Van", 1, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke)); } if (Trans > 0) { AddPriviewCell(tablePart, "Trans", 1, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke)); } if (BFT > 0) { AddPriviewCell(tablePart, "BFT", 1, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke) ); } DataView DV = TempSet.Days.DefaultView; DV.Sort = "Date ASC"; BindingSource TemS = new BindingSource(); TemS.DataSource = DV; int ItemsCount = 0; foreach (DataRowView Row in TemS.List) { if ((int)Row["ProfileId"] == Item.ProfileIdBills) { AddPriviewCell(tablePart, ((DateTime)Row["Date"]).ToShortDateString(), 1, 1, Element.ALIGN_CENTER); AddPriviewCell(tablePart, Row["Comments"].ToString(), 2, 1, Element.ALIGN_CENTER); if (Lanch > 0) { AddPriviewCell(tablePart, Row["LunchPrice"].ToString(), 1, 1, Element.ALIGN_CENTER); } if (TO > 0) { AddPriviewCell(tablePart, Row["TakeOutPrice"].ToString(), 1, 1, Element.ALIGN_CENTER); } if (Misc > 0) { AddPriviewCell(tablePart, Row["MiscellaneousPrice"].ToString(), 1, 1, Element.ALIGN_CENTER); } if (Program > 0) { AddPriviewCell(tablePart, Row["ProgramPrice"].ToString(), 1, 1, Element.ALIGN_CENTER); } if (Van > 0) { AddPriviewCell(tablePart, Row["VanPrice"].ToString(), 1, 1, Element.ALIGN_CENTER); } if (Trans > 0) { AddPriviewCell(tablePart, Row["RoundTripPrice"].ToString(), 1, 1, Element.ALIGN_CENTER); } if (BFT > 0) { AddPriviewCell(tablePart, Row["BookOfTickets"].ToString(), 1, 1, Element.ALIGN_CENTER); } ItemsCount++; } } AddPriviewCell(tablePart, ItemsCount.ToString(), 1, 1, Element.ALIGN_CENTER); AddPriviewCell(tablePart, "", TableColums + 2, 1, Element.ALIGN_CENTER); AddPriviewCell(tablePart, "Totals:", 1, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke)); AddPriviewCell(tablePart, (Lanch + TO + Misc + Program + Van + Trans + BFT).ToString(), 2, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke)); if (Lanch > 0) { AddPriviewCell(tablePart, Lanch.ToString(), 1, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke)); } if (TO > 0) { AddPriviewCell(tablePart, TO.ToString(), 1, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke)); } if (Misc > 0) { AddPriviewCell(tablePart, Misc.ToString(), 1, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke)); } if (Program > 0) { AddPriviewCell(tablePart, Program.ToString(), 1, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke)); } if (Van > 0) { AddPriviewCell(tablePart, Van.ToString(), 1, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke)); } if (Trans > 0) { AddPriviewCell(tablePart, Trans.ToString(), 1, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke)); } if (BFT > 0){ AddPriviewCell(tablePart, BFT.ToString(), 1, 1, Element.ALIGN_CENTER, new BaseColor(Color.WhiteSmoke) );} AddEmpyRow(tablePart); AddEmpyRow(tablePart); AddEmpyRow(tablePart); Doc.Add(tablePart); PdfPTable tableFooster = new PdfPTable(6); tableFooster.WidthPercentage = 100; if (Item.Paid > 0) { PdfPCell pricell = new PdfPCell(new Phrase("Paid", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.NORMAL, new BaseColor(Color.DimGray)))); pricell.Border = iTextSharp.text.Rectangle.NO_BORDER; pricell.HorizontalAlignment = Element.ALIGN_RIGHT; pricell.VerticalAlignment = Element.ALIGN_MIDDLE; pricell.Colspan = 1; tableFooster.AddCell(pricell); pricell = new PdfPCell(new Phrase(Item.Paid.ToString()+"$", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.UNDERLINE, new BaseColor(Color.DimGray)))); pricell.Border = iTextSharp.text.Rectangle.NO_BORDER; pricell.HorizontalAlignment = Element.ALIGN_CENTER; pricell.VerticalAlignment = Element.ALIGN_MIDDLE; pricell.Colspan = 1; tableFooster.AddCell(pricell); pricell = new PdfPCell(new Phrase("Cash", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.NORMAL, new BaseColor(Color.DimGray)))); pricell.Border = iTextSharp.text.Rectangle.NO_BORDER; pricell.HorizontalAlignment = Element.ALIGN_RIGHT; pricell.VerticalAlignment = Element.ALIGN_MIDDLE; pricell.PaddingBottom = 3; pricell.Colspan = 1; tableFooster.AddCell(pricell); if (Item.PaidType == "cash") { AddValueCell(tableFooster, true, true, 1, false); } else { AddValueCell(tableFooster, false, true, 1, false); } pricell = new PdfPCell(new Phrase("Cheque", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.NORMAL, new BaseColor(Color.DimGray)))); pricell.Border = iTextSharp.text.Rectangle.NO_BORDER; pricell.HorizontalAlignment = Element.ALIGN_RIGHT; pricell.VerticalAlignment = Element.ALIGN_MIDDLE; pricell.PaddingBottom = 3; pricell.Colspan = 1; tableFooster.AddCell(pricell); if (Item.PaidType == "cheque") { AddValueCell(tableFooster, true, true, 1, false); } else { AddValueCell(tableFooster, false, true, 1, false); } } else { PdfPCell pricell = new PdfPCell(new Phrase("Paid", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.NORMAL, new BaseColor(Color.DimGray)))); pricell.Border = iTextSharp.text.Rectangle.NO_BORDER; pricell.HorizontalAlignment = Element.ALIGN_RIGHT; pricell.VerticalAlignment = Element.ALIGN_MIDDLE; pricell.Colspan = 1; tableFooster.AddCell(pricell); pricell = new PdfPCell(new Phrase("___________$", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.NORMAL, new BaseColor(Color.DimGray)))); pricell.Border = iTextSharp.text.Rectangle.NO_BORDER; pricell.HorizontalAlignment = Element.ALIGN_CENTER; pricell.Colspan = 1; tableFooster.AddCell(pricell); pricell = new PdfPCell(new Phrase("Cash", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.NORMAL, new BaseColor(Color.DimGray)))); pricell.Border = iTextSharp.text.Rectangle.NO_BORDER; pricell.HorizontalAlignment = Element.ALIGN_RIGHT; pricell.VerticalAlignment = Element.ALIGN_BOTTOM; pricell.PaddingBottom = 3; pricell.Colspan = 1; tableFooster.AddCell(pricell); AddValueCell(tableFooster, false, true, 1, false); pricell = new PdfPCell(new Phrase("Cheque", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.NORMAL, new BaseColor(Color.DimGray)))); pricell.Border = iTextSharp.text.Rectangle.NO_BORDER; pricell.HorizontalAlignment = Element.ALIGN_RIGHT; pricell.VerticalAlignment = Element.ALIGN_MIDDLE; pricell.PaddingBottom = 3; pricell.Colspan = 1; tableFooster.AddCell(pricell); AddValueCell(tableFooster, false, true, 1, false); } AddEmpyRow(tableFooster); AddEmpyRow(tableFooster); PdfPCell pricellnew = new PdfPCell(new Phrase("Date", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.NORMAL, new BaseColor(Color.DimGray)))); pricellnew.Border = iTextSharp.text.Rectangle.NO_BORDER; pricellnew.HorizontalAlignment = Element.ALIGN_RIGHT; pricellnew.VerticalAlignment = Element.ALIGN_MIDDLE; pricellnew.Colspan = 1; tableFooster.AddCell(pricellnew); if (Item.Paid > 0) { pricellnew = new PdfPCell(new Phrase(Item.PaidDate.ToShortDateString(), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.UNDERLINE, new BaseColor(Color.DimGray)))); pricellnew.Border = iTextSharp.text.Rectangle.NO_BORDER; pricellnew.HorizontalAlignment = Element.ALIGN_CENTER; pricellnew.VerticalAlignment = Element.ALIGN_MIDDLE; pricellnew.Colspan = 1; tableFooster.AddCell(pricellnew); } else { pricellnew = new PdfPCell(new Phrase("___________", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.NORMAL, new BaseColor(Color.DimGray)))); pricellnew.Border = iTextSharp.text.Rectangle.NO_BORDER; pricellnew.HorizontalAlignment = Element.ALIGN_CENTER; pricellnew.VerticalAlignment = Element.ALIGN_MIDDLE; pricellnew.Colspan = 1; tableFooster.AddCell(pricellnew); } pricellnew = new PdfPCell(new Phrase("Society Representative", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.NORMAL, new BaseColor(Color.DimGray)))); pricellnew.Border = iTextSharp.text.Rectangle.NO_BORDER; pricellnew.HorizontalAlignment = Element.ALIGN_CENTER; pricellnew.VerticalAlignment = Element.ALIGN_MIDDLE; pricellnew.Colspan = 2; tableFooster.AddCell(pricellnew); pricellnew = new PdfPCell(new Phrase("___________________________", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.NORMAL, new BaseColor(Color.DimGray)))); pricellnew.Border = iTextSharp.text.Rectangle.NO_BORDER; pricellnew.HorizontalAlignment = Element.ALIGN_CENTER; pricellnew.VerticalAlignment = Element.ALIGN_MIDDLE; pricellnew.Colspan = 2; tableFooster.AddCell(pricellnew); Doc.Add(tableFooster); Doc.Close(); Process.Start(System.Windows.Forms.Application.UserAppDataPath + @"\Bill_" + ItemId.ToString() + ".pdf"); }
private void button21_Click(object sender, EventArgs e) { if (dataGridView5.SelectedCells.Count > 0) { BillsItem Item = new BillsItem((int)dataGridView5.Rows[dataGridView5.SelectedCells[0].RowIndex].Cells["billIdDataGridViewTextBoxColumn"].Value); Decimal Paid = Decimal.Zero; Decimal.TryParse(textBox5.Text, out Paid); Item.Paid = Paid; Item.PaidDate = dateTimePicker1.Value; if (radioButton6.Checked) { Item.PaidType = "cash"; } if (radioButton7.Checked) { Item.PaidType = "cheque"; } Item.Update(); MessageBox.Show("Платёж сделан", "Ok", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void dataGridView5_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { BillsItem Item = new BillsItem((int)dataGridView5.Rows[e.RowIndex].Cells["billIdDataGridViewTextBoxColumn"].Value); richTextBox2.ResetText(); richTextBox2.AppendText(String.Format("INVOICE #{0}", dataGridView5.Rows[e.RowIndex].Cells["billIdDataGridViewTextBoxColumn"].Value.ToString())+"\n"); richTextBox2.AppendText(String.Format("For Services in {0:MMMM}", Item.Date)); richTextBox3.ResetText(); richTextBox3.AppendText(String.Format("{0} \n", Item.Profile.Name)); richTextBox3.AppendText(String.Format("{0} \n",Item.Profile.Adress.Addres)); richTextBox3.AppendText(String.Format("{0} \n", Item.Profile.Adress.City)); richTextBox3.AppendText(String.Format("{0} \n", Item.Profile.Adress.PostalCode)); if (Item.PreviousBillPaid==0) { label67.Text = "Overdue"; textBox2.Text = Item.PreviousBillTotal.ToString(); textBox6.Text = (Item.PreviousBillTotal + Item.BillTotal).ToString(); } else { label67.Text = "Payments/Credits"; textBox2.Text = Item.PreviousBillPaid.ToString(); textBox6.Text = (Item.PreviousBillTotal - Item.PreviousBillPaid + Item.BillTotal).ToString(); } if (Item.Paid > 0) { checkBox1.Checked = true; groupBox25.Enabled = true; switch (Item.PaidType) { case "cash": radioButton6.Checked = true; break; case "cheque": radioButton7.Checked = true; break; } textBox5.Text = Item.Paid.ToString(); dateTimePicker1.Value = Item.PaidDate; } else { checkBox1.Checked = false; groupBox25.Enabled = false; textBox5.Text = String.Empty; dateTimePicker1.Value = DateTime.Now.Date; } textBox1.Text = Item.PreviousBillTotal.ToString(); textBox3.Text = Item.BillTotal.ToString(); textBox4.Text = Item.PreviousBillPaidDate.ToShortDateString(); //daysBindingSource2.RemoveFilter(); daysBindingSource2.Filter = String.Format("ProfileId = {0}", Item.ProfileIdBills.ToString()); RecountTotals(); } }
private void toolStripButton12_Click(object sender, EventArgs e) { if (dataGridView7.SelectedCells.Count > 0) { TDayDataSet tempSet = new TDayDataSet(); Bill _Bill = new Bill(); billsTableAdapter.FillByMonth(tempSet.Bills, _Bill.FirstDayOfMonth, _Bill.LastDayOfMonth); int Index = -1; foreach (DataRow Row in tempSet.Bills) { if ((int)Row["ProfileId"] == (int)dataGridView7.Rows[dataGridView7.SelectedCells[0].RowIndex].Cells["dataGridViewTextBoxColumn1"].Value) { Index = (int)Row["BillId"]; break; } } if (Index != -1) { panel8.Visible = false; foreach (DataGridViewRow Row in dataGridView5.Rows) { if ((int)Row.Cells["billIdDataGridViewTextBoxColumn"].Value == Index) { DataGridViewCellEventArgs eve = new DataGridViewCellEventArgs(0, Row.Index); dataGridView5_CellClick(sender, eve); dataGridView5.Rows[Row.Index].Selected = true; break; } } } else { BillsItem item = new BillsItem((int)dataGridView7.Rows[dataGridView7.SelectedCells[0].RowIndex].Cells["dataGridViewTextBoxColumn1"].Value, _Bill.FirstDayOfMonth, _Bill.LastDayOfMonth); item.Insert(); billsTableAdapter.Fill(tDayDataSet.Bills); panel8.Visible = false; dataGridView7.Rows[dataGridView7.Rows.Count - 1].Selected = true; } } }