Suivez et participez au développement du nouvel OpenCellar : PLOC.co
Page d'accueil
 
Français  English  
Open Cellar Home Edition - 1.2 - Le logiciel gratuit pour gérér efficacement votre cave à vins sous Windows. Open Cellar Mobile Edition - Beta 2 - La gestion de cave à vins a enfin sa solution Mobile sur Pocket PC. Open Cellar Cross Platform - Beta 1 - La gestion gratuite de vins disponible sous Mac OSX et Linux. Mon Open Cellar Les forums d'Open Cellar Place des vins
Rechercher : Bienvenue (se connecter - créer un compte)
Options de page

Nuage de tags
Livre de cave compacté (variante 2)
Le script suivant imprime le livre de cave compacté tout en effectuant de sous totaux et des regroupement par région
Pour l'éxécuter allez dans le menu "Préférences" -> "Editeurs de scripts"

// Auteur : dan768
// Date : Septembre 2007
if(App.ActiveCellar == null) 
{ 
return;
}
App.Animate(AnimationType.Work, true);
App.SetCursor(true);


//
// Modifiez ici le titre du report
//
string reportName = "Liste des vins - par région";

//
// Creation entete report
//
ReportTable rt = new ReportTable(reportName);

//
// Région
//
ReportColumn rcArea = rt.NewColumn("Région");
rcArea.Size = 110;

//
// Année
//
ReportColumn rcYear = rt.NewColumn("Année");
rcYear.Size = 40;
rcYear.ContentAlignment = ReportContentAlignment.Right;
rcYear.DataType = ReportColumnType.Numeric;

//
// Nom
//
ReportColumn rcName = rt.NewColumn("Nom");
rcName.Size = 225;

//
// Appellation
//
ReportColumn rcApp = rt.NewColumn("Appellation");
rcApp.Size = 140;


//
// Couleur
//
ReportColumn rcColor = rt.NewColumn("Couleur");
rcColor.Size = 60;

//
// Format
//
ReportColumn rcFormat = rt.NewColumn("Format");
rcFormat.Size = 70;

//
// Prix
//
//ReportColumn rcPrice = rt.NewColumn("Prix");
//rcPrice.Size = 50;
//rcPrice.ContentAlignment = ReportContentAlignment.Right;
//rcPrice.DataType = ReportColumnType.Numeric;

//
// Bouteilles
//
ReportColumn rcBottles = rt.NewColumn("Btles");
rcBottles.Size = 40;
rcBottles.ContentAlignment = ReportContentAlignment.Right;
rcBottles.DataType = ReportColumnType.Numeric;

//
// Prix
//
ReportColumn rcPrice = rt.NewColumn("Prix");
rcPrice.Size = 50;
rcPrice.ContentAlignment = ReportContentAlignment.Right;
rcPrice.DataType = ReportColumnType.Numeric;


//
// Total
//
ReportColumn rcAmount = rt.NewColumn("Total");
rcAmount.Size = 60;
rcAmount.ContentAlignment = ReportContentAlignment.Right;
rcAmount.DataType = ReportColumnType.Numeric;

// Colonne tri :: workaround
/*ReportColumn rcSort = rt.NewColumn("_");
rcSort.Size = 1;*/

//
// Alimentation de la source
//
ObjectCollection wines = App.ActiveCellar.GetCollection((ushort)ObjectType.Wine);

for (int i = 0; i < wines.Count; i++)
{
Wine wine = (Wine)wines[i];

ReportRow row = rt.NewRow();

row[0] = wine.Area.Name;
if(wine.Year != 0)
{
row[1] = wine.Year.ToString();
}
row[2] = wine.Name;
row[3] = wine.Appellation.Name;
row[4] = "Champ";

if(wine.WineColor == ColorType.Red)
{
row[4] = "Rouge"; 
}
else if(wine.WineColor == ColorType.White)
{
row[4] = "Blanc"; 
}
else if(wine.WineColor == ColorType.Rosy)
{
row[4] = "Rosé"; 
}
else if(wine.WineColor == ColorType.Yellow)
{
row[4] = "Champ"; 
}
else if(wine.WineColor == ColorType.LiqueurLike)
{
row[4] = "Liquoreux"; 
}
else if(wine.WineColor == ColorType.Misc)
{
row[4] = "Autre"; 
}

row[5] = wine.BottleType.Name; 

row[7] = wine.BuyPrice.ToString("f"); 


// 
// Gestion manuelle
//
if(wine.ManualManagement)
{
row[6] = wine.Bottles.ToString();
row[8] = (wine.Bottles * wine.BuyPrice).ToString("f");
}
else
{
row[6] = wine.RackItems.Count.ToString();
row[8] = (wine.RackItems.Count * wine.BuyPrice).ToString("f");
}

// row[9] = wine.Area.Name;

}

