415 lines
16 KiB
C#
415 lines
16 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Drawing;
|
||
using System.Windows.Forms;
|
||
using DevExpress.XtraEditors;
|
||
using UI.Framework.Forms;
|
||
using Newtonsoft.Json;
|
||
using UserFission.Properties;
|
||
using UserFission.Entitys;
|
||
using System.IO;
|
||
using UserFission.重绘;
|
||
using Api.Framework.Tools;
|
||
using UI.Framework.Tools;
|
||
using Chat.Framework;
|
||
using System.Linq;
|
||
|
||
namespace UserFission
|
||
{
|
||
public partial class ImageDesignForm : BaseForm
|
||
{
|
||
public ImageDesignForm()
|
||
{
|
||
InitializeComponent();
|
||
this.Text = Resources.PluginBillTitle;
|
||
}
|
||
|
||
private void cBox_txt_CheckedChangedcBox_txt_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
CheckBox check = (CheckBox)sender;
|
||
if (check.Name.Contains("1") && check.Checked)
|
||
lbltxt1.Visible = true;
|
||
else if (check.Name.Contains("1") && !check.Checked)
|
||
lbltxt1.Visible = false;
|
||
else if (check.Name.Contains("2") && check.Checked)
|
||
lbltxt2.Visible = true;
|
||
else if (check.Name.Contains("2") && !check.Checked)
|
||
lbltxt2.Visible = false;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ShowError(ex);
|
||
}
|
||
}
|
||
|
||
private void tBox_txt_TextChanged(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
TextBox text = (TextBox)sender;
|
||
if (text.Name.Contains("1"))
|
||
lbltxt1.Text = text.Text;
|
||
else
|
||
lbltxt2.Text = text.Text;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ShowError(ex);
|
||
}
|
||
}
|
||
|
||
//private void btn_QRCode_Click(object sender, EventArgs e)
|
||
//{
|
||
// try
|
||
// {
|
||
// OpenFileDialog openDialog = new OpenFileDialog();
|
||
// openDialog.Filter = "图片文件|*.jpg;*.png;*.gif|All files(*.*)|*.*";
|
||
// if (openDialog.ShowDialog() == DialogResult.OK)
|
||
// {
|
||
// if (string.IsNullOrEmpty(openDialog.FileName))
|
||
// throw new Exception("请先打开一张二维码图片!");
|
||
// else
|
||
// tBox_QRCode.Text = Util.DecodeQRCode(openDialog.FileName, Util.DecodeQRCodeType.Caoliao);
|
||
// }
|
||
// }
|
||
// catch (Exception ex)
|
||
// {
|
||
// if (ex.Message == "Invalid number of Finder Pattern detected")
|
||
// ShowError("二维码无法解析,请换一个重试");
|
||
// else
|
||
// ShowError(ex);
|
||
// }
|
||
//}
|
||
|
||
private void ImageDesignForm_Load(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
Class1.pick = new PickBox();
|
||
#region 海报加载模板
|
||
if (!string.IsNullOrEmpty(Class1.Config.Controlsdic))
|
||
{
|
||
var _controldic = JsonConvert.DeserializeObject<Dictionary<string, Controls>>(Class1.Config.Controlsdic);
|
||
foreach (KeyValuePair<string, Controls> item in _controldic)
|
||
{
|
||
if (item.Key == "pBox_QRcode")
|
||
{
|
||
pBox_QRcode.Name = item.Value.C_Name;
|
||
pBox_QRcode.Location = item.Value.C_Point;
|
||
pBox_QRcode.Size = item.Value.C_Size;
|
||
pBox_QRcode.BackgroundImage = null;
|
||
//tBox_QRCode.Text = item.Value.C_Tag;
|
||
}
|
||
else if (item.Value.C_Name == "lbltxt1")
|
||
{
|
||
lbltxt1.Font = JsonConvert.DeserializeObject<Font>(item.Value.T_FontJson);
|
||
lbltxt1.Size = item.Value.C_Size;
|
||
lbltxt1.ForeColor = item.Value.T_ForeColor;
|
||
lbltxt1.Width = item.Value.T_Width;
|
||
lbltxt1.Height = item.Value.T_Height;
|
||
lbltxt1.Location = item.Value.C_Point;
|
||
lbltxt1.Visible = item.Value.C_Visible;
|
||
cBox_txt1.Checked = item.Value.C_Visible;
|
||
tBox_txt1.Text = item.Value.C_Tag;
|
||
colorPickEdit1.Color = item.Value.T_ForeColor;
|
||
}
|
||
else if (item.Value.C_Name == "lbltxt2")
|
||
{
|
||
lbltxt2.Font = JsonConvert.DeserializeObject<Font>(item.Value.T_FontJson);
|
||
lbltxt2.Size = item.Value.C_Size;
|
||
lbltxt2.ForeColor = item.Value.T_ForeColor;
|
||
lbltxt2.Width = item.Value.T_Width;
|
||
lbltxt2.Height = item.Value.T_Height;
|
||
lbltxt2.Location = item.Value.C_Point;
|
||
lbltxt2.Visible = item.Value.C_Visible;
|
||
cBox_txt2.Checked = item.Value.C_Visible;
|
||
tBox_txt2.Text = item.Value.C_Tag;
|
||
colorPickEdit2.Color = item.Value.T_ForeColor;
|
||
}
|
||
else if (item.Key == "panel_Plot")
|
||
{
|
||
panel_Plot.Name = item.Value.C_Name;
|
||
panel_Plot.Location = item.Value.C_Point;
|
||
panel_Plot.Size = item.Value.C_Size;
|
||
panel_Plot.BackgroundImage = Tools.ReadImageFile(Tools.PosterPathImgUrl);
|
||
panel_Plot.BackgroundImageLayout = ImageLayout.Stretch;
|
||
panel_Plot.Font = JsonConvert.DeserializeObject<Font>(item.Value.T_FontJson);
|
||
}
|
||
}
|
||
}
|
||
cBox_AutoQrCode.Checked = Class1.Config.AutoQrCode;
|
||
cBox_AutoPicture.Checked = Class1.Config.AutoPicture;
|
||
tBox_Logo.Text = Class1.Config.LogoUrl;
|
||
tBox_Size.Text = Class1.Config.LogoSize.ToString();
|
||
|
||
if (panel_Plot.BackgroundImage == null)
|
||
panel_Plot.BackgroundImage = Resources.背景;
|
||
#endregion
|
||
|
||
#region 给控件增加移动,变大变小方法
|
||
foreach (Control item in panel1.Controls)
|
||
{
|
||
Class1.pick.WireControl(item);
|
||
}
|
||
foreach (Control item in panel_Plot.Controls)
|
||
{
|
||
Class1.pick.WireControl(item);
|
||
}
|
||
#endregion
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ShowError(ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 上传背景图
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btn_BackIamge_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)
|
||
{
|
||
if (Tools.PosterPathImgUrl.Trim() == fdlg.FileName.Trim()) throw new Exception("选择的路径为非法路径~!");
|
||
if (!string.IsNullOrWhiteSpace(Tools.PosterPathImgUrl))
|
||
File.Delete(Tools.PosterPathImgUrl);
|
||
File.Copy(fdlg.FileName, Tools.PosterPathImgUrl);
|
||
panel_Plot.BackgroundImage = Tools.ReadImageFile(Tools.PosterPathImgUrl);
|
||
}
|
||
fdlg.Dispose();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ShowError(ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 自动获取微信二维码
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void cBox_AutoQrCode_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
//try
|
||
//{
|
||
// if (cBox_AutoQrCode.Checked)
|
||
// groupBox_ImageType.Enabled = false;
|
||
// else
|
||
// groupBox_ImageType.Enabled = true;
|
||
//}
|
||
//catch (Exception ex)
|
||
//{
|
||
// ShowError(ex);
|
||
//}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 自动获取微信头像
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void cBox_AutoPicture_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (cBox_AutoPicture.Checked)
|
||
{
|
||
tBox_Logo.Enabled = false;
|
||
button2.Enabled = false;
|
||
}
|
||
else
|
||
{
|
||
tBox_Logo.Enabled = true;
|
||
button2.Enabled = true;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ShowError(ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 上传Logo图片
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void button2_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
OpenFileDialog openDialog = new OpenFileDialog();
|
||
openDialog.Filter = "图片文件|*.jpg;*.png;*.gif|All files(*.*)|*.*";
|
||
if (openDialog.ShowDialog() == DialogResult.OK) tBox_Logo.Text = openDialog.FileName;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ShowError(ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改字体属性
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btn_txt_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
Button button = (Button)sender;
|
||
FontDialog font = new FontDialog();
|
||
if (font.ShowDialog() == DialogResult.OK)
|
||
{
|
||
if (button.Name.Contains("1"))
|
||
lbltxt1.Font = font.Font;
|
||
else
|
||
lbltxt2.Font = font.Font;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ShowError(ex);
|
||
}
|
||
}
|
||
|
||
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||
{
|
||
Clipboard.SetDataObject(((LinkLabel)sender).Text);
|
||
}
|
||
|
||
private void button3_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
//if (string.IsNullOrWhiteSpace(tBox_QRCode.Text) && !cBox_AutoQrCode.Checked)
|
||
//if (!cBox_AutoQrCode.Checked)
|
||
// throw new Exception("二维码内容不能为空!");
|
||
|
||
Dictionary<string, Controls> _controls = new Dictionary<string, Controls>();
|
||
|
||
#region 保存控件的信息
|
||
foreach (Control item in panel_Plot.Controls)
|
||
{
|
||
var _control = new Controls();
|
||
_control.C_Name = item.Name;
|
||
_control.C_Point = item.Location;
|
||
_control.C_Size = item.Size;
|
||
if (typeof(Label) == item.GetType())
|
||
{
|
||
Label label = (Label)item;
|
||
if (label.Tag == null && string.IsNullOrWhiteSpace(label.Text)) { continue; }
|
||
_control.C_Tag = label.Text;
|
||
_control.T_FontJson = JsonConvert.SerializeObject(label.Font);
|
||
_control.T_Width = label.Width;
|
||
_control.T_Height = label.Height;
|
||
_control.T_ForeColor = label.ForeColor;
|
||
_control.C_Visible = label.Visible;
|
||
_controls.Add(item.Name, _control);
|
||
}
|
||
else if (typeof(MyPictureBox) == item.GetType())
|
||
{
|
||
_control.C_Tag = string.Empty;//tBox_QRCode.Text.Trim();
|
||
_controls.Add(item.Name, _control);
|
||
}
|
||
}
|
||
//保存底图控件信息
|
||
_controls.Add(panel_Plot.Name, new Controls() { C_Name = panel_Plot.Name, C_Point = panel_Plot.Location, C_Size = panel_Plot.Size, T_FontJson = JsonConvert.SerializeObject(panel_Plot.Font) });
|
||
#endregion
|
||
|
||
#region 保存窗体上的其他二维码属性
|
||
|
||
try
|
||
{
|
||
var imagePath = Util.MapFile("QRCodelogo.jpg", "File\\Image");
|
||
if (imagePath.Trim() != tBox_Logo.Text.Trim() && !string.IsNullOrWhiteSpace(tBox_Logo.Text.Trim()))
|
||
{
|
||
if (tBox_Logo.Text.Contains("http"))
|
||
FileTools.DownloadImage(tBox_Logo.Text, imagePath);
|
||
else
|
||
File.Copy(tBox_Logo.Text, imagePath, true);
|
||
tBox_Logo.Text = imagePath;
|
||
Class1.Config.LogoUrl = imagePath;
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
throw new Exception("logo图片路径不正确");
|
||
}
|
||
|
||
Class1.Config.AutoQrCode = cBox_AutoQrCode.Checked;
|
||
Class1.Config.AutoPicture = cBox_AutoPicture.Checked;
|
||
Class1.Config.LogoSize = int.Parse(tBox_Size.Text);
|
||
#endregion
|
||
Class1.Config.Controlsdic = JsonConvert.SerializeObject(_controls);
|
||
ShowSuccess("保存成功");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ShowError(ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 预览效果
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void button1_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
try
|
||
{ Class1.pick.RemoveSelect(); }
|
||
catch (Exception)
|
||
{ }
|
||
QrCode qrCode = null;
|
||
if (Class1.Config.QrCodes.Count != 0)
|
||
qrCode = Class1.Config.QrCodes.First();
|
||
|
||
pBox_QRcode.BackgroundImage = Tools.CreateQRCode(qrCode != null ? qrCode.url : "未存在二维码,当前为测试内容", tBox_Logo.Text, string.IsNullOrEmpty(tBox_Size.Text) ? 0 : int.Parse(tBox_Size.Text), 6);
|
||
//pBox_QRcode.BackgroundImage = Tools.CreateQRCode(tBox_QRCode.Text, tBox_Logo.Text, string.IsNullOrEmpty(tBox_Size.Text) ? 0 : int.Parse(tBox_Size.Text), 6);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ShowError(ex);
|
||
}
|
||
}
|
||
|
||
private void colorPickEdit1_EditValueChanged(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
var color = (ColorPickEdit)sender;
|
||
if (color.Name.Contains("1"))
|
||
lbltxt1.ForeColor = color.Color;
|
||
else
|
||
lbltxt2.ForeColor = color.Color;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ShowError(ex);
|
||
}
|
||
}
|
||
|
||
private void button4_Click(object sender, EventArgs e)
|
||
{
|
||
var form = new QRCodeForm();
|
||
form.ShowDialog();
|
||
}
|
||
|
||
}
|
||
} |