private void RadGridView1_Deleted(object sender, Telerik.Windows.Controls.GridViewDeletedEventArgs e) { JSDataContext lDataContext = new CommonFunction().JSDataContext(); foreach (HSSecurity l in e.Items) { if (l.Id < 0) { continue; } try { var lScreen = lDataContext.UserScreens.Where(p => p.UserId == l.Id); lDataContext.UserScreens.DeleteAllOnSubmit(lScreen); lDataContext.SubmitChanges(); DataSource.Security lItem = lDataContext.Securities.SingleOrDefault <DataSource.Security>(p => p.Id == l.Id); lDataContext.Securities.DeleteOnSubmit(lItem); lDataContext.SubmitChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void RadGridView1_RowEditEnded(object sender, Telerik.Windows.Controls.GridViewRowEditEndedEventArgs e) { if (e.EditAction == GridViewEditAction.Cancel) { return; } JSDataContext lDataContext = new CommonFunction().JSDataContext(); HSSecurity lEdited = e.EditedItem as HSSecurity; DataSource.Security lUpdate = lDataContext.Securities.SingleOrDefault(p => p.Id == lEdited.Id); if (lUpdate == null) { DataSource.Security newItem = new DataSource.Security { Id = lEdited.Id, UserName = lEdited.UserName, Password = lEdited.Password, RoleId = lEdited.RoleId, EmployeeId = lEdited.EmployeeId, DefaultPage = lEdited.PageId, AccessLevel = lEdited.AccessLevel }; // Add the new object to the Orders collection. lDataContext.Securities.InsertOnSubmit(newItem); // Submit the change to the database. try { lDataContext.SubmitChanges(); lEdited.Id = newItem.Id; } catch (Exception ex) { MessageBox.Show(ex.Message); RadGridView1.Items.Remove(e.NewData); } } else { lUpdate.UserName = lEdited.UserName; lUpdate.Password = lEdited.Password; lUpdate.RoleId = lEdited.RoleId; lUpdate.EmployeeId = lEdited.EmployeeId; lUpdate.DefaultPage = lEdited.PageId; lUpdate.AccessLevel = lEdited.AccessLevel; lDataContext.SubmitChanges(); } }
private void Load_Click(object sender, RoutedEventArgs e) { UISolution.DataSource.HanSungLinqDataContext lContext = new DataSource.HanSungLinqDataContext(); DataSource.Security lSecurity = lContext.Securities.SingleOrDefault(p => p.Id == 1); byte[] arrayBinary = lSecurity.Image.ToArray(); System.Drawing.Image rImage = null; MemoryStream ms = new MemoryStream(arrayBinary); rImage = System.Drawing.Image.FromStream(ms); string lpassword = Decrypt(lSecurity.Password); // imgTEST.Source = rImage; }
private void btnOpenFile_Click(object sender, RoutedEventArgs e) { byte[] m_barrImg; System.Drawing.Image limage = null; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Image files (*.png;*.jpeg)|*.png;*.jpeg|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == true) { string strFn = openFileDialog.FileName; //imgTEST.Source = new BitmapImage(new Uri(strFn)); limage = System.Drawing.Image.FromFile(strFn); //FileInfo fiImage = new FileInfo(strFn); //FileStream fs = new FileStream(strFn, FileMode.Open, FileAccess.Read, FileShare.Read); //m_barrImg = new byte[Convert.ToInt32(fiImage.Length)]; //int iBytesRead = fs.Read(m_barrImg, 0, Convert.ToInt32(fiImage.Length)); //fs.Close(); } DataSource.Security lSecurity = lContext.Securities.SingleOrDefault(p => p.Id == 1); MemoryStream ms = new MemoryStream(); limage.Save(ms, System.Drawing.Imaging.ImageFormat.Png); var binary = new System.Data.Linq.Binary(ms.GetBuffer()); lSecurity.Image = binary; lSecurity.Password = Encrypt("passme"); lContext.SubmitChanges(); //txtEditor.Text = File.ReadAllText(openFileDialog.FileName); }