SmartHouseAPI/Source/MyHouse/DbOp/FrmLocationAdd.cs
zilinsoft f0ff641ed4 ## 2025-02-08 星期六更新
### MyHouse    V1.0.2502.0801
- *.[新增]适配新版接口。
### SmartHouseAPI    V1.0.2502.0801
- *.[新增]支持Docker部署,支持NAS。
2025-02-08 17:01:20 +08:00

164 lines
6.0 KiB
C#

using ryCommon;
using ryCommonDb;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using static ScintillaNETV2.Style;
namespace MyHouse.DbOp
{
public partial class FrmLocationAdd : RySkins.SKinForm
{
public ModalForm mr = null;
public int isAdd = 1;
public string selectId = "-1";
private string last_img = "";
public int ParentId { get; set; } = 0;
private int init_parentId = 0;
public bool CanEditLoc { get; set; } = true;
public FrmLocationAdd()
{
InitializeComponent();
}
#region
public void GetInfo(string id)
{
selectId = id;
var jsonResult = API.API.Post("Goods", "GetLocation","id="+id);
if (jsonResult.IsOK)
{
DataTable data = jsonResult.List;
if (data.Rows.Count>0)
{
DataRow reader = data.Rows[0];
#region
TxtSN.Text = reader["SN"].ToString();
txtName.Text = reader["Name"].ToString();
TxtDes.Text = reader["Des"].ToString();
if (isAdd == 0)
{
last_img = reader["img"].ToString();
PicLogo.Image = API.WebDav.LoadPic(Public_Config.WebDav_VistorUrl + "/" + last_img);
}
init_parentId = reader["ParentId"].ToInt();
DtLocation.selectId = reader["ParentId"].ToString();
var ds_parent = API.API.Post("Goods", "GetLocation", "id=" + reader["ParentId"].ToString());
DtLocation.Text = "";
if (ds_parent.IsOK)
{
DataTable data_parent = ds_parent.List;
if(data_parent.Rows.Count>0)
{
DtLocation.Text = "【" + data_parent.Rows[0]["SN"].ToString() + "】" + data_parent.Rows[0]["Name"].ToString();
}
}
DtLocation.Enabled = CanEditLoc;
#endregion
}
}
}
public void GetByAdd()
{
var ds_parent = API.API.Post("Goods", "GetLocation", "id=" + ParentId);
DtLocation.selectId = ParentId.ToString();
DtLocation.Text = "";
if (ds_parent.IsOK)
{
DataTable data_parent = ds_parent.List;
if (data_parent.Rows.Count > 0)
{
DtLocation.Text = "【" + data_parent.Rows[0]["SN"].ToString() + "】" + data_parent.Rows[0]["Name"].ToString();
}
}
}
private void BtnOK_Click(object sender, EventArgs e)
{
if (txtName.Text == "")
{
RySkins.Msg.ShowMsg("名称不能为空。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (TxtSN.Text == "")
{
RySkins.Msg.ShowMsg("编号不能为空。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
var parentId = DtLocation.selectId.ToInt();
RyQuickSQL mySQL = new RyQuickSQL("Location");
mySQL.AddField("SN", TxtSN.Text);
mySQL.AddField("ParentId", parentId);
mySQL.AddField("name", txtName.Text);
mySQL.AddField("img", "");
mySQL.AddField("id", selectId.ToInt());
mySQL.AddField("Des", TxtDes.Text);
var jsonResult = API.API.Post("Goods", "SaveLocation", mySQL.GetPostData());
if (jsonResult.IsOK)
{
}
else
{
RySkins.Msg.ShowMsg(jsonResult.ResultText, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
ModalForm.SetDialogResult(this, mr, DialogResult.OK);
}
#endregion
private void BtnCancel_Click(object sender, EventArgs e)
{
ModalForm.SetDialogResult(this, mr, DialogResult.Cancel);
}
private void FrmAdd_Load(object sender, EventArgs e)
{
}
private string select_img = "";
private void PicLogo_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
select_img = openFileDialog1.FileName;
PicLogo.Image = RyImage.LoadPic(select_img);
}
}
private void BtnCapture_Click(object sender, EventArgs e)
{
var capture = new ryCommon._SCREEN_CAPTURE.ScreenCapture();
Bitmap m = capture.StartCapture(false);
if (m != null)
{
long tick = DateTime.Now.Ticks;
Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
string path = Application.StartupPath + @"\UserDb\tmp\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ran.Next(1000, 9999) + ".png";
if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(path)))
{
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path));
}
RyImage.SaveHighQualityImage(m, path);
select_img = path;
PicLogo.Image = RyImage.LoadPic(select_img);
}
}
private void DtLocation_OnSelected(object sender, EventArgs e)
{
FrmLocationView frm = new FrmLocationView();
frm.IsSelectedMode = true;
if (frm.ShowDialog() == DialogResult.OK)
{
DtLocation.selectId = frm.SelectId.ToString();
DtLocation.SelectName = frm.SelectName;
}
frm.Dispose();
}
}
}