public bool update(locationsBLL p) { //Creating Boolean Variable and set its default value to false bool isSuccess = false; //Sql Connection for DAtabase SqlConnection conn = new SqlConnection(myconnstrng); try { //SQL Query to insert company into database String sql = "UPDATE licence SET location=@location WHERE type=" + p.type; //Creating SQL Command to pass the values SqlCommand cmd = new SqlCommand(sql, conn); //Passign the values through parameters cmd.Parameters.AddWithValue("@location", p.location); //Opening the Database connection conn.Open(); int rows = cmd.ExecuteNonQuery(); //If the query is executed successfully then the value of rows will be greater than 0 else it will be less than 0 if (rows > 0) { //Query Executed Successfully isSuccess = true; } else { //FAiled to Execute Query isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
private void Form1_Load(object sender, EventArgs e) { locationsBLL l = new locationsBLL(); locationDAL ld = new locationDAL(); c = dc.Search(companydeact); emailsBLL email = new emailsBLL(); txtemail.Text = c.c_email; txtcompany.Text = c.c_name; l = ld.search("template"); lbltemplate.Text = l.location; filePath = lbltemplate.Text; l = ld.search("save deactivation"); lblsave.Text = l.location; filepathemail = lblsave.Text; savepath = lblsave.Text; }
public locationsBLL search(string keyword) { //Create an object of companysBLL and return it locationsBLL p = new locationsBLL(); //SqlConnection SqlConnection conn = new SqlConnection(myconnstrng); //Datatable to store data temporarily DataTable dt = new DataTable(); try { //Write the Query to Get the detaisl string sql = "SELECT location FROM locations WHERE type LIKE '%" + keyword + "%' "; //Create Sql Data Adapter to Execute the query SqlDataAdapter adapter = new SqlDataAdapter(sql, conn); //Open DAtabase Connection conn.Open(); //Pass the value from adapter to dt adapter.Fill(dt); //If we have any values on dt then set the values to companysBLL if (dt.Rows.Count > 0) { p.location = dt.Rows[0]["location"].ToString(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { //Close Database Connection conn.Close(); } return(p); }
private void button1_Click(object sender, EventArgs e) { string serial = txtserial.Text; string cid = txtcomputer_id.Text; locationsBLL l = new locationsBLL(); locationDAL l1 = new locationDAL(); OpenFileDialog file = new OpenFileDialog(); //open dialog to choose file if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK) //if there is a file choosen by the user { l.location = file.FileName; //get the path of the file l.type = "template"; if (l1.Insert(l)) { MessageBox.Show("file location saved"); } else { MessageBox.Show("file can not be added"); } } }
private void button3_Click(object sender, EventArgs e) { FolderBrowserDialog path = new FolderBrowserDialog(); //open dialog to choose file path.ShowNewFolderButton = true; if (path.ShowDialog() == System.Windows.Forms.DialogResult.OK) //if there is a file choosen by the user { locationsBLL l = new locationsBLL(); locationDAL l1 = new locationDAL(); OpenFileDialog file = new OpenFileDialog(); //open dialog to choose file l.location = path.SelectedPath; //get the path of the file l.type = "save deactivation"; if (l1.Insert(l)) { MessageBox.Show("file location saved"); } else { MessageBox.Show("file can not be added"); } } }