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 DevExpress.XtraLayout;
using ProjectBase.Data.Logs;
using SIMDP.Model;
using ProjectBase.Data.BaseDAL;
using SIMDP.BLL;
namespace SIMDP
{
public partial class FormEditDataManage : DevExpress.XtraEditors.XtraForm
{
//
///
/// 修改的数据
///
public DataRow row { get; set; }
///
/// 规则列表
///
public DataTable dtRule { get; set; }
public string ruleId { get; set; }
private List txtList = new List(); //动态生成的textEdit
public FormEditDataManage()
{
InitializeComponent();
}
private void FormEditDataManage_Load(object sender, EventArgs e)
{
InitControls();
}
private void InitControls()
{
this.layoutControl1.BeginUpdate();
this.layoutControlItem2.Text = dtRule.Rows[0].Field("Name") + ":";
this.textEditName.Text = row[3].ToString();
this.layoutControl1.EndUpdate();
for (int i = 1; i < dtRule.Rows.Count; i++)
{
DrawControls( i);
}
}
private void btn_Cancel_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 动态创建控件
///
///
private void DrawControls(int i)
{
try
{
int y = 26 + 24 * i;
this.layoutControl1.BeginUpdate();
DevExpress.XtraEditors.TextEdit textName = new TextEdit();
textName.Location = new System.Drawing.Point(84, 38);
textName.Name = "txtRulesName" + i.ToString();
textName.Size = new System.Drawing.Size(186, 20);
textName.StyleController = this.layoutControl1;
textName.Text = row[3 + i].ToString();
this.layoutControl1.Controls.Add(textName);
txtList.Add(textName);
DevExpress.XtraLayout.LayoutControlItem layout1 = new DevExpress.XtraLayout.LayoutControlItem();
layout1.Control = textName;
layout1.Location = new System.Drawing.Point(0, y);
//layout1.MaxSize = new System.Drawing.Size(150, 24);
//layout1.MinSize = new System.Drawing.Size(80, 24);
layout1.Name = "layout" + (i + 3).ToString();
layout1.Size = new System.Drawing.Size(262, 24);
//layout1.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
layout1.Text = dtRule.Rows[i].Field("Name") + ":";
//layout1.TextAlignMode = TextAlignModeItem.AutoSize;
layout1.TextSize = new System.Drawing.Size(69, 14);
this.layoutControlGroup1.Items.AddRange(new DevExpress.XtraLayout.BaseLayoutItem[] { layout1 });
this.layoutControl1.EndUpdate();
}
catch (Exception ex)
{
LogHelper.log.Error(string.Format("动态创建控件出现错误:{0}", ex));
}
}
private void btn_Save_Click(object sender, EventArgs e)
{
try
{
FormUserVerification form = new FormUserVerification();
form.ShowDialog();
if (form.DialogResult != DialogResult.OK)
{
DevExpress.XtraEditors.XtraMessageBox.Show("用户验证失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
MoProductData mo = new MoProductData();
mo.DataId = Convert.ToInt64(row[0]);
mo.RuleId = Convert.ToInt64(ruleId) ;
mo.RuleTime = Convert.ToDateTime(row[1]);
mo.Batchid = row[2].ToString();
string str = this.textEditName.Text;
for (int i = 0; i < txtList.Count; i++)
{
str += "," + txtList[i].Text;
}
mo.DataValue = str;
bool flag = BLLFactory.Instance.Update(mo,mo.DataId);
if (flag)
{
DevExpress.XtraEditors.XtraMessageBox.Show("保存成功。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
else
{
DevExpress.XtraEditors.XtraMessageBox.Show("保存失败。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
catch (Exception ex)
{
DevExpress.XtraEditors.XtraMessageBox.Show("保存失败。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
LogHelper.log.Error(string.Format("修改数据库product_data出现错误:{0}", ex));
}
}
}
}