Beispiel #1
0
        public ICollection Update(ICollection instance, decimal?value, decimal?offset)
        {
            using (var cmd = new DBCommand())
            {
                try
                {
                    CollectionDAL.Update(cmd, instance, value, offset);

                    cmd.Commit();
                    return(instance);
                }
                catch (Exception ex)
                {
                    cmd.RollBack();
                    using (var builder = new MessageBuilder())
                    {
                        string err = builder.AppendLine("更新付费信息错误!").AppendLine(ex).Message;
                        throw new Exception(err);
                    }
                }
            }
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            string name = txtCollectionName.Text.Trim();

            if (string.IsNullOrEmpty(name))
            {
                MessageBox.Show(this, "采集端名称不能为空");
                return;
            }
            if (cmbClient.SelectedIndex < 0)
            {
                MessageBox.Show(this, "请选择客户端");
                return;
            }
            if (btnSave.Text == "添加")
            {
                if (ClientDAL.ISClientInfoName(name))
                {
                    MessageBox.Show(this, "采集端名称已存在");
                    return;
                }
                int            id     = 0;
                CollectionInfo client = new CollectionInfo();
                client.Collection_Name      = name;
                client.Collection_Client_ID = Convert.ToInt32(cmbClient.SelectedValue);
                client.Collection_Remark    = txtRemark.Text.Trim();

                if (CollectionDAL.InsertOneQCRecord(client))
                {
                    MessageBox.Show("添加成功!");
                    Empty();
                }
                else
                {
                    MessageBox.Show("添加失败!");
                }
            }
            else
            {
                if (cid == 0)
                {
                    return;
                }
                object obj = LinQBaseDao.GetSingle("select count(0) from CollectionInfo where Collection_ID !=" + cid + " and Collection_Name='" + name + "'");
                if (Convert.ToInt32(obj.ToString()) > 0)
                {
                    MessageBox.Show(this, "采集端名称已存在");
                    return;
                }
                Expression <Func <CollectionInfo, bool> > exp = n => n.Collection_ID == cid;
                Action <CollectionInfo> ap = s =>
                {
                    s.Collection_Name      = name;
                    s.Collection_Client_ID = Convert.ToInt32(cmbClient.SelectedValue);
                    s.Collection_Remark    = txtRemark.Text.Trim();
                };
                CollectionDAL.Update(exp, ap);
                Empty();
            }
            LoadData("");
        }