void pd_PrintPage(object sender, PrintPageEventArgs e) { Graphics g = e.Graphics; Font fBody; SolidBrush sb = new SolidBrush(Color.Black); switch (TypeDocToPrint) { case TypeDoc.Label: #region Label const float LEFT_TEXT_X = 19; const float RIGHT_TEXT_X = 118; float CURRENT_LINE = 70; const float INTER_SPACE_Y = 20; const float ONE_DOC_HEIGHT = 232; const float LEFT_MARG = 7; const float RIGHT_MARG = 7; g.DrawImage(Images[0], 15, 31, 90, 31); g.DrawImage(Images[0], 15, 255, 90, 31); Font fBodyLabel = new Font("Lucida Console", 9, FontStyle.Bold); fBody = new Font("Lucida Console", 9, FontStyle.Regular); GUIA_LABEL_DUO Data = (GUIA_LABEL_DUO)DataToPrint; Image x1 = (Bitmap)((new ImageConverter()).ConvertFrom(Data.BARCODE1)); g.DrawImage(x1, LEFT_TEXT_X, 204, 180, 27); Image x2 = null; if (Data.BARCODE2 != null && Data.BARCODE2.Length > 0) { x2 = (Bitmap)((new ImageConverter()).ConvertFrom(Data.BARCODE2)); g.DrawImage(x2, LEFT_TEXT_X, 204 + ONE_DOC_HEIGHT, 180, 27); } float _wTb = Width - RIGHT_TEXT_X - RIGHT_MARG; int wTb = int.Parse(_wTb.ToString()); int RightTextX = int.Parse(RIGHT_TEXT_X.ToString()); int one_doc_height = int.Parse(ONE_DOC_HEIGHT.ToString()); g.DrawString("Nombre:", fBodyLabel, sb, LEFT_TEXT_X, CURRENT_LINE); g.DrawString("Nombre:", fBodyLabel, sb, LEFT_TEXT_X, CURRENT_LINE + ONE_DOC_HEIGHT); g.DrawString("Direccion:", fBodyLabel, sb, LEFT_TEXT_X, CURRENT_LINE += INTER_SPACE_Y); g.DrawString("Direccion:", fBodyLabel, sb, LEFT_TEXT_X, CURRENT_LINE + ONE_DOC_HEIGHT); g.DrawString("Telefono:", fBodyLabel, sb, LEFT_TEXT_X, CURRENT_LINE += INTER_SPACE_Y); g.DrawString("Telefono:", fBodyLabel, sb, LEFT_TEXT_X, CURRENT_LINE + ONE_DOC_HEIGHT); g.DrawString("Ciudad:", fBodyLabel, sb, LEFT_TEXT_X, CURRENT_LINE += INTER_SPACE_Y); g.DrawString("Ciudad:", fBodyLabel, sb, LEFT_TEXT_X, CURRENT_LINE + ONE_DOC_HEIGHT); g.DrawString("Referencia:", fBodyLabel, sb, LEFT_TEXT_X, CURRENT_LINE += INTER_SPACE_Y); g.DrawString("Referencia:", fBodyLabel, sb, LEFT_TEXT_X, CURRENT_LINE + ONE_DOC_HEIGHT); g.DrawString("Consec:", fBodyLabel, sb, LEFT_TEXT_X, CURRENT_LINE += INTER_SPACE_Y); g.DrawString("Consec:", fBodyLabel, sb, LEFT_TEXT_X, CURRENT_LINE + ONE_DOC_HEIGHT); g.DrawString(Data.NOMBRE1, fBody, sb, new Rectangle(RightTextX, 70, wTb, 20)); g.DrawString(Data.NOMBRE2, fBody, sb, new Rectangle(RightTextX, 70 + one_doc_height, wTb, 20)); g.DrawString(Data.DIRECCION1, fBody, sb, new Rectangle(RightTextX, 90, wTb, 20)); g.DrawString(Data.DIRECCION2, fBody, sb, new Rectangle(RightTextX, 90 + one_doc_height, wTb, 20)); g.DrawString(Data.TELEFONO1, fBody, sb, new Rectangle(RightTextX, 110, wTb, 20)); g.DrawString(Data.TELEFONO2, fBody, sb, new Rectangle(RightTextX, 110 + one_doc_height, wTb, 20)); g.DrawString(Data.CIUDAD1, fBody, sb, new Rectangle(RightTextX, 130, wTb, 20)); g.DrawString(Data.CIUDAD2, fBody, sb, new Rectangle(RightTextX, 130 + one_doc_height, wTb, 20)); g.DrawString(Data.REFERENCIA1, fBody, sb, new Rectangle(RightTextX, 150, wTb, 20)); g.DrawString(Data.REFERENCIA2, fBody, sb, new Rectangle(RightTextX, 150 + one_doc_height, wTb, 20)); g.DrawString(Data.CONSECUTIVO_CLIENTE1, fBody, sb, new Rectangle(RightTextX, 170, wTb, 20)); g.DrawString(Data.CONSECUTIVO_CLIENTE2, fBody, sb, new Rectangle(RightTextX, 170 + one_doc_height, wTb, 20)); g.DrawLine(new Pen(Color.Black, 1), LEFT_MARG, ONE_DOC_HEIGHT + 10, Width - RIGHT_MARG, ONE_DOC_HEIGHT + 10); #endregion break; case TypeDoc.Guia: #region Guia fBody = new Font("Consolas", 10, FontStyle.Regular); JObject DataG = (JObject)DataToPrint; int wwTb = 330; int smWTb = 70; int hTb = 35; int firstField = 95; int LeftTextX = 39; int RTextX = 393; int curField = firstField; g.DrawString(DataG["REMITENTE_NOMBRE"].ToString(), fBody, sb, new Rectangle(LeftTextX, curField, wwTb, hTb)); g.DrawString(DataG["ORIGEN_VAL"].ToString(), fBody, sb, new Rectangle(RTextX, curField, wwTb, hTb)); string dest = DataG["DESTINATARIO_NOMBRE"].ToString() + Environment.NewLine + DataG["DESTINATARIO_DIRECCION"].ToString() + Environment.NewLine + DataG["DESTINATARIO_TELEFONO"].ToString(); g.DrawString(dest, fBody, sb, new Rectangle(LeftTextX, curField += 62, wwTb, hTb)); g.DrawString(DataG["DESTINO_VAL"].ToString(), fBody, sb, new Rectangle(RTextX, curField, wwTb, hTb)); string date = string.Format("{0:dd/MM/yyyy}", DataG["FECHA_ENVIO"]); g.DrawString(date, fBody, sb, new Rectangle(LeftTextX, curField += 78, wwTb / 2, hTb)); g.DrawString(DataG["UNIDADES"].ToString(), fBody, sb, new Rectangle(RTextX, curField, smWTb, hTb)); g.DrawString(DataG["PESO"].ToString() + "Kgs", fBody, sb, new Rectangle(RTextX + smWTb, curField, smWTb, hTb)); g.DrawString(DataG["PESO_VOL"].ToString() + "Kgs", fBody, sb, new Rectangle(RTextX + (smWTb * 2), curField, smWTb, hTb)); g.DrawString(DataG["PESO_LIQ"].ToString() + "Kgs", fBody, sb, new Rectangle(RTextX + (smWTb * 3), curField, smWTb, hTb)); string curr = string.Format("{0:C0}", DataG["VALOR_DECLARADO"].ToString()); g.DrawString(curr, fBody, sb, new Rectangle(RTextX + (smWTb * 4), curField, smWTb, hTb)); g.DrawString(DataG["DICE_CONTENER"].ToString(), fBody, sb, new Rectangle(LeftTextX, curField += 59, wwTb, hTb)); g.DrawString(DataG["OBSERVACIONES"].ToString(), fBody, sb, new Rectangle(RTextX, curField, wwTb, hTb)); g.DrawString(DataG["ELABORADO_POR_VAL"].ToString(), fBody, sb, new Rectangle(LeftTextX, curField += 43, wwTb, hTb)); #endregion break; default: break; } //g.DrawImage(Images[0], 15, 31, 90, 31); //g.DrawImage(Images[0], 15, 255, 90, 31); //Font fBodyLabel = new Font("Lucida Console", 9, FontStyle.Bold); //Font fBody = new Font("Lucida Console", 9, FontStyle.Regular); //SolidBrush sb = new SolidBrush(Color.Black); //GUIA_LABEL_DUO Data = (GUIA_LABEL_DUO)DataToPrint; //Image x1 = (Bitmap)((new ImageConverter()).ConvertFrom(Data.BARCODE1)); //Image x2 = (Bitmap)((new ImageConverter()).ConvertFrom(Data.BARCODE2)); //g.DrawImage(x1, LEFT_TEXT_X, 204, 180, 27); //g.DrawImage(x2, LEFT_TEXT_X, 204 + ONE_DOC_HEIGHT, 180, 27); //float _wTb = Width - RIGHT_TEXT_X - RIGHT_MARG; //int wTb = int.Parse(_wTb.ToString()); //int RightTextX = int.Parse(RIGHT_TEXT_X.ToString()); //int one_doc_height = int.Parse(ONE_DOC_HEIGHT.ToString()); //g.DrawString("Nombre:", fBodyLabel, sb, LEFT_TEXT_X, 70); //g.DrawString("Nombre:", fBodyLabel, sb, LEFT_TEXT_X, 70 + ONE_DOC_HEIGHT); //g.DrawString("Direccion:", fBodyLabel, sb, LEFT_TEXT_X, 90); //g.DrawString("Direccion:", fBodyLabel, sb, LEFT_TEXT_X, 90 + ONE_DOC_HEIGHT); //g.DrawString("Telefono:", fBodyLabel, sb, LEFT_TEXT_X, 110); //g.DrawString("Telefono:", fBodyLabel, sb, LEFT_TEXT_X, 110 + ONE_DOC_HEIGHT); //g.DrawString("Ciudad:", fBodyLabel, sb, LEFT_TEXT_X, 130); //g.DrawString("Ciudad:", fBodyLabel, sb, LEFT_TEXT_X, 130 + ONE_DOC_HEIGHT); //g.DrawString("Referencia:", fBodyLabel, sb, LEFT_TEXT_X, 150); //g.DrawString("Referencia:", fBodyLabel, sb, LEFT_TEXT_X, 150 + ONE_DOC_HEIGHT); //g.DrawString("Consec:", fBodyLabel, sb, LEFT_TEXT_X, 170); //g.DrawString("Consec:", fBodyLabel, sb, LEFT_TEXT_X, 170 + ONE_DOC_HEIGHT); //g.DrawString(Data.NOMBRE1, fBody, sb, new Rectangle(RightTextX, 70, wTb, 20)); //g.DrawString(Data.NOMBRE2, fBody, sb, new Rectangle(RightTextX, 70 + one_doc_height, wTb, 20)); //g.DrawString(Data.DIRECCION1, fBody, sb, new Rectangle(RightTextX, 90, wTb, 20)); //g.DrawString(Data.DIRECCION2, fBody, sb, new Rectangle(RightTextX, 90 + one_doc_height, wTb, 20)); //g.DrawString(Data.TELEFONO1, fBody, sb, new Rectangle(RightTextX, 110, wTb, 20)); //g.DrawString(Data.TELEFONO2, fBody, sb, new Rectangle(RightTextX, 110 + one_doc_height, wTb, 20)); //g.DrawString(Data.CIUDAD1, fBody, sb, new Rectangle(RightTextX, 130, wTb, 20)); //g.DrawString(Data.CIUDAD2, fBody, sb, new Rectangle(RightTextX, 130 + one_doc_height, wTb, 20)); //g.DrawString(Data.REFERENCIA1, fBody, sb, new Rectangle(RightTextX, 150, wTb, 20)); //g.DrawString(Data.REFERENCIA2, fBody, sb, new Rectangle(RightTextX, 150 + one_doc_height, wTb, 20)); //g.DrawString(Data.CONSECUTIVO_CLIENTE1, fBody, sb, new Rectangle(RightTextX, 170, wTb, 20)); //g.DrawString(Data.CONSECUTIVO_CLIENTE2, fBody, sb, new Rectangle(RightTextX, 170 + one_doc_height, wTb, 20)); //g.DrawLine(new Pen(Color.Black, 1), LEFT_MARG, ONE_DOC_HEIGHT + 10, Width - RIGHT_MARG, ONE_DOC_HEIGHT + 10); }
private void Print(PrintingDocument pDoc) { try { //RViewer rview; LabelPrintDoc printDoc; switch (pDoc) { case PrintingDocument.Label: #region Label int sel = 0; List <string> ids = new List <string>(); foreach (DataGridViewRow r in dgvDespachos.Rows) { if (((DataGridViewCheckBoxCell)r.Cells["Imp_Etqueta"]).Value == null) { continue; } bool val = bool.Parse(((DataGridViewCheckBoxCell)r.Cells["Imp_Etqueta"]).Value.ToString()); if (val) { ids.Add(((DataGridViewTextBoxCell)r.Cells["GUIA_ID"]).Value.ToString()); } } //if (sel < 2) { MessageBox.Show("Debe seleccionar al menos 2 registros para imprimir etiquetas"); return; } if (ids.Count == 0) { MessageBox.Show("Debe seleccionar al menos 1 registro para imprimir etiquetas"); return; } //rview = new RViewer(); //rview.ReportType = RViewer.ActionType.Label; //rview.PrinterName = cbPrinterLabel.Text; controller.RequestObj.TransParms.Clear(); controller.RequestObj.TransParms.Add(new TransParm("gNo", JsonConvert.SerializeObject(ids.ToArray()))); List <V_GUIA_ETIQUETA> dSource = (List <V_GUIA_ETIQUETA>)controller.GetData((int)GuiasController.ActionType.GetLabels); printDoc = new LabelPrintDoc(400, 480); printDoc.Images.Add(Properties.Resources.logoblanconegro); printDoc.PrinterName = cbPrinterLabel.Text; printDoc.TypeDocToPrint = LabelPrintDoc.TypeDoc.Label; //List<GUIA_LABEL_DUO> ds = new List<GUIA_LABEL_DUO>(); for (int i = 0; i < dSource.Count; i++) { GUIA_LABEL_DUO d = new GUIA_LABEL_DUO(); if (i % 2 == 0) { d.GUIA_PREFIJO1 = dSource[i].GUIA_PREFIJO; d.GUIA_ID1 = dSource[i].GUIA_ID; d.NOMBRE1 = dSource[i].NOMBRE; d.DIRECCION1 = dSource[i].DIRECCION; d.CIUDAD1 = dSource[i].CUIDAD; d.REFERENCIA1 = dSource[i].REFERENCIA; d.CONSECUTIVO_CLIENTE1 = dSource[i].CONSECUTIVO_CLIENTE; d.BARCODE1 = BarcodeUtils.GenBarcode(d.GUIA_PREFIJO1 + d.GUIA_ID1.ToString()); } i++; if (i < dSource.Count) { d.GUIA_PREFIJO2 = dSource[i].GUIA_PREFIJO; d.GUIA_ID2 = dSource[i].GUIA_ID; d.NOMBRE2 = dSource[i].NOMBRE; d.DIRECCION2 = dSource[i].DIRECCION; d.CIUDAD2 = dSource[i].CUIDAD; d.REFERENCIA2 = dSource[i].REFERENCIA; d.CONSECUTIVO_CLIENTE2 = dSource[i].CONSECUTIVO_CLIENTE; d.BARCODE2 = BarcodeUtils.GenBarcode(d.GUIA_PREFIJO2 + d.GUIA_ID2.ToString()); } //ds.Add(d); printDoc.DataToPrint = d; printDoc.PrintDoc(); } //rview.D_Source = ds; //rview.ShowDialog(); #endregion break; case PrintingDocument.Guia: #region Guia //WITH VIEWER //rview = new RViewer(); //rview.ReportType = RViewer.ActionType.Guia; //rview.PrinterName = cbPrinterGuia.Text; controller.RequestObj.TransParms.Clear(); controller.RequestObj.TransParms.Add(new TransParm("gNo", _guiaNo.ToString())); //JObject o = JsonConvert.DeserializeObject<JObject>(JsonConvert.SerializeObject(controller.GetData((int)GuiasController.ActionType.GetGuia))); //rview.D_Source = o; //rview.ShowDialog(); //With LabelPrintDoc printDoc = new LabelPrintDoc(580, 820); printDoc.PrinterName = cbPrinterGuia.Text; printDoc.TypeDocToPrint = LabelPrintDoc.TypeDoc.Guia; JArray o = JsonConvert.DeserializeObject <JArray>(JsonConvert.SerializeObject(controller.GetData((int)GuiasController.ActionType.GetGuia))); if (o.Count == 0) { throw new Exception("Error cargando datos de guia"); } printDoc.DataToPrint = o[0].ToObject <JObject>(); printDoc.PrintDoc(); #endregion break; default: break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }