public string PrintBinderLotPrintBarcode(Int32 BinderAllotmentId, Int32 From, Int32 To, string IP) { BinderAllotQuantity objBinderAllotQuantity = new BinderAllotQuantity(); List <BinderAllotQuantityDtl> lstDtl = new List <BinderAllotQuantityDtl>(); try { objBinderAllotQuantity.barcodeDPL = new StringBuilder(); StringBuilder strReport = new StringBuilder(); DataTable GetBinderAllotQtyDtl = objDbTrx.GetBinderAllotmentQtyByID(BinderAllotmentId); if (GetBinderAllotQtyDtl.Rows.Count > 0) { objBinderAllotQuantity.ID = Convert.ToInt32(GetBinderAllotQtyDtl.Rows[0]["ID"].ToString()); objBinderAllotQuantity.AllotmentCode = GetBinderAllotQtyDtl.Rows[0]["BINDER_ALLOT_CODE"].ToString(); //objBinderAllotQuantity.BookCode = GetBinderAllotQtyDtl.Rows[0]["BOOK_CODE"].ToString(); objBinderAllotQuantity.BookCode = GetBinderAllotQtyDtl.Rows[0]["COMMON_BOOK_CODE"].ToString(); objBinderAllotQuantity.BinderName = GetBinderAllotQtyDtl.Rows[0]["BinderName"].ToString(); objBinderAllotQuantity.LanguageName = GetBinderAllotQtyDtl.Rows[0]["LANGUAGE"].ToString(); objBinderAllotQuantity.BookName = GetBinderAllotQtyDtl.Rows[0]["BOOK_NAME"].ToString(); objBinderAllotQuantity.AllotmentDate = Convert.ToDateTime(GetBinderAllotQtyDtl.Rows[0]["ALLOTMENT_DATE"].ToString()).ToString("dd-MMM-yyyy").ToUpper(); objBinderAllotQuantity.TotQty = Convert.ToInt32(GetBinderAllotQtyDtl.Rows[0]["TOT_QTY"].ToString()); objBinderAllotQuantity.Lot = Convert.ToInt32(GetBinderAllotQtyDtl.Rows[0]["LOT"].ToString()); objBinderAllotQuantity.ReqQty = Convert.ToInt32(GetBinderAllotQtyDtl.Rows[0]["REQ_QTY"].ToString()); objBinderAllotQuantity.QtyIssued = Convert.ToInt32(GetBinderAllotQtyDtl.Rows[0]["QTY_ISSUED"].ToString()); objBinderAllotQuantity.SaveStatus = Convert.ToInt16(GetBinderAllotQtyDtl.Rows[0]["STATUS"].ToString()); DataTable dtblDetail = objDbTrx.GetBinderAllotmentDtlByBinderIdFrom_To(objBinderAllotQuantity.AllotmentCode, default(int), objBinderAllotQuantity.ID, From, To); if (dtblDetail.Rows.Count > default(int)) { for (int i = 0; i < dtblDetail.Rows.Count; i++) { lstDtl.Add(new BinderAllotQuantityDtl() { DTLID = Convert.ToInt64(dtblDetail.Rows[i]["DTLID"].ToString()), //BINDER_ID = Convert.ToInt32(dtblDetail.Rows[i]["BINDER_ID"].ToString()), STICKER_CODE = dtblDetail.Rows[i]["STICKER_CODE"].ToString(), BINDER_ALLOT_CODE = dtblDetail.Rows[i]["BINDER_ALLOT_CODE"].ToString(), BINDER_SHORT_CODE = dtblDetail.Rows[i]["BINDER_SHORT_CODE"].ToString(), //BOOK_CODE = dtblDetail.Rows[i]["BOOK_CODE"].ToString(), BOOK_CODE = dtblDetail.Rows[i]["COMMON_BOOK_CODE"].ToString(), SCANNED_STATUS = Convert.ToInt32(dtblDetail.Rows[i]["SCANNED_STATUS"].ToString()) }); } } if (lstDtl.Count() > default(int)) { var cnt = 0; var barcode3 = 1; foreach (var obj in lstDtl) { string book_name = objBinderAllotQuantity.BookName; string booknameline1 = book_name.Substring(0, book_name.Length >= 16 ? 16 : book_name.Length); string booknameline2 = ""; string booknameline3 = ""; if (book_name.Length > 16) { int pending_len = book_name.Length - 16; if (pending_len > 16) { booknameline2 = book_name.Substring(16, 16); pending_len = book_name.Length - 32; if (pending_len > 16) { booknameline3 = book_name.Substring(32, 16); } else { booknameline3 = book_name.Substring(32, pending_len); } } else { booknameline2 = book_name.Substring(16, pending_len); } } cnt++; if (cnt % 2 != 0) { objBinderAllotQuantity.barcodeDPL.AppendLine("SYSVAR(48) = 0"); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "SYSVAR(35)=0"); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "qXPos% = 5"); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "FT " + @"""Univers Bold""" + ",8,0,99"); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP40+qXPos%,68:BARSET " + @"""QRCODE""" + ",1,1,6,2,1:PB " + '"' + obj.BINDER_ALLOT_CODE + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP178++qXPos%,165:PT " + '"' + obj.BOOK_CODE + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP178+qXPos%,138:PT " + '"' + booknameline1.ToUpper() + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP178+qXPos%,109:PT " + '"' + booknameline2.ToUpper() + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP178+qXPos%,85:PT " + '"' + booknameline3.ToUpper() + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP44+qXPos%,44:PT " + '"' + obj.BINDER_ALLOT_CODE + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP350+qXPos%,44:PT " + '"' + obj.BINDER_SHORT_CODE + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "FT " + @"""Univers Bold""" + ",8,0,99"); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP29+qXPos%,15:PT " + @""" ALOT QTY:" + objBinderAllotQuantity.TotQty + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP231+qXPos%,15:PT " + @""" STICKERS:" + objBinderAllotQuantity.ReqQty + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "qXPos% = 420"); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "FT " + @"""Univers Bold""" + ",8,0,99"); if (cnt == lstDtl.Count()) { objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PF" + System.Environment.NewLine); } } else if (cnt % 2 == 0) { objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP40+qXPos%,68:BARSET " + @"""QRCODE""" + ",1,1,6,2,1:PB " + '"' + obj.BINDER_ALLOT_CODE + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP178++qXPos%,165:PT " + '"' + obj.BOOK_CODE + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP178+qXPos%,138:PT " + '"' + booknameline1.ToUpper() + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP178+qXPos%,109:PT " + '"' + booknameline2.ToUpper() + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP178+qXPos%,85:PT " + '"' + booknameline3.ToUpper() + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP44+qXPos%,44:PT " + '"' + obj.BINDER_ALLOT_CODE + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP350+qXPos%,44:PT " + '"' + obj.BINDER_SHORT_CODE + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "FT " + @"""Univers Bold""" + ",8,0,99"); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP29+qXPos%,15:PT " + @""" ALOT QTY:" + objBinderAllotQuantity.TotQty + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PP231+qXPos%,15:PT " + @""" STICKERS:" + objBinderAllotQuantity.ReqQty + '"'); objBinderAllotQuantity.barcodeDPL.AppendLine(System.Environment.NewLine + "PF" + System.Environment.NewLine); } } System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient(); try { client.Connect(IP, 9100); } catch { return("Please check printer connected to network"); } try { System.IO.StreamWriter writer = new StreamWriter(client.GetStream()); writer.Write(objBinderAllotQuantity.barcodeDPL.ToString()); writer.Flush(); writer.Close(); client.Close(); return("success"); } catch { return("Printing error"); } //ViewBag.BarcodeDPL = barcodeDPL; } } } catch (Exception ex) { objDbTrx.SaveSystemErrorLog(ex, Request.UserHostAddress); } return("Print Error"); }