old_flsystem/应用/TBAppraisalTools/Forms/EditPhotoForm.cs

156 lines
5.8 KiB
C#
Raw Permalink Normal View History

2022-09-20 03:10:29 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using TBAppraisalTools.Properties;
using UI.Framework.Forms;
using static TBAppraisalTools.Enums;
using Api.Framework.Tools;
using System.IO;
namespace TBAppraisalTools.Forms
{
public partial class EditPhotoForm : BaseForm
{
public TbConfig tbConfig = null;
/// <summary>
/// 增加/编辑图片
/// </summary>
/// <param name="tbConfig">为null时,添加</param>
public EditPhotoForm(TbConfig tbConfig = null)
{
InitializeComponent();
this.Text = tbConfig == null ? Resources.AddPhotoTitle : Resources.EditPhotoTitle;
this.tbConfig = tbConfig;
}
/// <summary>
/// 窗体加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void EditPhotoForm_Load(object sender, EventArgs e)
{
ImageInfo imageInfo = null;
if (tbConfig != null)//编辑图片信息
{
imageInfo = tbConfig.C_Tag as ImageInfo;
radioButton1.Checked = imageInfo.Shape;
radioButton2.Checked = !imageInfo.Shape;
if (imageInfo.Varible.Contains(EditImageType..ToString())) tBox_path.Text = imageInfo.ImagePath;
numericUpDown_Width.Value = tbConfig.C_Size.Width;
numericUpDown_Height.Value = tbConfig.C_Size.Height;
}
int i = -1;//定义这个是为了选中之后,带动触发事件
foreach (EditImageType item in Enum.GetValues(typeof(EditImageType)))
{
i++;
cBox_Variable.Items.Add("#" + item.ToString());
if (imageInfo != null && "#" + item.ToString() == imageInfo.Varible)
cBox_Variable.SelectedIndex = i;
}
if (cBox_Variable.SelectedIndex == -1) cBox_Variable.SelectedIndex = 0;
}
/// <summary>
/// 图片类型下标改变时间
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (cBox_Variable.SelectedItem.ToString().Contains(EditImageType..ToString()))
btn_LocalImage.Enabled = tBox_path.Enabled = true;
else
btn_LocalImage.Enabled = tBox_path.Enabled = false;
}
catch (Exception ex)
{
ShowError(ex);
}
}
/// <summary>
/// 上传图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_LocalImage_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "选择要上传的图片";
fdlg.InitialDirectory = @"c:\";
fdlg.Filter = "jpg,png,bmp,gif|*.jpg;*.png;*.bmp;*.gif";
fdlg.FilterIndex = 1;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
tBox_path.Text = fdlg.FileName;
fdlg.Dispose();
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void simpleButton2_Click(object sender, EventArgs e)
{
try
{
string path = string.Empty;
if (string.IsNullOrWhiteSpace(tBox_path.Text.Trim()) && cBox_Variable.SelectedItem.ToString().Contains(EditImageType..ToString()))
throw new Exception("图片地址不能为空,请选择要添加的图片");
if (cBox_Variable.SelectedItem.ToString().Contains(EditImageType..ToString()))
path = TbTools.SHOPICO;
else if (cBox_Variable.SelectedItem.ToString().Contains(EditImageType..ToString()))
path = TbTools.ITEMICO;
else
{
path = tBox_path.Text.Trim();
if (!File.Exists(path))
{
var path_temp = Util.MapFile(Guid.NewGuid().ToString() + ".png", TbTools.OTHERSICOPATH);
Tools.DownloadImage(path, path_temp);
path = path_temp;
}
}
if (tbConfig == null)
tbConfig = new TbConfig() { C_Size = new Size() { Height = (int)numericUpDown_Height.Value, Width = (int)numericUpDown_Width.Value }, C_Tag = new ImageInfo() { Shape = radioButton1.Checked, ImagePath = path, Varible = cBox_Variable.SelectedItem.ToString() } };
else
{
tbConfig.C_Size = new Size() { Height = (int)numericUpDown_Height.Value, Width = (int)numericUpDown_Width.Value };
tbConfig.C_Tag = new ImageInfo() { Shape = radioButton1.Checked, ImagePath = path, Varible = cBox_Variable.SelectedItem.ToString() };
}
this.DialogResult = DialogResult.OK;
}
catch (Exception ex)
{
ShowError(ex);
}
}
/// <summary>
/// 关闭窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void simpleButton3_Click(object sender, EventArgs e)
{
this.Close();
}
}
}