private void form_save_Click(object sender, EventArgs e)
 {
     if (materialType == null)
     {
         MaterialTypeManager mtm          = new MaterialTypeManager();
         MaterialTypeForm    clientForm   = (MaterialTypeForm)this.Owner;
         MaterialType        materialType = new MaterialType()
         {
             MT_Code     = BuildCode.ModuleCode("MT"),
             MT_Name     = textBox1.Text.Trim(),
             MT_ParentID = matype_code,
             MT_Clear    = 1,
             MT_Enable   = 1,
             MT_ID       = 0
         };
         try
         {
             int result = mtm.Add(materialType);
             if (result > 0)
             {
                 clientForm.Isflag = true;
                 MessageBox.Show("产品类别:" + textBox1.Text + " \n添加成功");
                 Close();
             }
             else
             {
                 clientForm.Isflag = false;
                 MessageBox.Show("添加失败,请重新添加");
                 Close();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("商品插入异常:" + ex.Message);
             Close();
         }
     }
     else
     {
         MaterialTypeManager mtm = new MaterialTypeManager();
         try
         {
             if (mtm.UpdateByCode(materialType))
             {
                 MessageBox.Show("更改成功!");
                 Close();
             }
             else
             {
                 MessageBox.Show("更改失败,请检查服务器连接");
                 Close();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("更改错误,请检查服务器连接.异常:" + ex.Message);
             Close();
         }
     }
 }
 private void form_save_Click(object sender, EventArgs e)
 {
     if (_MaterialType == null)
     {
         MaterialType materialType = new MaterialType()
         {
             MT_Name     = textBox1.Text.Trim(),
             MT_ParentID = _MType_Code,
             MT_Clear    = 1,
             MT_Enable   = 1,
             MT_Code     = BuildCode.ModuleCode("MT")
         };
         try
         {
             int          result       = mtm.Add(materialType);
             MaterialForm materialForm = (MaterialForm)this.Owner;
             if (result > 0)
             {
                 materialForm.Isflag = true;
                 MessageBox.Show("地区名称:" + textBox1.Text + " \n添加成功");
                 Close();
             }
             else
             {
                 materialForm.Isflag = false;
                 MessageBox.Show("添加失败,请重新添加");
                 Close();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("新增地区资料错误,请检查服务器连接.错误信息:" + ex.Message);
         }
     }
     else
     {
         _MaterialType.MT_Name = textBox1.Text.Trim();
         try
         {
             bool result = mtm.UpdateByCode(_MaterialType);
             if (result)
             {
                 MaterialForm materialForm = (MaterialForm)this.Owner;
                 materialForm.Isflag = true;
                 MessageBox.Show("地区名称:" + textBox1.Text + " \n修改成功");
                 Close();
             }
             else
             {
                 MaterialForm materialForm = (MaterialForm)this.Owner;
                 materialForm.Isflag = false;
                 MessageBox.Show("修改失败,请重新修改");
                 Close();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("新增地区资料错误,请检查服务器连接.错误信息:" + ex.Message);
         }
     }
 }