Ejemplo n.º 1
0
		FlowDocument FillFlowDocument(ref FlowDocument doc, Size pageSize)   // Per stampa
			{
			doc.ColumnWidth = doc.MaxPageWidth = pageSize.Width;
			doc.MaxPageHeight = pageSize.Height;

			Section[] sz = new Section[4];


			sz[0] = CreateSectionWithPageBreak();
			PrintTesto(ref sz[0], "OPERAZIONI");                              // Stampa le Operazioni (filtrate)
			Table tOp = new Table();
			Operazione opEmpty = new Operazione();
			TableRowGroup rgOp = new TableRowGroup();
			PrintTitoliTabella(ref tOp, ref rgOp, opEmpty);
			foreach (Operazione op in operazioni.operazioni)
				{
				PrintRigaTabella(ref tOp, ref rgOp, op);
				}
			tOp.RowGroups.Add(rgOp);
			sz[0].Blocks.Add(tOp);
			doc.Blocks.Add(sz[0]);
			
			sz[1] = CreateSectionWithPageBreak();
			PrintTesto(ref sz[1], "CONTI");                                   // Stampa i Conti
			Table tCn = new Table();
			Conto cnEmpty = new Conto();
			TableRowGroup rgCn = new TableRowGroup();
			PrintTitoliTabella(ref tCn, ref rgCn, cnEmpty);
			foreach (Conto cn in operazioni.conti)
				{
				PrintRigaTabella(ref tCn, ref rgCn, cn);
				}
			tCn.RowGroups.Add(rgCn);
			sz[1].Blocks.Add(tCn);
			doc.Blocks.Add(sz[1]);

			sz[2] = CreateSectionWithPageBreak();
			PrintTesto(ref sz[2], "OPERAZIONI STANDARD");                     // Stampa le Operazioni Standard
			Table tOs = new Table();
			OpStandard osEmpty = new OpStandard();
			TableRowGroup rgOs = new TableRowGroup();
			PrintTitoliTabella(ref tOs, ref rgOs, osEmpty);
			foreach (OpStandard os in operazioni.opStandard)
				{
				PrintRigaTabella(ref tOs, ref rgOs, os);
				}
			tOs.RowGroups.Add(rgOs);
			sz[2].Blocks.Add(tOs);
			doc.Blocks.Add(sz[2]);

			#region DA SCRIVERE

			sz[3] = CreateSectionWithPageBreak(true);
			foreach (Conto cnt in operazioni.Conti())
				{
				PrintTesto(ref sz[3], "CONSUNTIVO[" + cnt.numero.ToString() + "]: " + cnt.descrizione);
				List<Consuntivo> lc = operazioni.FindListaConsuntivi(cnt.numero);
				if (lc != null)
					{
					Table tCns = new Table();
					Consuntivo cnsEmpty = new Consuntivo();
					TableRowGroup rgCns = new TableRowGroup();
					PrintTitoliTabella(ref tCns, ref rgCns, cnsEmpty);
					foreach (Consuntivo cns in lc)
						{
						PrintRigaTabella(ref tCns, ref rgCns, cns);
						}
					tCns.RowGroups.Add(rgCns);
					sz[3].Blocks.Add(tCns);
					}
				else
					MessageBox.Show("Nessun consuntivo ["+cnt.numero.ToString()+"]");
				}
			doc.Blocks.Add(sz[3]);
#if false
			PrintPageBreak(ref doc);

			foreach (Conto cnt in operazioni.Conti())
				{
				PrintTesto(ref doc, "CONSUNTIVO[" + cnt.numero + "]: " + cnt.descrizione);

				List<Consuntivo> lc = operazioni.FindListaConsuntivi(cnt.numero);
				if(lc != null)
					{
					Consuntivo nouseCn = new Consuntivo();
					Table tCCn = new Table();
					int ncolCn = nouseCn.Count();
					for (int i = 0; i < ncolCn; i++)
						{
						TableColumn tc = new TableColumn();
						tc.Width = new GridLength(70, GridUnitType.Pixel);
						tCn.Columns.Add(tc);
						}
					var rgCn = new TableRowGroup();

					TableRow rowintCn = new TableRow();
					rowintCn.Background = Brushes.Transparent;
					rowintCn.FontSize = headerSize;
					rowintCn.FontWeight = FontWeights.Bold;
					foreach (string str in nouseCn.Titoli())
						{
						TableCell tc = new TableCell(new Paragraph(new Run(str)));
						tc.BorderBrush = Brushes.Black;
						tc.BorderThickness = new Thickness(0, 1, 0, 1);
						rowintC.Cells.Add(tc);
						}
					rgCn.Rows.Add(rowintCn);

					TableRow rowtypCn = new TableRow();
					rowtypCn.Background = Brushes.Transparent;
					rowtypCn.FontSize = headerSize;
					rowtypCn.FontWeight = FontWeights.Bold;

					rgCn.Rows.Add(rowtypCn);
					foreach (Consuntivo cons in lc)
						{
						TableRow row = new TableRow();
						row.Background = Brushes.Transparent;
						row.FontSize = textSize;
						row.FontWeight = FontWeights.Normal;
						foreach (string str in cons.Valori())
							{
							TableCell tc = new TableCell(new Paragraph(new Run(str)));
							tc.BorderBrush = Brushes.Black;
							tc.BorderThickness = new Thickness(0, 0, 0, 0.5);
							row.Cells.Add(tc);
							}
						rgC.Rows.Add(row);
						}
					tCn.RowGroups.Add(rgC);

					doc.Blocks.Add(tCn);
					}
				}
#endif
			#endregion


			return doc;
			}
