private void Btn_ok_Click(object sender, RoutedEventArgs e) { try { if (string.IsNullOrEmpty(oldFilePath) || string.IsNullOrEmpty(tb_name.Text) || string.IsNullOrEmpty(tb_tableno.Text)) { CustomMessageBox.ShowInfoMessage("图片、姓名、桌号缺一不可!"); return; } //文件夹不存在的话,创建文件夹 if (!Directory.Exists(CommonValues.IMAGEPATH)) { Directory.CreateDirectory(CommonValues.IMAGEPATH); } //复制图片到指定的目录 string imgName = Guid.NewGuid().ToString("N") + ".jpg"; File.Copy(oldFilePath, CommonValues.IMAGEPATH + "\\" + imgName); DBHelper.InsertSalesMans(tb_name.Text.Trim(), imgName, tb_tableno.Text.Trim()); CustomMessageBox.ShowInfoMessage("添加业务员成功!"); oldFilePath = string.Empty; tb_name.Text = string.Empty; tb_tableno.Text = string.Empty; img.Source = null; } catch (Exception ex) { CustomMessageBox.ShowInfoMessage("添加业务员失败!\r\n失败原因:" + ex.ToString()); } }
private void Btn_path_Click(object sender, RoutedEventArgs e) { try { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "图片|*.jpg;*.png;*.jpeg"; if (openFileDialog.ShowDialog() == true) { oldFilePath = openFileDialog.FileName; img.Source = ImageHelper.GetImageSourceFromString(oldFilePath); } } catch (Exception ex) { CustomMessageBox.ShowInfoMessage("读取图片失败!\r\n失败原因:" + ex.ToString()); } }