using PaintDotNet.Base.SettingModel;
using PaintDotNet.DbOpreate.DbBll;
using PaintDotNet.DbOpreate.DbModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PaintDotNet.Setting
{
///
/// 相机维护
///
public partial class CameraSettingsAddDialog : Form
{
#region 控件
private Label label2;
private TextBox textBox1;
private TextBox textBox2;
private Label label1;
private Label label5;
private Button button1;
private Button button2;
#endregion
private string pointId = string.Empty;
private ListView fatherListView;
private Label label4;
private int listIndex = 0;
public CameraSettingsAddDialog(string id, ListView listView, int index = 0)
{
StartPosition = FormStartPosition.CenterScreen;
InitializeComponent();
InitializeLanguageText();
#region [展示控件]
pointId = id;
fatherListView = listView;
listIndex = index;
if (!string.IsNullOrEmpty(pointId))
{
var point = mic_camerasettings_BLL.FindDefault(Convert.ToInt32(pointId));
if (point == null)
{
MessageBox.Show(PdnResources.GetString("Menu.Abnormalinformatio.Text"));
}
textBox1.Text = point.camera_model;
textBox2.Text = point.pixel_size;
//textBox3.Text = point.resolution;
}
#endregion
}
#region 初始化
private void InitializeLanguageText()
{
this.label1.Text = PdnResources.GetString("Menu.Cameramodel.text") + ":";
this.label2.Text = PdnResources.GetString("Menu.PixelSize.text") + ":";
//this.label3.Text = PdnResources.GetString("Menu.Set.Generalsettings.Sidelengthresolution.text") + ":";
this.label4.Text = PdnResources.GetString("Menu.Micron.text");
this.button1.Text = PdnResources.GetString("Menu.ensure.text");
this.button2.Text = PdnResources.GetString("Menu.cancel.text");
this.Text = PdnResources.GetString("Menu.Set.Generalsettings.Cameramaintenance.text");
}
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(20, 43);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(65, 12);
this.label1.TabIndex = 0;
this.label1.Text = "相机型号:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(8, 75);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(77, 12);
this.label2.TabIndex = 1;
this.label2.Text = "像素点尺寸:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(81, 40);
this.textBox1.MaxLength = 10;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(160, 21);
this.textBox1.TabIndex = 3;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(81, 72);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(160, 21);
this.textBox2.TabIndex = 4;
this.textBox2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox2_KeyPress);
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(-1, 136);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(287, 12);
this.label5.TabIndex = 7;
this.label5.Text = "-----------------------------------------------";
//
// button1
//
this.button1.Location = new System.Drawing.Point(98, 165);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(80, 30);
this.button1.TabIndex = 8;
this.button1.Text = "确定";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(189, 165);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(80, 30);
this.button2.TabIndex = 9;
this.button2.Text = "取消";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(247, 75);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(29, 12);
this.label4.TabIndex = 10;
this.label4.Text = "微米";
//
// CameraSettingsAddDialog
//
this.ClientSize = new System.Drawing.Size(284, 208);
this.Controls.Add(this.label4);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label5);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "CameraSettingsAddDialog";
this.Text = "相机维护";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
///
/// 格式限制
///
///
///
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
e.Handled = true;
//小数点的处理
if ((int)e.KeyChar == 46)
{
if (textBox2.Text.Length <= 0)
e.Handled = true; //小数点不能在第一位
else
{
float f;
float oldf;
bool b1 = false, b2 = false;
b1 = float.TryParse(textBox2.Text, out oldf);
b2 = float.TryParse(textBox2.Text + e.KeyChar.ToString(), out f);
if (b2 == false)
{
if (b1 == true)
e.Handled = true;
else
e.Handled = false;
}
}
}
}
///
/// 格式限制
///
///
///
//private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
//{
// if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
// e.Handled = true;
// //小数点的处理
// if ((int)e.KeyChar == 46)
// {
// if (textBox3.Text.Length <= 0)
// e.Handled = true; //小数点不能在第一位
// else
// {
// float f;
// float oldf;
// bool b1 = false, b2 = false;
// b1 = float.TryParse(textBox3.Text, out oldf);
// b2 = float.TryParse(textBox3.Text + e.KeyChar.ToString(), out f);
// if (b2 == false)
// {
// if (b1 == true)
// e.Handled = true;
// else
// e.Handled = false;
// }
// }
// }
//}
/////
///// textbox1获得焦点
/////
/////
/////
//private void Textbox1_Enter(object sender, EventArgs e)
//{
// if (textbox1HasText == false)
// this.textBox1.Text = "";
// this.textBox1.ForeColor = Color.Black;
//}
/////
///// textbox1失去焦点
/////
/////
/////
//private void Textbox1_Leave(object sender, EventArgs e)
//{
// if (this.textBox1.Text == "")
// {
// this.textBox1.Text = "请输入相机型号";
// this.textBox1.ForeColor = Color.LightGray;
// textbox1HasText = false;
// }
// else
// textbox1HasText = true;
//}
/////
///// textbox2获得焦点
/////
/////
/////
//private void Textbox2_Enter(object sender, EventArgs e)
//{
// if (textbox2HasText == false)
// this.textBox2.Text = "";
// this.textBox2.ForeColor = Color.Black;
//}
/////
///// textbox2失去焦点
/////
/////
/////
//private void Textbox2_Leave(object sender, EventArgs e)
//{
// if (this.textBox2.Text == "")
// {
// this.textBox2.Text = "请输入感光软件边长";
// this.textBox2.ForeColor = Color.LightGray;
// textbox2HasText = false;
// }
// else
// textbox2HasText = true;
//}
/////
///// textbox3获得焦点
/////
/////
/////
//private void Textbox3_Enter(object sender, EventArgs e)
//{
// if (textbox3HasText == false)
// this.textBox3.Text = "";
// this.textBox3.ForeColor = Color.Black;
//}
/////
///// textbox3失去焦点
/////
/////
/////
//private void Textbox3_Leave(object sender, EventArgs e)
//{
// if (this.textBox3.Text == "")
// {
// this.textBox3.Text = "请输入边长分辨率";
// this.textBox3.ForeColor = Color.LightGray;
// textbox3HasText = false;
// }
// else
// textbox3HasText = true;
//}
///
/// 确认按钮
///
///
///
private void button1_Click(object sender, EventArgs e)
{
var id = pointId;
if (string.IsNullOrEmpty(textBox1.Text))
{
MessageBox.Show(PdnResources.GetString("Menu.Cameramodelplease.Text"));
return;
}
else if (string.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterthsidelengthofphotosensitiveso.Text"));
return;
}
//else if (string.IsNullOrEmpty(textBox3.Text))
//{
// MessageBox.Show(PdnResources.GetString("Menu.leaseenterthesidelengthr.Text"));
// return;
//}
if (string.IsNullOrEmpty(id))
{
var point = new mic_camerasettings();
point.delete_flag = 2;
point.camera_model = textBox1.Text;
point.pixel_size = textBox2.Text;
//point.resolution = textBox3.Text;
mic_camerasettings_BLL.Add(point);
fatherListView.BeginUpdate();
var lv = new ListViewItem();
lv.Text = "2";
lv.SubItems.Add("×");
lv.SubItems.Add(point.camera_model);
lv.SubItems.Add(point.pixel_size);
//lv.SubItems.Add(point.resolution);
lv.Tag = point.id;
fatherListView.Items.Add(lv);
fatherListView.EndUpdate();
}
else
{
var point = mic_camerasettings_BLL.FindDefault(Convert.ToInt32(pointId));
var screenRulesId = config.Camera;
if (point == null)
{
MessageBox.Show(PdnResources.GetString("Menu.Abnormalinformatio.Text"));
}
point.camera_model = textBox1.Text;
point.pixel_size = textBox2.Text;
//point.resolution = textBox3.Text;
mic_camerasettings_BLL.Update(point);
fatherListView.BeginUpdate();
var lv = fatherListView.Items[listIndex];
lv.SubItems[1].Text = screenRulesId == int.Parse(id.ToString()) ? "√" : "×";
lv.SubItems[2].Text = point.camera_model;
lv.SubItems[3].Text = point.pixel_size;
//lv.SubItems[4].Text = point.resolution;
fatherListView.EndUpdate();
}
Close();
}
private ConfigModel config = Startup.instance.configModel;
///
///取消按钮
///
///
///
private void button2_Click(object sender, EventArgs e)
{
Hide();
}
}
}