コード例 #1
0
        private void btnToolAdd_Click(object sender, EventArgs e)
        {
            try
            {
                //
                //表格新增
                //int index = this.dataGridViewTool.Rows.Add();
                //this.dataGridViewTool.Rows[index].Cells[0].Value = txtToolNo.Text;
                //this.dataGridViewTool.Rows[index].Cells[1].Value = txtToolName.Text;
                //this.dataGridViewTool.Rows[index].Cells[2].Value = txtToolAddress.Text;
                //this.dataGridViewTool.Rows[index].Cells[3].Value = txtToolPic.Text;
                //this.dataGridViewTool.Refresh();
                //数据库新增
                tool tool = new tool();
                tool.No      = txtToolNo.Text.Trim();
                tool.name    = txtToolName.Text.Trim();
                tool.address = txtToolAddress.Text.Trim();
                tool.picture = txtToolPic.Text.Trim();
                tool.x       = rectengle.Split(',')[0];
                tool.y       = rectengle.Split(',')[1];
                tool.w       = rectengle.Split(',')[2];
                tool.h       = rectengle.Split(',')[3];

                if (check_tool(tool))
                {
                    //List<tool> listTool = new List<tool>();
                    listTool.Add(tool);
                    DataTable dataTable = Common.FillDataTable <tool>(listTool);
                    dataGridViewTool.DataSource = dataTable;
                    DBSet.dataTableToCsvT(dataTable, @"..\tool.csv");
                }
                rectengle = "";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
 public bool check_tool(tool tool)
 {
     if (string.IsNullOrEmpty(tool.No))
     {
         MessageBox.Show("编号不能为空");
         return(false);
     }
     if (string.IsNullOrEmpty(tool.name))
     {
         MessageBox.Show("物品名称不能为空");
         return(false);
     }
     if (string.IsNullOrEmpty(tool.address))
     {
         MessageBox.Show("存储位置不能为空");
         return(false);
     }
     //if (string.IsNullOrEmpty(tool.picture))
     //{
     //    MessageBox.Show("物品图片不能为空");
     //}
     return(true);
 }
コード例 #3
0
        private void btn_save_device_Click(object sender, EventArgs e)
        {
            try
            {
                tool tool = new tool();
                tool.name    = txtToolNo.Text.Trim();
                tool.No      = txtToolName.Text.Trim();
                tool.address = txtToolAddress.Text.Trim();
                tool.picture = txtToolPic.Text.Trim();
                this.config.listTool.RemoveAt(this.config.num);
                this.config.listTool.Add(tool);

                DataTable dataTable = Common.FillDataTable <tool>(this.config.listTool);
                DBSet.dataTableToCsvT(dataTable, @"..\tool.csv");

                MessageBox.Show("保存成功");
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }