old_flsystem/类库/Grant.Framework/SetOEM.cs

188 lines
7.7 KiB
C#
Raw 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.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using UI.Framework.Forms;
namespace Grant.Framework
{
public partial class SetOEM : BaseForm
{
private int sid = 1003;
AuthorizationManage auth;
private string userid = "";
public SetOEM(AuthorizationManage auth, string userid = "")
{
InitializeComponent();
this.auth = auth;
this.userid = userid;
}
private string logo = string.Empty;
private void SetOEM_Load(object sender, EventArgs e)
{
try
{
var content = auth.SendCoredata("get_oem", new { cid = userid, sid = sid }) as Dictionary<string, object>;
//var content = data["content"] as Dictionary<string, object>;
this.buttonCheck.Checked = (content.ContainsKey("ispayform") && content["ispayform"].ToString() == "1");
this.textBox1.Text = content.ContainsKey("title") ? content["title"].ToString() : "秒单客-返利机器人官网fanli.miaodanke.com";
this.textBox2.Text = content.ContainsKey("notice") ? content["notice"].ToString() : string.Empty;
logo = content.ContainsKey("logo") ? content["logo"].ToString().Replace("data:image/png;base64,", "") : string.Empty;
this.pictureBox1.Image = CsharpHttpHelper.HttpExtend.Base64StringToImage(logo);
}
catch (Exception ex)
{
BaseForm.ShowError(ex);
//this.Close();
}
}
private void simpleButton1_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Multiselect = false;//该值确定是否可以选择多个文件
dialog.Title = "请选择文件夹"; //窗体标题
dialog.Filter = "透明图片(*.png)|*.png"; //文件筛选
//默认路径设置为我的电脑文件夹
dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string file = dialog.FileName;//文件夹路径
//Size picSize;float Wpx, Hpx;
//GetSize(file,out picSize,out Wpx,out Hpx);
//if (Wpx != 380 && Hpx != 100) throw new Exception("尺寸必须为长380 宽100");
var imgByte = File.ReadAllBytes(file);
this.logo = CsharpHttpHelper.HttpHelper.ByteToBase64(imgByte);
this.pictureBox1.Image = CsharpHttpHelper.HttpExtend.Base64StringToImage(this.logo);
}
}
catch (Exception ex)
{
BaseForm.ShowError(ex);
}
}
public static int GetSize(string FileName, out Size Size, out float Wpx, out float Hpx)
{//C#快速获取JPG图片大小及英寸分辨率
Size = new Size(0, 0);
Wpx = 0; Hpx = 0;
int rx = 0;
if (!File.Exists(FileName)) return rx;
FileStream F_Stream = File.OpenRead(FileName);
int ff = F_Stream.ReadByte();
int type = F_Stream.ReadByte();
//if (ff != 0xff || type != 0xd8)
//{//非JPG文件
// F_Stream.Close();
// return rx;
//}
long ps = 0;
do
{
do
{
ff = F_Stream.ReadByte();
if (ff < 0) //文件结束
{
F_Stream.Close();
return rx;
}
} while (ff != 0xff);
do
{
type = F_Stream.ReadByte();
} while (type == 0xff);
//MessageBox.Show(ff.ToString() + "," + type.ToString(), F_Stream.Position.ToString());
ps = F_Stream.Position;
switch (type)
{
case 0x00:
case 0x01:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
break;
case 0xc0: //SOF0段
ps = F_Stream.ReadByte() * 256;
ps = F_Stream.Position + ps + F_Stream.ReadByte() - 2; //加段长度
F_Stream.ReadByte(); //丢弃精度数据
//高度
Size.Height = F_Stream.ReadByte() * 256;
Size.Height = Size.Height + F_Stream.ReadByte();
//宽度
Size.Width = F_Stream.ReadByte() * 256;
Size.Width = Size.Width + F_Stream.ReadByte();
//后面信息忽略
if (rx != 1 && rx < 3) rx = rx + 1;
break;
case 0xe0: //APP0段
ps = F_Stream.ReadByte() * 256;
ps = F_Stream.Position + ps + F_Stream.ReadByte() - 2; //加段长度
F_Stream.Seek(5, SeekOrigin.Current); //丢弃APP0标记(5bytes)
F_Stream.Seek(2, SeekOrigin.Current); //丢弃主版本号(1bytes)及次版本号(1bytes)
int units = F_Stream.ReadByte(); //X和Y的密度单位,units=0无单位,units=1点数/英寸,units=2点数/厘米
//水平方向(像素/英寸)分辨率
Wpx = F_Stream.ReadByte() * 256;
Wpx = Wpx + F_Stream.ReadByte();
if (units == 2) Wpx = (float)(Wpx * 2.54); //厘米变为英寸
//垂直方向(像素/英寸)分辨率
Hpx = F_Stream.ReadByte() * 256;
Hpx = Hpx + F_Stream.ReadByte();
if (units == 2) Hpx = (float)(Hpx * 2.54); //厘米变为英寸
//后面信息忽略
if (rx != 2 && rx < 3) rx = rx + 2;
break;
default: //别的段都跳过////////////////
ps = F_Stream.ReadByte() * 256;
ps = F_Stream.Position + ps + F_Stream.ReadByte() - 2; //加段长度
break;
}
if (ps + 1 >= F_Stream.Length) //文件结束
{
F_Stream.Close();
return rx;
}
F_Stream.Position = ps; //移动指针
} while (type != 0xda); // 扫描行开始
F_Stream.Close();
return rx;
}
private void simpleButton2_Click(object sender, EventArgs e)
{
try
{
var data = this.auth.SendCoredata("set_oem", new { sid = sid, cid = userid, content = CsharpHttpHelper.HttpHelper.ObjectToJson(new { title = this.textBox1.Text, notice = this.textBox2.Text, ispayform = (buttonCheck.Checked ? "1" : "0"), logo = this.logo }) });
this.Close();
}
catch (Exception ex)
{
BaseForm.ShowError(ex);
}
}
}
}