예제 #1
0
 /// <summary>
 /// 单击保存按钮
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         if (string.IsNullOrEmpty(txtWeighInfo_Name.Text.Trim()))
         {
             MessageBox.Show("请输入地磅房名称");
             return;
         }
         if (string.IsNullOrEmpty(cobWeighInfo_State.Text.Trim()))
         {
             MessageBox.Show("请选择启动状态");
             return;
         }
         if (txtRemark.Text.Trim().Length > 200)
         {
             MessageBox.Show("超过最大字符,限制200字内");
             return;
         }
         //查重
         DataSet ds = LinQBaseDao.Query("select COUNT(1) from WeighInfo where WeighInfo_Name='" + txtWeighInfo_Name.Text.Trim() + "'");
         if (Convert.ToInt32(ds.Tables[0].Rows[0][0]) > 0)
         {
             MessageBox.Show("该磅房名称已存在");
             return;
         }
         //进行新增操作
         WeighInfo info = new WeighInfo();
         info.WeighInfo_Name       = txtWeighInfo_Name.Text.Trim();
         info.WeighInfo_Phone      = txtWeighInfo_Phone.Text.Trim();
         info.WeighInfo_State      = cobWeighInfo_State.Text.Trim();
         info.WeighInfo_CreateTime = CommonalityEntity.GetServersTime();
         info.WeighInfo_Remark     = txtRemark.Text.Trim();
         if (WeighInfoDAL.InsertOneCamera(info))
         {
             MessageBox.Show("保存成功");
             CommonalityEntity.WriteLogData("新增", "新增过磅基础信息:" + txtWeighInfo_Name.Text.Trim(), CommonalityEntity.USERNAME);//添加操作日志
             Empty();
         }
         else
         {
             MessageBox.Show("保存失败");
         }
     }
     catch
     {
         Console.WriteLine("");
     }
     finally
     {
         LogInfoLoad("");
     }
 }
예제 #2
0
        /// <summary>
        /// 单击删除按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                int j = 0;                                    //删除标签
                if (this.dgvWeighInfo.SelectedRows.Count > 0) //选中行
                {
                    if (MessageBox.Show("确定要删除吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        for (int i = 0; i < dgvWeighInfo.SelectedRows.Count; i++)
                        {
                            Expression <Func <WeighInfo, bool> > funuserinfo = n => n.WeighInfo_ID == int.Parse(this.dgvWeighInfo.SelectedRows[i].Cells["WeighInfo_ID"].Value.ToString());

                            if (!WeighInfoDAL.DeleteToMany(funuserinfo))
                            {
                                j++;
                            }
                        }
                        if (j == 0)
                        {
                            MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("删除失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("请选中要删除的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch
            {
                MessageBox.Show("");
            }
            finally
            {
                LogInfoLoad("");
                Empty();
            }
        }
예제 #3
0
 /// <summary>
 /// 单击修改按钮
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnupdate_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.dgvWeighInfo.SelectedRows.Count > 0)//选中行
         {
             if (dgvWeighInfo.SelectedRows.Count > 1)
             {
                 MessageBox.Show("修改只能选中一行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 return;
             }
             else
             {
                 //进行修改
                 WeighInfo info = new WeighInfo();
                 if (string.IsNullOrEmpty(txtWeighInfo_Name.Text.Trim()))
                 {
                     MessageBox.Show("地磅房名称不能为空");
                     return;
                 }
                 if (string.IsNullOrEmpty(cobWeighInfo_State.Text.Trim()))
                 {
                     MessageBox.Show("请选择启动状态");
                     return;
                 }
                 if (dgvWeighInfo.SelectedRows[0].Cells["WeighInfo_Name"].Value.ToString() != txtWeighInfo_Name.Text.Trim())
                 {
                     //查重
                     DataSet ds = LinQBaseDao.Query("select COUNT(1) from WeighInfo where WeighInfo_Name='" + txtWeighInfo_Name.Text.Trim() + "'");
                     if (Convert.ToInt32(ds.Tables[0].Rows[0][0]) > 0)
                     {
                         MessageBox.Show("该磅房名称已存在");
                         Empty();
                         return;
                     }
                 }
                 Expression <Func <WeighInfo, bool> > p = n => n.WeighInfo_ID == int.Parse(this.dgvWeighInfo.SelectedRows[0].Cells["WeighInfo_ID"].Value.ToString());
                 Action <WeighInfo> ap = s =>
                 {
                     s.WeighInfo_Name   = txtWeighInfo_Name.Text.Trim();
                     s.WeighInfo_Phone  = this.txtWeighInfo_Phone.Text.Trim();
                     s.WeighInfo_State  = this.cobWeighInfo_State.Text.Trim();
                     s.WeighInfo_Remark = this.txtRemark.Text.Trim();
                 };
                 if (WeighInfoDAL.Update(p, ap))
                 {
                     MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     Empty();
                 }
                 else
                 {
                     MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 }
             }
         }
     }
     catch
     {
         CommonalityEntity.WriteTextLog("地磅房信息管理 btnupdate_Click()" + "".ToString());
     }
     finally
     {
         LogInfoLoad("");
     }
 }