saving image into database which is generated dynamically and saved in image button - html

Random rd = new Random();
string data = rd.Next(111111111, 999999999).ToString();
QRCodeGenerator q = new QRCodeGenerator();
QRCodeGenerator.QRCode qc = q.CreateQrCode(data,
QRCodeGenerator.ECCLevel.Q);
System.Drawing.Bitmap bm = qc.GetGraphic(28);
MemoryStream ms = new MemoryStream();
bm.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] b = ms.ToArray();
Image1.ImageUrl = "data:image/png;base64," + `Convert.ToBase64String(b);`
String qr = Image1.ImageUrl.ToString();
i have generated qr code and put into imagebox i need to save it to sql database in asp.net

I think you don't want to save the actual image in the db, just the link to it:
Random rd = new Random();
string Path="D:\data\images\"; //folder where you want to store images
string data = rd.Next(111111111, 999999999).ToString();
QRCodeGenerator q = new QRCodeGenerator();
QRCodeGenerator.QRCode qc = q.CreateQrCode(data,
QRCodeGenerator.ECCLevel.Q);
System.Drawing.Bitmap bm = qc.GetGraphic(28);
Guid uniqueid=new Guid();
bm.Save(path+uniqueid.ToString()+'.png', System.Drawing.Imaging.ImageFormat.Png);
You only save the link to this file in the DB
(the path and the file name to this png file) as well as an identifier that you will query to get this link.
You need to create a table in the database, add the fields needed
(once you do this I could help you further with inserting the record in the db)

First create a database in SQL, like this:
CREATE DATABASE QRDataBaseEntities
GO
CREATE TABLE Photo
(
PhotoID INT IDENTITY PRIMARY KEY,
Name NVARCHAR(100),
Photo VARBINARY(MAX)
)
Then create a function in C#, like this:
void SaveOnDatabase()
{
QRDataBaseEntities DbContext = new QRDataBaseEntities();
Photo Item = new Photo();
Item.Name = Image1;
Item.Photo=b;
DbContext.Photos.Add(Item);
DbContext.SaveChanges();
}

Related

importing data from another database based on field value

I have a website where I am trying to setup a page where someone would have to enter a number into a field, which would correspond to a field in the other database, and import (add) the records from that database, into a table of another database, and I am having trouble with that.
I know how to update and add data from table to table within the same database, but just unsure how I would do that from another database.
This is the code that I would use to add data to another table
$data = array();
$keyvalues = array();
$data["Number"] = $values['Number'];
$data["Rider Name"] = $values['Rider Name'];
$data["Horse Name"] = $values['Horse Name'];
$data["Division Name"] = $values['Division Name'];
$data["Level"] = $values['Level'];
$data["Division Type"] = $values['Division Type'];
$data["Show Type"] = $values['Show Type'];
$data["Dressage Test"] = $values['Dressage Test'];
$keyvalues["Number"] = $values['Number'];
if ($values['Number'] = $values['Number']){
DB::Insert("Scoring", $data, $keyvalues );
}
But not sure how I would do it from another database. Any help would be appreciated.

VB.net Autocomplete Textbox filter using mysql database as custom source