Ejemplo n.º 2
0
		/// <summary>
		/// Genera le liste dei consuntivi
		/// </summary>
		/// <returns></returns>
		public bool GeneraConsuntivi()
			{
			bool ok = Check();
			try
				{
				if (ok)
					{
					// Crea il dizionario dei conti
					dicConsuntivi.Clear();
					try
						{
						foreach (Conto conto in conti)
							{
							int nc = conto.numero;
							if (nc > 0)
								dicConsuntivi.Add(nc, new List<Consuntivo>());
							}
						}
					catch
						{
						ok = false;
						lstErr.Add("Errore nella creazione della lista dei consuntivi");
						this.status = false;
						throw new Exception("Fallita generazione consuntivi");
						}
					// Ordina le operazioni
					List<Operazione> opOrdinata = OrdinaOperazioni();
					// Percorre le operazioni e le ricopia nei rispettivi consuntivi
					try
						{
						foreach (Operazione op in opOrdinata)       // Percorre le operazioni
							{
							foreach (int nc in op.Conti())          // Percorre i conti dell'operazione
								{
								int nca = Math.Abs(nc);             // Estrae il conto
								int ncs = Math.Sign(nc);
								// Crea nuova voce di consuntivo, copiando i dati dell'operazione
								Consuntivo cns = new Consuntivo(Riga.String2DateTime(op.data), op.descrizione, (op.importo) * ncs, op.tipo, 0, op.consuntivo, op.verificato,false);
								dicConsuntivi[nca].Add(cns);            // E la aggiunge alla lista del conto rispettivo
								}
							}
						}
					catch
						{
						ok = false;
						lstErr.Add("Errore nella generazione dei consuntivi");
						this.status = false;
						throw new Exception("Fallita generazione consuntivi");
						}
					// Calcola i totali dei consuntivi, percorrendo, per ogni conto, la lista dei consuntivi
					// foreach(List<Consuntivo> lcons in dicConsuntivi.Values)
					foreach(int nc_key in dicConsuntivi.Keys)
						{
						List<Consuntivo> lcons = dicConsuntivi[nc_key];
						decimal totale = 0;
						decimal x;

						Consuntivo.AlertConto alert = Consuntivo.AlertConto.Disattivo;
						Conto tmp = FindConto(nc_key);
						if (tmp != null)
							alert = tmp.alert;

						foreach (Consuntivo cons in lcons)
							{
							x = cons.importo;
							switch(cons.tipo)
								{
								case Riga.Tipo.A:       // Azzera e reimposta al valore
									totale = x;
									break;
								case Riga.Tipo.P:       // Somma o sottrae
									totale += x;
									break;
								case Riga.Tipo.N:		// Non fa nulla
									break;
								}
							cons.totale = totale;

							switch(alert)
								{
								case Consuntivo.AlertConto.Negativo:
									if (cons.totale < 0)
										cons.err = true;
									break;
								case Consuntivo.AlertConto.Positivo:
									if (cons.totale > 0)
										cons.err = true;
									break;
								default:
									break;
								}
							}
						}
					}
				}
			catch(Exception e)
				{
				ok = false;
				lstErr.Add(e.Message);
				this.status = false;
				}
			return ok;
			}	
Ejemplo n.º 3
0
		public override bool FromString(string str)
			{
			bool ok = false;
			bool[] conv = new bool[CAMPI];
			for (int i = 0; i < conv.Length; i++) conv[i] = true;
			string[] cmp = str.ToString().Split(new char[] { Separatore.field });
			if (cmp.Length == CAMPI)
				{
				Consuntivo tmp = new Consuntivo();
				tmp.data = cmp[0];
				tmp.descrizione = cmp[1];
				tmp.importo = Consuntivo.String2DecimalOrZero(cmp[2], out conv[2]);
				tmp.consuntivo = ((cmp[3] == Consuntivo.strTrue.ToString()) ? true : false);
				tmp.verificato = ((cmp[4] == Consuntivo.strTrue.ToString()) ? true : false);
				foreach (Consuntivo.Tipo tp in Enum.GetValues(typeof(Consuntivo.Tipo)))
					{
					if (cmp[5] == tp.ToString())
						{
						tmp.tipo = tp;
						conv[5] = true;
						break;
						}
					conv[5] = false;
					}
				tmp.totale = Consuntivo.String2DecimalOrZero(cmp[6], out conv[6]);
				tmp.err = ((cmp[7] == Consuntivo.strTrue.ToString()) ? true : false);
				ok = true;
				if (Array.Exists(conv, el => el == false))
					{
					ok = false;
					}
				if (ok)
					{
					this.data = tmp.data;
					this.descrizione = tmp.descrizione;
					this.importo = tmp.importo;
					this.consuntivo = tmp.consuntivo;
					this.verificato = tmp.verificato;
					this.tipo = tmp.tipo;
					this.totale = tmp.totale;
					this.err = tmp.err;
					}
				}
			return ok;
			}