//
// Tri des elements, par region, vin puis année
//
rt.Sort("0-0;2-0;1-1");

/*
string lastArea = null;

for (int i = 0; i < rt.Rows.Count; i++)
{
ReportRow row = rt.Rows[i];
if(row[0] != lastArea)
{
lastArea = row[0];
}
else 
{
row[0] = string.Empty;
}
}
*/

// Second rapport

// Creation entete report
ReportTable rtEx = new ReportTable(reportName);

rcArea = rtEx.NewColumn("Région");
rcArea.Size = 110;

//
// Année
//
rcYear = rtEx.NewColumn("Année");
rcYear.Size = 40;
rcYear.ContentAlignment = ReportContentAlignment.Right;
rcYear.DataType = ReportColumnType.Numeric;

//
// Nom
//
rcName = rtEx.NewColumn("Nom");
rcName.Size = 225;

//
// Appellation
//
rcApp = rtEx.NewColumn("Appellation");
rcApp.Size = 140;


//
// Couleur
//
rcColor = rtEx.NewColumn("Couleur");
rcColor.Size = 60;

//
// Format
//
rcFormat = rtEx.NewColumn("Format");
rcFormat.Size = 70;

//
// Prix
//
rcPrice = rtEx.NewColumn("Btles");
rcPrice.Size = 40;
rcPrice.ContentAlignment = ReportContentAlignment.Right;
rcPrice.DataType = ReportColumnType.Numeric;

//
// Bouteilles
//
rcBottles = rtEx.NewColumn("Prix");
rcBottles.Size = 50;
rcBottles.ContentAlignment = ReportContentAlignment.Right;
rcBottles.DataType = ReportColumnType.Numeric;

//
// Total
//
rcAmount = rtEx.NewColumn("Total");
rcAmount.Size = 60;
rcAmount.ContentAlignment = ReportContentAlignment.Right;
rcAmount.DataType = ReportColumnType.Numeric;


float amount = 0;
float bottles = 0;

float tmpAmount = 0;
float tmpBottles = 0;

// :: OK
string lastArea = null;

for (int i = 0; i < rt.Rows.Count; i++)
{
ReportRow row = rt.Rows[i];

if(row[0] != lastArea)
{
if(lastArea != null)
{
// Cumul
ReportRow amountRow = rtEx.NewRow();
amountRow[2] ="Sous total "+lastArea+ " ----->";
amountRow[3] = "";
amountRow[5] = "Btles";
amountRow[6] = tmpBottles.ToString();
amountRow[7] = "Montant";
amountRow[8] = tmpAmount.ToString("f");
}

ReportRow areaRow = rtEx.NewRow();
areaRow[0] = row[0];
lastArea = row[0];
tmpBottles = 0;
tmpAmount = 0; 
}

ReportRow row2 = rtEx.NewRow();
row2[1] = row[1];
row2[2] = row[2];
row2[3] = row[3];
row2[4] = row[4];
row2[5] = row[5];
row2[6] = row[6];
row2[7] = row[7];
row2[8] = row[8];

amount+= Convert.ToSingle(row[8]);
bottles+= Convert.ToSingle(row[6]);

tmpAmount+= Convert.ToSingle(row[8]);
tmpBottles+= Convert.ToSingle(row[6]);
}

if(lastArea != null)
{
// Cumul
ReportRow amountRow = rtEx.NewRow();
amountRow[2] ="Sous total "+lastArea+ " ----->";
amountRow[3] = " ";
amountRow[5] = "Btles";
amountRow[6] = tmpBottles.ToString();
amountRow[7] = "Montant";
amountRow[8] = tmpAmount.ToString("f");
}

// Cumul total
rtEx.NewRow();

ReportRow amountRowEx = rtEx.NewRow();
amountRowEx[2] = "Total général";
amountRowEx[3] = "";
amountRowEx[5] = "Btles";
amountRowEx[6] = bottles.ToString();
amountRowEx[7] = "Montant";
amountRowEx[8] = amount.ToString("f");

//
// Génération
//
System.Collections.ArrayList list = new System.Collections.ArrayList();
list.Add(rtEx);

IReport report = App.ReportEngine.GetSystemReport(PredefinedReport.Grid);

string destFileName = App.Path + "Cache\\UserWinesGrid.pdf";
bool success = false;
try
{
report.Create(list, destFileName);
success = true;
}
catch(Exception ex)
{
MessageBox.Show("Erreur (1)");
}

//
// Affichage du report
//
if(success)
{
IShellWindow shellWindow = (IShellWindow)App.GetWindow(WindowType.Shell, null);
if(shellWindow != null)
{
shellWindow.Start(destFileName);
}
}

App.SetCursor(false);
App.StopAnimate();
© 2006-2014 Matthieu DUCROCQ Blog officiel d'Open Cellar - Tous droits réservés - Dernière mise à jour : janvier 2014 | twitter | facebook