123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- 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
- {
- //
- /// <summary>
- /// 修改的数据
- /// </summary>
- public DataRow row { get; set; }
- /// <summary>
- /// 规则列表
- /// </summary>
- public DataTable dtRule { get; set; }
- public string ruleId { get; set; }
- private List<TextEdit> txtList = new List<TextEdit>(); //动态生成的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<string>("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();
- }
- /// <summary>
- /// 动态创建控件
- /// </summary>
- /// <param name="i"></param>
- 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<string>("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<BlProductData>.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));
- }
- }
- }
- }
|