I need to create a infinite sequence of images ex:
string connectionLine;
connectionLine = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
MySqlConnection connection = new MySqlConnection(connectionLine);
MySqlCommand command = connection.CreateCommand();
command.CommandText = "SELECT comment_content, comment_author FROM " + wp_comments + " WHERE comment_post_ID =#iddo and comment_approved =#app";
command.Parameters.AddWithValue("article", article.id);
command.Parameters.AddWithValue("app", "1");
MySqlDataReader Reader;
try
{
connection.Open();
Reader = command.ExecuteReader();
if (Reader.HasRows == true)
{
while (Reader.Read())
{
radListControl1.Items.Add("By: " + Reader.GetValue(1) + " - " + Reader.GetValue(0));
PictureBox myPicBox = new PictureBox();
myPicBox.Location = new Point(300, 200);
myPicBox.Width = 328;
myPicBox.Height = 131;
myPicBox.SizeMode = PictureBoxSizeMode.StretchImage;
myPicBox.Visible = true;
myPicBox.Image = new Bitmap(Properties.Resources.fumetto);
this.Controls.Add(myPicBox);
PictureBox myPicBox1 = new PictureBox();
myPicBox1.Location = new Point(myPicBox.Location.X, myPicBox.Location.Y + 100);
myPicBox1.Width = 328;
myPicBox1.Height = 131;
myPicBox1.SizeMode = PictureBoxSizeMode.StretchImage;
myPicBox1.Visible = true;
myPicBox1.Image = new Bitmap(Properties.Resources.fumetto);
this.Controls.Add(myPicBox1);
}
}
}
catch
{ }
but this mode is good for 2 or 3 element for more element it's impossibile to calculate distance of image.
My Idea is this:
it is possibile? how to create this infinite sequenze of image with space between images ?
Related
I am trying to update mu existing image field in one of my table and I am getting error saying "A generic error occurred in GDI+". Please help.
private void Add_Records()
{
int i = check_for_null();
if (i == 1)
{
DateTime Nw = DateTime.Now;
int user = Form_Common_Login.user_id;
int ref_lc = 0;
ref_lc = Convert.ToInt16(cbo_emp_cat.SelectedValue);
try
{
string query = #"INSERT INTO tbl_Labour_Employee_Reg
(Ref_IDLC,First_Name,Last_Name,Emp_Image,Designation,NIC_No,Emp_Address,Previous_WorkPlaces,Phone_Number_Mobile,Phone_Number_Residential,Account_Number,Employee_Number,Remarks,Accessed_By,Accessed_Time,Is_Deleted,Is_Active)
VALUES ('" + ref_lc + "','" + txt_Fname.Text + "','" + txt_Lname.Text + "',#image_array,'" + txt_designation.Text + "','" + txt_nic.Text + "','" + txt_address.Text + "','" + txt_previous_wp.Text + "','" + txt_Mnumber.Text + "','" + txt_Lnumber.Text + "','" + txt_account_number.Text + "','" + txt_emp_number.Text + "','" + txt_remarks.Text + "','" + user + "','" + Nw + "',0,1)";
clz_Common_SqlConnection con = new clz_Common_SqlConnection();
SqlCommand cmd = new SqlCommand(query ,con.ActiveCon ());
MemoryStream ms = new MemoryStream ();
pic_box_employee.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] image_array = ms.ToArray();
cmd.Parameters.AddWithValue("#image_array", image_array);
cmd.ExecuteNonQuery();
MessageBox.Show("Successfully Saved");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else { MessageBox.Show("Please enter Valid Data"); }
}
my update code here
private void Update_Records()
{
int i = check_for_null();
if (i == 1)
{
DateTime Nw = DateTime.Now;
int user = Form_Common_Login.user_id;
int ref_lc = 0;
ref_lc = Convert.ToInt16(cbo_emp_cat.SelectedValue);
try
{
string update_query = "UPDATE tbl_Labour_Employee_Reg"+
"SET Ref_IDLC ='"+ref_lc+"',First_Name = ,'" + txt_Fname.Text + "',Last_Name='" + txt_Lname.Text + "',Emp_Image = #image_array,Designation = '" + txt_designation.Text + "',NIC_No='" + txt_nic.Text + "',Emp_Address = '" + txt_address.Text + "'"+
",Previous_WorkPlaces = '" + txt_previous_wp.Text + "', Phone_Number_Mobile = '" + txt_Mnumber.Text + "',Phone_Number_Residential='" + txt_Lnumber.Text + "', Account_Number= '" + txt_account_number.Text + "',Employee_Number='" + txt_emp_number.Text + "'"+
",Remarks='" + txt_remarks.Text + "',Accessed_By='" + user + "',Accessed_Time= '" + Nw + "',Is_Deleted=0,Is_Active=1";
clz_Common_SqlConnection con = new clz_Common_SqlConnection();
SqlCommand cmd = new SqlCommand(update_query, con.ActiveCon());
MemoryStream ms = new MemoryStream();
pic_box_employee.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] image_array = ms.ToArray();
cmd.Parameters.AddWithValue("#image_array", image_array);
cmd.ExecuteNonQuery();
MessageBox.Show("Successfully Updated");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else { MessageBox.Show("Please enter Valid Data"); }
}
Insert function is properly working but the update is not. I am really struck in here. If you have better way to insert & update a image field please explain.
First of all move your answer to your question. Its not an answer. Its just a new question.
try using the following, I personally update images as follows;
Image img = Image.FromFile(#"C:\Users\Awais\Desktop\image.png");
byte[] arr;
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
arr = ms.ToArray();
}
int dr = 0;
SqlConnection con = new SqlConnection("data source=.; initial catalog=database; uid=sa;pwd=password;");
SqlCommand cmd = new SqlCommand("update table set I1 = #img", con);
cmd.Parameters.AddWithValue("#img", arr);
con.Open();
using (con)
{
dr = cmd.ExecuteNonQuery();
}
I am having issues with looping through my repeater to save all the data. If I have 30 items in the repeater it will go through the repeater 30 times. However the ID never is updated. I set the id to textbox so I know the value is correct with DB and not duplicated.
Here i the code.
protected void Save()
{
foreach (RepeaterItem RI in Repeater1.Items)
{
bool budgetvalue = CBBudgeted.Checked;
//lblHeader.Text = rs["BudgetYear"].ToString();
string Janbudget = txtJanBudget.Text;
string Febbudget = txtFebBudget.Text;
string Marbudget = txtMarBudget.Text;
string Aprbudget = txtAprBudget.Text;
string Maybudget = txtMayBudget.Text;
string Junbudget = txtJunBudget.Text;
string Julbudget = txtJulBudget.Text;
string Augbudget = txtAugBudget.Text;
string Sepbudget = txtSepBudget.Text;
string Octbudget = txtOctBudget.Text;
string Novbudget = txtNovBudget.Text;
string Decbudget = txtDecBudget.Text;
string PriceEach = txtPriceEach.Text;
string IDnum = txtID.Text;
string saveStaff = "Update sales_budget " +
"set Janbudget " + Janbudget +
", Febbudget " + Febbudget +
", Marbudget " + Marbudget +
", Aprbudget " + Aprbudget +
", Maybudget " + Maybudget +
", Junbudget " + Junbudget +
", Julbudget " + Julbudget +
", Augbudget " + Augbudget +
", Sepbudget " + Sepbudget +
", Octbudget " + Octbudget +
", Novbudget " + Novbudget +
", Decbudget " + Decbudget +
", Budget " + budgetvalue +
", Price_Each " + PriceEach +
" Where id = " + IDnum;
GetConnection Sales = new GetConnection();
string conn = Sales.SalesConnect;
SqlCommand querySaveStaff = new SqlCommand(saveStaff);
using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(conn))
{
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(saveStaff, con);
con.Open();
try
{
command.ExecuteNonQuery();
}
catch
{
//GetConnection Sales = new GetConnection();
// string conn = Sales.SalesConnect;
// using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(conn))
// {
// System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(mysql, con);
// con.Open();
// System.Data.SqlClient.SqlDataReader rs = command.ExecuteReader();
// while (rs.Read())
}
con.Close();
}
}
If database files .mdf and .log do not exist in folder with application then i need to create new database, but if i do like this
CREATE DATABASE Mydvds.mdf
And i have exception that databese Mydvds.mdf is alredy exist. If i try to drop database like this
DROP DATABASE Mydvds.mdf
I have exception that base is not exist or i don't have premmisions.
I was checking database list by way of
SELECT * FROM sysdatabases
And C:\Mydvds.mdf in this list.
How i can remove this database from server?
Or can you tell me about another way do this?
public void create_db()
{
string base_path = Environment.CurrentDirectory + #"..\..\..\My_cool_db.mdf";
string log_path = Environment.CurrentDirectory + #"..\..\..\My_cool_db_log.ldf";
string ConnectionString = #"Data Source=(LocalDB)\v11.0";
string cmnd_create_db;
connection = new SqlConnection(ConnectionString);
cmnd_create_db = "CREATE DATABASE My_cool_db ON PRIMARY " +
"(NAME = My_cool_db, " +
"FILENAME = '" + #base_path + "', " +
"SIZE = 4MB, MAXSIZE = 20MB, FILEGROWTH = 10%) " +
"LOG ON (NAME = My_cool_db_log, " +
"FILENAME = '" + #log_path + "', " +
"SIZE = 4MB, " +
"MAXSIZE = 5MB, " +
"FILEGROWTH = 10%)";
ConnectionString = #"Data Source=(LocalDB)\v11.0;AttachDbFilename=" + #base_path + ";Integrated Security=True";
connection = new SqlConnection(ConnectionString);
cmnd = connection.CreateCommand();
cmnd.CommandText = cmnd_create_db;
connection.Open();
cmnd.ExecuteNonQuery();
List<string> db_cmnd = new List<string>();
db_cmnd.Add(File.ReadAllText(Environment.CurrentDirectory + "\\res\\Main.sql"));
db_cmnd.Add(File.ReadAllText(Environment.CurrentDirectory + "\\res\\Category_table.sql"));
db_cmnd.Add(File.ReadAllText(Environment.CurrentDirectory + "\\res\\ForeignKeyConstraint1.sql"));
foreach (string command_text in db_cmnd)
{
cmnd.CommandText = command_text;
cmnd.ExecuteNonQuery();
}
connection.Close();
connection.Dispose();
cmnd.Dispose();
}
as of now i can upload my image in the database the problem is when i rotate the image.
the uploaded image is not the rotated one, its still the image that i upload that i didnt rotate.
how can i upload the rotated image ?
Stream FileStream = File.OpenRead(ServerPath + Filename);
// Stream FileStream = FileUpload1.PostedFile.InputStream;
// System.Drawing.Image.FromFile(ServerPath + Filename);
//System.Drawing.Bitmap postedimage = new System.Drawing.Bitmap(FileStream);
objImage = ScaleImage(PostedImage, 73);
if (FileType != "jpg" && FileType != "JPG")
{
objImage.Save(ServerPath + jpgFileName, ImageFormat.Jpeg);
}
else
{
//objImage.Save(ServerPath + Filename);
}
img = new byte[FileStream.Length];
contentlength = FileStream.Length;
if (contentlength > 506000)
{
ClientScript.RegisterClientScriptBlock(typeof(Page), "ClosePopup", "File is to large! Maximum size is 8kb", true);
}
else if (contentlength <= 506000)
{
//ImageConverter converter = new ImageConverter();
//byte[] bytestr = (byte[])converter.ConvertTo(objImage, typeof(byte[]));
//fs.InputStream.Read(img, 0, fs.ContentLength);
byte[] bytestr = null;
var fsm = ToStream(objImage, ImageFormat.Jpeg);
//Stream fsm = ScaleImage(objImage, 73);
BinaryReader br = new BinaryReader(fsm);
bytestr = br.ReadBytes((int)fsm.Length);
SqlCommand cmd = new SqlCommand("Select * FROM tblphotoupload where mem_cardno = '" + sParameter + "'", connection);
SqlDataReader alinan_veri3;
alinan_veri3 = cmd.ExecuteReader();
if (alinan_veri3.Read())
{
int sct = 2;
int a = Convert.ToInt32(alinan_veri3["upload_count"]);
if (sct == 2)
{
if (a >= 2) a = 2;
sql = "update tblphotoupload set mem_photo" + Convert.ToString(a + 1) + " = #img, upload_date" + Convert.ToString(a + 1) + " = '" + sDateTime + "', mem_contenttype" + Convert.ToString(a + 1) + " = '" + FileType + "', mem_photofile" + Convert.ToString(a + 1) + " = '" + Filename + "', upload_count='" + (a + 1) + "' where mem_cardno = '" + sParameter + "'";
connection.Close();
SqlConnection connection2 = new SqlConnection(ConfigurationManager.ConnectionStrings["EKConn"].ConnectionString);
connection2.Open();
SqlCommand cmd2 = new SqlCommand(sql, connection2);
cmd2.Parameters.Add(new SqlParameter("#img", bytestr));
cmd2.ExecuteNonQuery();
connection2.Close();
}
}
else
{
//string ole;
sql = "insert into tblphotoupload (mem_cardno, mem_photo1, upload_date1, upload_count, mem_contenttype1, mem_photofile1) values ('" + sParameter + "', #img, '" + sDateTime + "','1','" + FileType + "','" + Filename + "')";
connection.Close();
SqlConnection connection2 = new SqlConnection(ConfigurationManager.ConnectionStrings["EKConn"].ConnectionString);
connection2.Open();
SqlCommand cmd2 = new SqlCommand(sql, connection2);
cmd2.Parameters.Add(new SqlParameter("#img", bytestr));
cmd2.ExecuteNonQuery();
connection2.Close();
}
}
}
First of all make sure that your file is saved on the disk and then save the file into DB.
If this will not help you probably will have to either:
rotate it properly, rotation might be saved only by the image viewer without changing the image on the disk, i have encountered the issue with Picassa
rotate it in the code (rotate bytes)
This button (loginButton) does everything it's supposed to on the first click. Then, on all subsequent clicks, it refuses change the text of loginStatusLabel at the beginning and end of the method...why? It's as if the code is completely skipped over for with no explanation. The debug messages before and afterword both come through fine, and loginStatusLabel isn't referenced anywhere else.
Am I an idiot?
private void loginButton_Click(object sender, EventArgs e)
{
Debug.Write("Changing label...");
loginStatusLabel.Text = "STATUS: Running..."; //this line is ignored after the first iteration
Debug.WriteLine("label changed.");
loginButton.Enabled = false;
try
{
string LDS01_start = "select count(*) from BBLEARN.AUTH_PROVIDER_LOG where AUTH_PROVIDER_PK1 = 103 ";
string LDAPS_start = "select count(*) from BBLEARN.AUTH_PROVIDER_LOG where AUTH_PROVIDER_PK1 = 106 ";
string middle = "and log_date >= '" + GetDate(loginStartDate) + #"'
and log_date < '" + GetDate(loginEndDate) + #"' ";
string LDS01_0 = LDS01_start + middle + "and event_type = 0";
string LDS01_1 = LDS01_start + middle + "and event_type = 1";
string LDS01_2 = LDS01_start + middle + "and event_type = 2";
string LDS01_5 = LDS01_start + middle + "and event_type = 5";
string LDS01_6 = LDS01_start + middle + "and event_type = 6";
string LDAPS_0 = LDAPS_start + middle + "and event_type = 0";
string LDAPS_1 = LDAPS_start + middle + "and event_type = 1";
string LDAPS_2 = LDAPS_start + middle + "and event_type = 2";
string LDAPS_5 = LDAPS_start + middle + "and event_type = 5";
string LDAPS_6 = LDAPS_start + middle + "and event_type = 6";
GetData(LDS01_0, LDS01_LB0);
GetData(LDS01_1, LDS01_LB1);
GetData(LDS01_2, LDS01_LB2);
GetData(LDS01_5, LDS01_LB5);
GetData(LDS01_6, LDS01_LB6);
GetData(LDAPS_0, LDAPS_LB0);
GetData(LDAPS_1, LDAPS_LB1);
GetData(LDAPS_2, LDAPS_LB2);
GetData(LDAPS_5, LDAPS_LB5);
GetData(LDAPS_6, LDAPS_LB6);
}
catch (Exception exception)
{
Debug.WriteLine(exception);
}
loginButton.Enabled = true;
Debug.Write("Changing label...");
loginStatusLabel.Text = "STATUS: Complete";
Debug.WriteLine("label changed.");
}
private void GetData(string selectCommand, Label label)
{
Debug.WriteLine("Getting data for " + label.Name + "...");
//open the connection
OracleConnection conn = new OracleConnection(connectString);
conn.Open();
Debug.WriteLine("Connection open...");
//define the command
selectCommand = selectCommand.Replace(Environment.NewLine, " ");
OracleDataAdapter dataAdapter = new OracleDataAdapter(selectCommand, conn);
OracleCommandBuilder commandBuilder = new OracleCommandBuilder(dataAdapter);
//run the command
Debug.WriteLine("Running command...");
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
Debug.WriteLine("Command complete.");
//close the connection
conn.Close();
Invoke(new Action(() => RenderData(label, table.Rows[0][0].ToString())));
}
private void RenderData(Label label, string text)
{
label.Text = text;
}
Forgot to create the new thread in the first place. I'm stupid.