I'm Having a problem regarding to the autocomplete textbox. First I already made the autocomplete textbox work with mysql database as custom source but the default textfilter of autocomplete is "start with" not "contains". I want to change the textfilter to "contains", so that when I search any part of the string, the whole name which contains the searched word will appear in the autocomplete suggestions.
Can anyone help me fix my code?
This is the code i've done so far:
txtSearch.AutoCompleteMode = AutoCompleteMode.SuggestAppend
txtSearch.AutoCompleteSource = AutoCompleteSource.CustomSource
Dim DataCollection As New AutoCompleteStringCollection()
Dim query As String
sqlcon = New MySqlConnection
sqlcon.ConnectionString =
"server=localhost;userid=root;password=root;database=svfmemberlistdb"
Try
sqlcon.Open()
query = " SELECT Name FROM svfmemberlistdb.svfmemberlist "
sqlcmd = New MySqlCommand(query, sqlcon)
sqladr.SelectCommand = sqlcmd
sqladr.Fill(ds)
sqladr.Dispose()
sqlcon.Close()
For Each row As DataRow In ds.Tables(0).Rows
If row.ToString.Contains(txtSearch.Text) Then
DataCollection.Add(row(0).ToString())
End If
Next
Catch ex As Exception
End Try
txtSearch.AutoCompleteCustomSource = DataCollection
I quote here Mitja Bonca's answer on MSDN.
In this case, autocompletemode will just not do. Its code is not meant
for something like it.
You will have to do your own code, to do the filtering on each letter
press.
So I would suggest not to use autocompletemode, and get all the data
(names) into dataTable. When user presses some button ("1" for
example), you start with your filtering, by creating new Datatable
(leave the main one untached - so you can return back to all data when
clearing comboBox by backspace), with Copy() method - to create a full
copy of original one, and use Select method to do the filteing.
This should look something like by using % simbol on both sides of a
string - to filter inbetween - this is what you want!
DataTable AllNames = new DataTable();
//fill it up and leave it untouched!
//to filter comboBox with names that contains pressed characters do in
private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
string name = string.Format("{0}{1}", comboBox1.Text, e.KeyChar.ToString()); //join previous text and new pressed char
DataRow[] rows = table.Select(string.Format("FieldName LIKE '%{0}%'", name));
DataTable filteredTable = AllNames.Clone();
foreach(DataRow r in rows)
filteredTable.ImportRow(r);
comboBox1.DataSource = null;
comboBox1.DataSource = filteredTable.DefaultView;
comboBox1.DisplayMember = "FieldName";
}
Reference
EDIT: This is of course a c# answer not VB.NET but it might be helpful to get the concept.

Embedding SSRS 2016 reports into another webpage without iFrame?

Reporting-services 2016 (currently only available as a technical preview) comes with big-upgrades including HTML5 rendering and compliance. See: https://msdn.microsoft.com/en-us/library/ms170438.aspx
My desire is to embed SSRS 2016 reports into another webpage using native mode (no Sharepoint or aspx, just pure HTML5).
The traditional fashion to do this is to use an iFrame.
This is an half-way okay method as it's possible to remove the toolbar, hide parameters etc but still you end up losing a lot of control over the document. This is a cross-site implementation from a different domain so I can't manipulate the contained iFrame document as I please.
Does there exist an official way to embed the report element 'natively'?
I could envision a URL parameter option like rs:Format=REPORTDIV which serves me a html element.
I also tried fetching the report as an image (rs:Format=IMAGE&rc:OutputFormat=PNG) but the resulting PNG has a huge white frame (even when setting background to transparent in Report Builder) around the report element which is a no-go.
This should work. It should work outside of the environment as well as it embeds the images from memory instead of fetching them from the database
// Create service instance
ReportExecutionServiceSoapClient rsExec = new ReportExecutionServiceSoapClient(binding, endpoint);
rsExec.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
rsExec.ChannelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
ReportingServices.Extension[] extentions = null;
ReportingServices.TrustedUserHeader trustedUserHeader = new ReportingServices.TrustedUserHeader();
rsExec.ListRenderingExtensions(trustedUserHeader, out extentions);
string reportPath = "/Untitled";
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
ReportingServices.ServerInfoHeader serverInfo = new ReportingServices.ServerInfoHeader();
string historyID = null;
rsExec.LoadReport(trustedUserHeader, reportPath, historyID, out serverInfo, out execInfo);
//Get execution ID
execHeader.ExecutionID = execInfo.ExecutionID;
string deviceInfo = null;
string extension;
string encoding;
string mimeType;
ReportingServices.Warning[] warnings = new ReportingServices.Warning[1];
warnings[0] = new ReportingServices.Warning();
string[] streamIDs = null;
string format = "HTML5";
Byte[] result;
rsExec.Render(execHeader, trustedUserHeader, format, deviceInfo, out result, out extension, out mimeType, out encoding, out warnings, out streamIDs);
var report = Encoding.UTF8.GetString(result);
int streamIdCount = streamIDs.Length;
Byte[][] imageArray = new Byte[streamIdCount][];
String[] base64Images = new String[streamIdCount];
for (int i = 0; i <= streamIdCount - 1; i++)
{
Byte[] result2;
string streamId = streamIDs[i];
rsExec.RenderStream(execHeader, trustedUserHeader, format, streamId, deviceInfo, out result2, out encoding, out mimeType);
imageArray[i] = result2;
base64Images[i] = Convert.ToBase64String(result2);
string replace = string.Format("https://<reportserver>/ReportServer?%2FUntitled&rs%3ASessionID={0}&rs%3AFormat={1}&rs%3AImageID={2}", execInfo.ExecutionID, format, streamId);
string src = string.Format("data:{0};charset=utf-8;base64, {1}", mimeType, base64Images[i]);
report = report.Replace(replace, src);
}

