Skip to content

Instantly share code, notes, and snippets.

@darbio
Forked from monotocho/gist:3001973
Created June 27, 2012 07:53
Show Gist options
  • Save darbio/3002292 to your computer and use it in GitHub Desktop.
Save darbio/3002292 to your computer and use it in GitHub Desktop.
Selected custom element
//********************
//Navigate to DVC1 !!!
//********************
namespace EMALI
{
public partial class vPtoVentaTipo : DialogViewController
{
public int PaginaIndex { get; set; }
public vPtoVentaTipo (int index) : base (UITableViewStyle.Grouped, null)
{
PaginaIndex = index;
RootElement root;
DataTable dt;
if (PaginaIndex == 0) {
dt = EMALI.Comun.PtoVenta.ConsultaPtoVenta (6000000114);
root = new RootElement ("Detalle Punto Venta") {
new Section (""){
new StringElement ("Código", dt.Rows[0]["PV_CODIGO_PUNTO_VENTA"].ToString()),
new eTextoLargo ("Nombre", dt.Rows[0]["PV_DENOMINACION"].ToString()),
new eTextoLargo ("Dirección", dt.Rows[0]["PV_DIRECCION"].ToString()),
new StringElement ("Población", dt.Rows[0]["PV_POBLACION"].ToString()),
new StringElement ("Provincia", dt.Rows[0]["PV_NOMBRE_PROVINCIA"].ToString()),
new StringElement ("Teléfono", dt.Rows[0]["PV_TELEFONO"].ToString()),
new StringElement ("Fax", dt.Rows[0]["PV_FAX"].ToString())
}
};
} else {
root = CargaSucursales ();
}
Root = root;
}
//********************
//Navigate to DVC1 !!!
//********************
private RootElement CargaSucursales ()
{
DataTable dt;
RootElement root;
eSucursal elemento = new eSucursal (...);
Section seccion = new Section ();
elemento.OnSelected += delegate(object sender, EventArgs e) {
this.NavigationController.PushViewController (new DialogViewController (null));
};
dt = EMALI.Comun.PtoVenta.ConsultaClientesPtoVenta (6000000114);
foreach (DataRow d in dt.Rows) {
elemento = new eSucursal (
d ["CLTE_NOMBRE"].ToString (),
d ["DIC_RAZON_SOCIAL"].ToString (),
d ["CLTE_DNI_CIF"].ToString (),
d ["DIC_DIRECCION_ENVIO"].ToString (),
d ["EMP_NOMBRE_ABREVIADO"].ToString (),
Convert.ToInt32 (d ["CLTE_CLIENTE"]),
Convert.ToInt32 (d ["DIC_SUCURSAL"])
);
seccion.Add (elemento);
}
root = new RootElement ("Sucursales Pto Venta");
root.Add (seccion);
return root;
}
// public void CargaDetalleSucursal(int cliente, int sucursal)
// {
// vSucursalDetalle sdetalle = new vSucursalDetalle (cliente, sucursal);
// this.NavigationController.PushViewController (sdetalle, true);
// }
}
}
//**************
//CUSTOM ELEMENT
//**************
namespace Test1
{
public class eSucursal : OwnerDrawnElement
{
CGGradient gradient;
private UIFont subjectFont = UIFont.SystemFontOfSize (13.0f);
private UIFont fromFont = UIFont.BoldSystemFontOfSize (14.0f);
private UIFont dateFont = UIFont.BoldSystemFontOfSize (14.0f);
public eSucursal (string nomcli, string nomsuc, string cif, string direc, string emp, int cli, int suc) : base(UITableViewCellStyle.Default, "sampleOwnerDrawnElement")
{
this.NombreCliente = nomcli;
this.NombreSucursal = nomsuc;
this.CIF = cif;
this.Direccion = direc;
this.cEmpresa = emp;
this.cCliente = cli;
this.cSucursal = suc;
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB ();
gradient = new CGGradient (
colorSpace,
new float[] { 0.95f, 0.95f, 0.95f, 1,
0.85f, 0.85f, 0.85f, 1},
new float[] { 0, 1 });
}
public string NombreSucursal {
get;
set;
}
public string NombreCliente {
get;
set;
}
public string CIF {
get;
set;
}
public string Direccion {
get;
set;
}
public string cEmpresa {
get;
set;
}
public int cCliente {
get;
set;
}
public int cSucursal {
get;
set;
}
public string FormatDate (DateTime date)
{
if (DateTime.Today == date.Date) {
return date.ToString ("hh:mm");
} else if ((DateTime.Today - date.Date).TotalDays < 7) {
return date.ToString ("ddd hh:mm");
} else {
return date.ToShortDateString ();
}
}
static public event EventHandler<EventArgs> OnSelected;
public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
base.Selected (dvc, tableView, path);
vSucursalDetalle sdetalle = new vSucursalDetalle (cliente, sucursal);
if (OnSelected != null)
OnSelected(this, EventArgs.Empty);
}
public override void Draw (RectangleF bounds, CGContext context, UIView view)
{
UIColor.White.SetFill ();
context.FillRect (bounds);
context.DrawLinearGradient (
gradient,
new PointF (bounds.Left, bounds.Top),
new PointF (bounds.Left, bounds.Bottom),
CGGradientDrawingOptions.DrawsAfterEndLocation
);
UIColor.Blue.SetColor ();
view.DrawString (
this.NombreSucursal,
new RectangleF (10, 5, bounds.Width / 2 + bounds.Width / 4, 10),
fromFont,
UILineBreakMode.MiddleTruncation
);
UIColor.Brown.SetColor ();
view.DrawString (
this.cEmpresa,
new RectangleF (bounds.Width / 2, 5, (bounds.Width / 2), 10),
dateFont,
UILineBreakMode.TailTruncation,
UITextAlignment.Right
);
UIColor.DarkGray.SetColor ();
view.DrawString (this.NombreCliente + this.CIF, new RectangleF (10, 20, bounds.Width - 20, 10), subjectFont, UILineBreakMode.WordWrap);
UIColor.DarkGray.SetColor ();
view.DrawString (this.Direccion, new RectangleF (10, 33, bounds.Width - 20, 10), subjectFont, UILineBreakMode.WordWrap);
}
public override float Height (RectangleF bounds)
{
//var height = 40.0f + TextHeight (bounds);
var height = 50.0f;
return height;
}
private float TextHeight (RectangleF bounds)
{
SizeF size;
using (NSString str = new NSString (this.Direccion)) {
size = str.StringSize (subjectFont, new SizeF (bounds.Width - 20, 1000), UILineBreakMode.WordWrap);
}
return size.Height;
}
public override string ToString ()
{
return string.Format (NombreSucursal);
}
}
}
//***************
//CREATE DVC2
//***************
namespace EMALI
{
public partial class vSucursalDetalle : DialogViewController
{
DataTable dt;
public vSucursalDetalle (int ccliente, int csucursal) : base (UITableViewStyle.Grouped, null, true)
{
dt = EMALI.Comun.Sucursal.ConsultaSucursal(ccliente, csucursal);
Root = new RootElement ("Detalle Punto Venta") {
new Section (""){
new StringElement ("Código", dt.Rows[0]["DIC_CLIENTE"].ToString()),
new eTextoLargo ("Nombre", dt.Rows[0]["DIC_RAZON_SOCIAL"].ToString()),
new eTextoLargo ("Dirección", dt.Rows[0]["DIC_DIRECCION_ENVIO"].ToString()),
new StringElement ("Población", dt.Rows[0]["DIC_POBLACION_ENVIO"].ToString()),
new StringElement ("Provincia", dt.Rows[0]["DIC_NOMBRE_PROV_ENVIO"].ToString()),
new StringElement ("Teléfono", dt.Rows[0]["DIC_TELEFONO"].ToString()),
new StringElement ("Fax", dt.Rows[0]["DIC_OBSERVACIONES"].ToString())
}
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment