/// <summary> /// 读取行元素中的内容元素 /// </summary> /// <param name="EL"></param> /// <returns></returns> private List <ContentEntity> ReadContent(XElement EL) { List <ContentEntity> listResult = new List <ContentEntity>(); foreach (XElement Node in EL.Elements()) { if (Node.Name == "Text") { TextEntity Result = this.ReadText(Node); listResult.Add(Result); } else if (Node.Name == "StrLine") { StrLineEntity Result = this.ReadStrLine(Node); listResult.Add(Result); } else if (Node.Name == "Image") { ImageEntity Result = this.ReadImage(Node); listResult.Add(Result); } else if (Node.Name == "QRCode") { QRCodeEntity Result = this.ReadQRCode(Node); listResult.Add(Result); } else if (Node.Name == "BarCode") { BarCodeEntity Result = this.ReadBarCode(Node); listResult.Add(Result); } } return(listResult); }
/// <summary> /// 读取二维码节点 /// </summary> /// <param name="Node"></param> /// <returns></returns> private QRCodeEntity ReadQRCode(XElement Node) { QRCodeEntity Result = new QRCodeEntity(); float Left = Node.Value <float>("Left"); float Top = Node.Value <float>("Top"); int ModuleSize = Node.Value <int>("ModuleSize"); float Width = Node.Value <float>("Width"); float Height = Node.Value <float>("Height"); string Content = Node.Value; if (Content.Contains("{{") && Content.Contains("}}")) { Result.ContentType = 2; } else { Result.ContentType = 1; } Result.Content = Content; Result.Left = Left; Result.Top = Top; Result.Width = Width; Result.Height = Height; Result.ModuleSize = ModuleSize; return(Result); }
/// <summary> /// 写入单行 /// </summary> /// <param name="entity"></param> private void WriteLine(LineEntity entity, Dictionary <string, object> dicSource) { if (!entity.ListContent.IsNullOrEmpty()) { foreach (ContentEntity item in entity.ListContent) { if (item is StrLineEntity) { StrLineEntity Content = item as StrLineEntity; this.WriteLine(Content); } else if (item is TextEntity) { TextEntity Content = item as TextEntity; this.WriteText(Content, dicSource); } else if (item is ImageEntity) { ImageEntity Content = item as ImageEntity; this.WriteImage(Content, dicSource); } else if (item is QRCodeEntity) { QRCodeEntity Content = item as QRCodeEntity; this.WriteQRCode(Content, dicSource); } else if (item is BarCodeEntity) { BarCodeEntity Content = item as BarCodeEntity; this.WriteBarCode(Content, dicSource); } } } this.CurrentHeight += entity.Height; }
/// <summary> /// 写入二维码 /// </summary> /// <param name="entity"></param> private void WriteQRCode(QRCodeEntity entity, Dictionary <string, object> dicSource) { float CurrentTop = entity.Top + this.CurrentHeight; string content = string.Empty; if (entity.ContentType == 2) { content = entity.Content; int beginIndex = content.IndexOf("{{"); int endIndex = content.LastIndexOf("}}"); string key = content.Substring(beginIndex + 2, endIndex - beginIndex - 2); string Value = dicSource.Value <string, object>(key) as string; content = Value; } else if (entity.ContentType == 1) { content = entity.Content; } QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H); QrCode qrCode = new QrCode(); qrEncoder.TryEncode(content, out qrCode); using (MemoryStream ms = new MemoryStream()) { if (entity.ModuleSize <= 0 || entity.ModuleSize > 5) { entity.ModuleSize = 3; } GraphicsRenderer renderer = new GraphicsRenderer(new FixedModuleSize(entity.ModuleSize, QuietZoneModules.Two)); renderer.WriteToStream(qrCode.Matrix, ImageFormat.Jpeg, ms); Image image = Image.FromStream(ms); g.DrawImage(image, new PointF(entity.Left, CurrentTop)); } }
public QRCodeEntity Read(int id) { QRCodeEntity entity = new QRCodeEntity(); string sql = $"SELECT * FROM {GetTableName()} WHERE ID= @id"; using (SqlConnection sqlConnection = new SqlConnection(GetConnectionString())) { sqlConnection.Open(); SqlParameter IdParam = new SqlParameter("@id", id); using (SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection)) { sqlCommand.Parameters.Add(IdParam); SqlDataReader reader = sqlCommand.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { entity.Id = Int32.Parse(reader["Id"].ToString()); entity.Content = (byte[])reader["Content"]; entity.QrCodeType = (QrCodeType)reader["QrCodeType"]; } } else { throw new Exception("No data found!"); } } return(entity); } }
public void CreateQRCode(Guid id) { var entity = new QRCodeEntity(); entity.Id = id; entity.CreationTime = DateTime.Now; _dbContext.Set <QRCodeEntity>().Add(entity); WriteLog(QRCodeActionType.保存二维码, entity); _dbContext.SaveChanges(); }
private void WriteLog(QRCodeActionType type, QRCodeEntity qrCodeEntity) { var entity = new LogEntity(); entity.Id = Guid.NewGuid(); entity.ActionId = (int)type; entity.QRCodeId = qrCodeEntity.Id; entity.CreationTime = DateTime.Now; entity.Json = JsonSerializer.Serialize(qrCodeEntity); _dbContext.Set <LogEntity>().Add(entity); }
/// <summary> /// 获取用户分享的二维码 /// </summary> /// <param name="reqst"></param> /// <returns></returns> public ResultInfo <QRCodeEntity> SelectShareQRCode(RequestParam <RequestQRCode> reqst) { var ri = new ResultInfo <QRCodeEntity>("99999"); int userid = ConvertHelper.ParseValue(reqst.body.UserId, 0); if (userid == 0) { ri.code = "1000000000"; ri.message = Settings.Instance.GetErrorMsg(ri.code); return(ri); } QRCodeEntity entity = new QRCodeEntity(); MemberEntity ent = _logic.SelectMemberByUserId(userid); if (ent == null) { ri.code = "1000000015"; ri.message = Settings.Instance.GetErrorMsg(ri.code); return(ri); } else { #region 组装数据 string path = System.Web.HttpContext.Current.Server.MapPath("/Static/Images/"); string fileName = ent.username + ent.invitedcode + ".jpg"; #endregion ri.code = "1"; ri.message = Settings.Instance.GetErrorMsg(ri.code); entity.LinkUrl = Settings.Instance.SiteDomain + "/Static/Images/" + fileName; ri.body = entity; string shareUrl = "http://" + ChuanglitouP2P.Common.PublicURL.NewWXUrl + "/register/index?invitedcode=" + ent.invitedcode; try { SaveQRCode(shareUrl, path, fileName); return(ri); } catch (Exception ex) { LoggerHelper.Error(JsonHelper.Entity2Json(reqst)); LoggerHelper.Error(ex.ToString()); LoggerHelper.Error(JsonHelper.Entity2Json(reqst)); ri.code = "500"; ri.message = Settings.Instance.GetErrorMsg(ri.code); return(ri); } } }
static void Main(string[] args) { Console.WriteLine("1. QR Code инфо покупателя/n2. QR Code геолокация"); int choice = int.Parse(Console.ReadLine()); switch (choice) { case 1: { QRCodeGeneratorService qr = new QRCodeGeneratorService(); qr.GetQrCodePurchaseInfo(1, 1); QrCodeRepository q = new QrCodeRepository(); QRCodeEntity e = q.Read(3); using (MemoryStream ms = new MemoryStream()) { ms.Write(e.Content, 0, e.Content.Length); Bitmap qrCodeImage = new Bitmap(ms); qrCodeImage.Save(@"G:\\QR\Info.png"); } } break; case 2: { QRCodeGeneratorService qr = new QRCodeGeneratorService(); qr.GetQrCodeGeolocation("43.2565", "76.9285"); QrCodeRepository q = new QrCodeRepository(); QRCodeEntity e = q.ReadGeo(2); using (MemoryStream ms = new MemoryStream()) { ms.Write(e.Content, 0, e.Content.Length); Bitmap qrCodeImage = new Bitmap(ms); qrCodeImage.Save(@"G:\\QR\Geolocation.png"); } } break; default: break; } }
/// <summary> /// 读取二维码节点 /// </summary> /// <param name="Node"></param> /// <returns></returns> private QRCodeEntity ReadQRCode(XElement Node) { QRCodeEntity Result = new QRCodeEntity(); float Left = Node.Value <float>("Left"); float Top = Node.Value <float>("Top"); string Content = Node.Value; if (Content.Contains("{{") && Content.Contains("}}")) { Result.ContentType = 2; } else { Result.ContentType = 1; } Result.Content = Content; Result.Left = Left; Result.Top = Top; return(Result); }
public void AddGeo(QRCodeEntity entity) { string sqlCommand = $"INSERT INTO {GetTableNameGeo()}(UserId, Geolocation, QrCodeType) " + $"VALUES (@userId, @content, @qrCodeType)"; using (SqlConnection sqlConnection = new SqlConnection(GetConnectionString())) { sqlConnection.Open(); using (SqlCommand command = new SqlCommand(sqlCommand, sqlConnection)) { SqlParameter userIdParam = new SqlParameter("@userId", entity.UserId); SqlParameter contentParam = new SqlParameter("@content", entity.Content); SqlParameter qrCodeTypeParam = new SqlParameter("@qrCodeType", (int)entity.QrCodeType); command.Parameters.Add(userIdParam); command.Parameters.Add(contentParam); command.Parameters.Add(qrCodeTypeParam); command.ExecuteNonQuery(); } } }
/// <summary> /// 写入二维码 /// </summary> /// <param name="entity"></param> private void WriteQRCode(QRCodeEntity entity, Dictionary <string, object> dicSource) { float CurrentTop = entity.Top + this.CurrentHeight; string content = string.Empty; if (entity.ContentType == 2) { content = entity.Content; int beginIndex = content.IndexOf("{{"); int endIndex = content.LastIndexOf("}}"); string key = content.Substring(beginIndex + 2, endIndex - beginIndex - 2); string Value = dicSource.Value <string, object>(key) as string; content = Value; } else if (entity.ContentType == 1) { content = entity.Content; } cpcl_dll.CPCL_AddQRCode(dll.printer, cpcl_dll.ROTATE_NONE, (int)entity.Left, (int)CurrentTop, 1, 5, cpcl_dll.ECC_LEVEL_H, content); //QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H); //QrCode qrCode = new QrCode(); //qrEncoder.TryEncode(content, out qrCode); //using (MemoryStream ms = new MemoryStream()) //{ // if (entity.ModuleSize <= 0 || entity.ModuleSize > 5) // { // entity.ModuleSize = 3; // } // GraphicsRenderer renderer = new GraphicsRenderer(new FixedModuleSize(entity.ModuleSize, QuietZoneModules.Two)); // renderer.WriteToStream(qrCode.Matrix, ImageFormat.Jpeg, ms); // Image image = Image.FromStream(ms); // g.DrawImage(image, new PointF(entity.Left, CurrentTop)); //} }
/// <summary> /// 打印触发事件 /// </summary> private void PrintEvent() { foreach (RowEntity row in this.Page.Rows.Where(item => item.RowType == (int)ERowType.Table)) { TableEntity RowItem = row as TableEntity; float TabLeft = RowItem.Left; Action <List <TdEntity> > action = (List <TdEntity> listTD) => { float CurrentLeft = TabLeft; foreach (TdEntity Td in listTD) { if (!Td.ListContent.IsNullOrEmpty()) { foreach (ContentEntity item in Td.ListContent) { if (item is StrLineEntity) { } else if (item is TextEntity) { TextEntity Content = item as TextEntity; Content.Left = Content.Left + CurrentLeft; } else if (item is ImageEntity) { ImageEntity Content = item as ImageEntity; Content.Left = Content.Left + CurrentLeft; } else if (item is QRCodeEntity) { QRCodeEntity Content = item as QRCodeEntity; Content.Left = Content.Left + CurrentLeft; } else if (item is BarCodeEntity) { BarCodeEntity Content = item as BarCodeEntity; Content.Left = Content.Left + CurrentLeft; } } } CurrentLeft = CurrentLeft + Td.Width; } }; if (RowItem.Head != null) { action(RowItem.Head.ListTD); } if (!RowItem.ListTR.IsNullOrEmpty()) { foreach (TrEntity td in RowItem.ListTR) { action(td.ListTD); } } } foreach (RowEntity row in this.Page.Rows) { if (row.RowType == (int)ERowType.Line) { LineEntity RowItem = row as LineEntity; this.WriteLine(RowItem, this.DataSource); } else if (row.RowType == (int)ERowType.Loop) { LoopEntity RowItem = row as LoopEntity; string KeyName = RowItem.KeyName; object ds = this.DataSource.Value <string, object>(KeyName); List <Dictionary <string, object> > listSource = ds as List <Dictionary <string, object> >; if (!listSource.IsNullOrEmpty()) { this.WriteLoop(RowItem, listSource); } } else if (row.RowType == (int)ERowType.Table) { TableEntity RowItem = row as TableEntity; string KeyName = RowItem.KeyName; object ds = this.DataSource.Value <string, object>(KeyName); List <Dictionary <string, object> > listSource = ds as List <Dictionary <string, object> >; if (!listSource.IsNullOrEmpty()) { this.WriteTable(RowItem, listSource); } } } }