private void AttachButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Multiselect = false;
            openFileDialog1.Filter      = "JPEG files (*.jpg)|*.jpg";//|GIF files (*.gif)|*.gif|All files (*.*)|*.*";
            // Call the ShowDialog method to show the dialog box.
            bool?userClickedOK = openFileDialog1.ShowDialog();

            // Process input if the user clicked OK.
            if (userClickedOK == true)
            {
                //------- Checking file extention to allow only jepg file
                string extention = openFileDialog1.File.Extension;
                extention = extention.ToLower();
                if (!(extention == ".jpg" || extention == ".jpeg"))
                {
                    //MessageBox.Show(extention);
                    MessageBox.Show("فرمت فایل مورد قبول نیست.");
                    return;
                }
                UploadBusyIndicator.IsBusy = true;
                // Open the selected file to read.
                System.IO.Stream fileStream = openFileDialog1.File.OpenRead();
                byte[]           bytes      = new byte[fileStream.Length];
                int numBytesToRead          = (int)fileStream.Length;
                int numBytesRead            = 0;
                while (numBytesToRead > 0)
                {
                    // Read may return anything from 0 to 10.
                    int n = fileStream.Read(bytes, numBytesRead, 1);
                    // The end of the file is reached.
                    if (n == 0)
                    {
                        break;
                    }
                    numBytesRead   += n;
                    numBytesToRead -= n;
                }
                fileStream.Close();

                var attachment = new Acct_Ac_tblJournalAttachments();
                attachment.pic = bytes;
                attachment.Acct_Ac_tblJournalID = this.JournalID;
                attachment.ClientID             = SystemSettings.Settings.GetClientId();
                attachment.Created        = SystemSettings.Settings.ClientNow();
                attachment.CreatedBy      = SystemSettings.Settings.GetUserID();
                attachment.OrganizationID = SystemSettings.Settings.GetOraganizationID();
                attachment.Updated        = SystemSettings.Settings.ClientNow();
                attachment.UpdatedBy      = SystemSettings.Settings.GetUserID();
                attachment.IsActive       = true;


                ctx.Acct_Ac_tblJournalAttachments.Add(attachment);
                var t = ctx.SubmitChanges(OnSubmitCompleted, null);
            }
        }
 public ViewAttachmentChildWindow(Acct_Ac_tblJournalAttachments attachment)
 {
     InitializeComponent();
     this.Attachment  = attachment;
     this.DataContext = this;
 }