F#: DataContractJsonSerializer.WriteObject method

I am new to programming and F# is my first language.
Here are the relevant parts of my code:
let internal saveJsonToFile<'t> (someObject:'t) (filePath: string) =
use fileStream = new FileStream(filePath, FileMode.OpenOrCreate)
(new DataContractJsonSerializer(typeof<'t>)).WriteObject(fileStream, someObject)
let dummyFighter1 = { id = 1; name = "Dummy1"; location = "Here"; nationality = "Somalia"; heightInMeters = 2.0; weightInKgs = 220.0; weightClass = "Too fat"}
let dummyFighter2 = { id = 2; name = "Dummy2"; location = "There"; nationality = "Afghanistan"; heightInMeters = 1.8; weightInKgs = 80.0; weightClass = "Just Nice"}
let filePath = #"G:\User\Fighters.json"
saveJsonToFile dummyFighter1 filePath
saveJsonToFile dummyFighter2 filePath
When I run "saveJsonToFile dummyFighter1 filePath", the information is successfully saved. My problem is this: Once I run "saveJsonToFile dummyFighter2 filePath", it immediately replaces all the contents that are already in the file, i.e., all the information about dummyFighter1.
What changes should I make so that information about dummyFighter2 is appended to the file, instead of replacing information about dummyFighter1?
Change the way you open a file setting FileMode.OpenOrCreate to FileMode.Append. Append means "create or append" :
use fileStream = new FileStream(filePath, FileMode.Append)
From MSDN (https://msdn.microsoft.com/fr-fr/library/system.io.filemode%28v=vs.110%29.aspx) :
FileMode.Append opens the file if it exists and seeks to the end of the file, or
creates a new file. This requires FileIOPermissionAccess.Append
permission. FileMode.Append can be used only in conjunction with
FileAccess.Write. Trying to seek to a position before the end of the
file throws an IOException exception, and any attempt to read fails
and throws a NotSupportedException exception.

cocos2dx CCArray of sprites

I am working on cocos2dx. I am fetching images from facebook for the Leaderboard.
When images fetched from facebook I used them as CCtexture but I have lot of images so, each time I don't want to create object of CCTexture.
I used CCArray but it also create each object of CCTexture.
CCArray* ccArray = new CCArray();
CCObject* ccText = NULL;
CCTexture2D *ccTexture = dynamic_cast<CCTexture2D*>(ccText);
CCTexture2D * ccTexture0 = new CCTexture2D();
CCTexture2D * ccTexture1 = new CCTexture2D();
CCARRAY_FOREACH(ccArray, ccText)
{
ccTexture=new CCTexture2D();
ccArray->addObject(ccTexture);
ccArray->addObject(ccTexture0);
ccArray->addObject(ccTexture1);
}