1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
| using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
//ATTENTION, LA DONNEE ID_EMPLOYE EST UTILISEE DANS CETTE PAGE, IL FAUDRA LA METTRE A JOUR QUAND LES ID_EMPLOYES SERONT GERES
public partial class Ecrans_Gestion_de_la_boutique_ActionsAnimal : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void FormViewAnimal_DataBound(object sender, EventArgs e)
{
//******************************************************************************************************
//Initialisation du Gridview de la liste des prestations en fonction des données de l'énimal sélectionné
if (((System.Data.DataRowView)FormViewAnimal.DataItem) != null)
{
//**************************************************************************************************
//Selection du dataitem contenu dans le formview
Gestion.T_ANIMALRow _animal = (Gestion.T_ANIMALRow)((System.Data.DataRowView)FormViewAnimal.DataItem).Row;
//**************************************************************************************************
//Initialisation du GridView GridViewListePrestation en fonction des paramètres de l'animal sélectionné
ODS_ListeTarifsPrestations.SelectParameters[0].DefaultValue = Convert.ToString(_animal.ID_LONGUEUR);
ODS_ListeTarifsPrestations.SelectParameters[1].DefaultValue = Convert.ToString(_animal.ID_TAILLE);
ODS_ListeTarifsPrestations.Select();
ODS_ListeTarifsPrestations.DataBind();
//**************************************************************************************************
//Initialisation du Detailsview après création d'une nouvelle vente
//Récupération de l'ID_CLIENT du maitre de l'animal sélectionné
int _idClient = _animal.ID_CLIENT;
//Récupération de l'ID_Animal de l'animal sélectionné
int _idAnimal = _animal.ID_ANIMAL;
//Récupération de la date
DateTime _datevente = DateTime.Now;
//Création d'une nouvelle vente avec récupération de l'ID de la vente
VenteBLL _Vente = new VenteBLL();
//Paramètres: @ID_CLIENT,@ID_EMPLOYE,@Date_Vente,@Total_Vente_HT,@Total_Vente_TTC
//On récupère l'id de la dernière vente enregistrée pour initialiser le detailsview
int _idVente = _Vente.InsertVenteReturnIDVente(_idClient, 1,_idAnimal, _datevente, 0, 0);
//Affichage de la vente créée
ODS_VenteData.SelectParameters[0].DefaultValue = Convert.ToString(_idVente);
ODS_VenteData.Select();
ODS_VenteData.DataBind();
//Affichage des boutons en fonction du type d'animal
switch (_animal.TypeAnimal)
{
case "Chien":
BtnAnnuler.ImageUrl = "~/App_Themes/Vert/Images/dog2_back_32.gif";
BtnValider.ImageUrl = "~/App_Themes/Vert/Images/dog5_ok_32.gif";
break;
case "Chat":
BtnAnnuler.ImageUrl = "~/App_Themes/Vert/Images/russianblu_32_Annuler.gif";
BtnValider.ImageUrl = "~/App_Themes/Vert/Images/birman2_32_OK.gif";
break;
default:
BtnAnnuler.ImageUrl = "~/App_Themes/Vert/Images/dog2_back_32.gif";
BtnValider.ImageUrl = "~/App_Themes/Vert/Images/dog5_ok_32.gif";
break;
}
}
//******************************************************************************************************
//Récupérer l'id de l'animal envoyé dans la page
//int Param = Request.QueryString["ID"];
//FormView Fw = (FormView)FormViewAnimal;
//TextBox _TxtbxidClient = (TextBox)Fw.FindControl("MaitreAnimalTextBox");
//String _Client = _TxtbxidClient.Text;
////@ID_CLIENT
//ODS_VenteData.InsertParameters[0].DefaultValue = "1";
////@ID_EMPLOYE
//ODS_VenteData.InsertParameters[1].DefaultValue = "1";
////@Date_Vente
//ODS_VenteData.InsertParameters[2].DefaultValue = _datevente.ToString();
////@Total_Vente_HT
//ODS_VenteData.InsertParameters[3].DefaultValue = "0";
////
//ODS_VenteData.InsertParameters[4].DefaultValue = "0";
}
protected void GridViewListePrestations_RowDataBound(object sender, GridViewRowEventArgs e)
{
//Si un élément est sélectionné (y compris si c'est un alternate) on récupère les valeurs dont
//on a besoin pour ajouter au ticket
if ((e.Row.RowState & DataControlRowState.Selected) == DataControlRowState.Selected)
{
DataRowView _rowview = (DataRowView)e.Row.DataItem;
//Récupération des valeurs de la sélection à ajouter à la vente
string _codeitem = _rowview.Row.ItemArray[1].ToString();
int _idPrestation =(int)_rowview.Row.ItemArray[2];
string _prestation = _rowview.Row.ItemArray[3].ToString();
double _tarif = (double)_rowview.Row.ItemArray[9];
double _tva = (double)_rowview.Row.ItemArray[10];
//Calcul de la valeur Hors TVA
double _tarif_ht;
if (_tva == 0 || _tva == null)
_tarif_ht = 0;
else
_tarif_ht = _tarif / (1+_tva);
//Calcul de la valeur remisée
double _val_remisee;
_val_remisee = _tarif;
//Récupération de l'ID_VENTE du détailsview
DetailsView Dv = (DetailsView)DetailsViewVente;
int _idVente = (int)Dv.DataKey.Value;
//Insertion d'une ligne dans la table T_VENTE_DETAIL
VenteDetailBLL _DetailVente = new VenteDetailBLL();
//Paramètres: @ID_VENTE,@ID_ARTICLE,@ID_PRESTATION,@Code_Item,@Item,@Prix_Unitaire_HT,@Taux_TVA
// @Prix_Unitaire_TTC,@Quantite,@Remise,@Total_Article
_DetailVente.InsertVenteDetail(_idVente, 0, _idPrestation, _codeitem, _prestation, _tarif_ht, _tva, _tarif, 1, 0, _val_remisee);
//Mise à jour de l'affichage dans le gridview
ODS_PrestationsRDV.Select();
//ODS_PrestationsRDV.DataBind();
GridViewDetailVente.DataBind();
}
}
protected void GridViewListePrestations_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewListePrestations.DataBind();
}
protected void BtnAnnuler_Click(object sender, ImageClickEventArgs e)
{
//if ("return confirm('Are you sure that you want to delete the product ?')")
//{
//************************************************************************************
//**** Annulation de la vente *******************************************************
//************************************************************************************
VenteDetailBLL _DetailVente = new VenteDetailBLL();
VenteBLL _Vente = new VenteBLL();
//Récupération de l'ID_VENTE du détailsview
DetailsView Dv = (DetailsView)DetailsViewVente;
int _idVente = (int)Dv.DataKey.Value;
//Suppression des prestations ajoutées
//_DetailVente..DeleteVenteDetailByIDVente(_idVente);(ne fonctionne pas, je ne sais pas pourquoi)
// Iterate through the Products.Rows property
foreach (GridViewRow row in GridViewDetailVente.Rows)
{
// Access the CheckBox
{
// Delete row! (Well, not really...)
// First, get the ProductID for the selected row
int _IDDetailVente = Convert.ToInt32(GridViewDetailVente.DataKeys[row.RowIndex].Value);
// "Delete" the row
_DetailVente.DeleteVenteDetail(_IDDetailVente);
//............................................
}
}
//}
//Suppression de la vente
_Vente.DeleteVente(_idVente);
//retour à l'écran de recherche
Response.Redirect("RechercheClient.aspx");
}
private bool confirm(string p)
{
throw new NotImplementedException();
}
protected void BtnValider_Click(object sender, ImageClickEventArgs e)
{
//Retour à l'écran de recherche
Response.Redirect("RechercheClient.aspx");
}
//Création de variables de niveau page pour le calcul de totaux dans le GridViewDetailVente
double _totalTTC = 0;
double _totalHT = 0;
double _totalGeneral = 0;
int _NbreElements = 0;
protected void GridViewDetailVente_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Reference the DetailVenteRow via the e.Row.DataItem property
Vente.T_VENTE_DETAILRow _detailVente = (Vente.T_VENTE_DETAILRow)
((System.Data.DataRowView)e.Row.DataItem).Row;
// Increment the running totals (if they're not NULL!)
if (!_detailVente.IsPrix_Unitaire_HTNull())
{
_totalHT += _detailVente.Prix_Unitaire_HT;
_totalTTC += _detailVente.Prix_Unitaire_TTC;
_totalGeneral += _detailVente.Total_Article;
}
//incrémente le nombre d'élément même si la valeur est NULL
_NbreElements++;
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[0].Text = "Nbre d'élts:" + _NbreElements.ToString();
e.Row.Cells[1].Text = "Total:";
e.Row.Cells[2].Text = _totalHT.ToString("c");
e.Row.Cells[4].Text = _totalTTC.ToString("c");
e.Row.Cells[6].Text = _totalGeneral.ToString("c");
}
//Récupération de l'ID_VENTE du détailsview
VenteBLL _Vente = new VenteBLL();
DetailsView Dv = (DetailsView)DetailsViewVente;
int _idVente = (int)Dv.DataKey.Value;
_Vente.UpdateTotalByIDVente(_totalHT, _totalTTC, _idVente);
Dv.DataBind();
}
} |
Partager