Beispiel #1
0
        protected void btDelete_Click(object sender, EventArgs e)
        {
            ArrayList     pkArray = null;
            WarehouseBLL  bll     = null;
            List <string> msgList = new List <string>();

            try
            {
                bll = BLLFactory.CreateBLL <WarehouseBLL>();

                pkArray = GvHelper.GetPKValueByChk(this.GvList, 0, "cbxSelect", 0);

                if (pkArray.Count == 0)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "myjs", "MSI('提示','请选择要删除的记录');", true);
                    return;
                }

                for (int i = 0; i < this.GvList.Rows.Count; i++)
                {
                    CheckBox cbxSelect = this.GvList.Rows[i].Cells[0].FindControl("cbxSelect") as CheckBox;

                    if (cbxSelect.Checked == false)
                    {
                        continue;
                    }

                    Warehouse site = new Warehouse();
                    site.ID          = this.GvList.DataKeys[i]["ID"].ToString();
                    site.Description = this.GvList.Rows[i].Cells[1].Text;

                    //判断是否已使用
                    bool r = bll.IsUse(site);
                    if (r == true)
                    {
                        msgList.Add(site.Description);
                        continue;
                    }

                    //删除
                    bll.Delete(site);
                }
                string msg = string.Join(",", msgList.ToArray());
                if (msg != "")
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "myjs", "MSI('提示','" + msg + "仓库已使用,无法删除');", true);
                }
                this.BindData();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        //删除
        private void button8_Click(object sender, EventArgs e)
        {
            if (dgv_Data.SelectedRows.Count <= 0)
            {
                MessageBox.Show("没有要删除的记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (MessageBox.Show("删除之后信息将不能恢复,是否确认删除?", "提示:", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    List <String> lists = new List <string>();

                    for (int i = 0; i < dgv_Data.SelectedRows.Count; i++)
                    {
                        string id = Convert.ToString(dgv_Data.SelectedRows[i].Cells[0].Value);

                        if (bll.IsUse(id)) //被使用
                        {
                            lists.Clear();
                            MessageBox.Show("该信息被使用,不能删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            break;
                        }
                        else
                        {
                            lists.Add(id);
                        }
                    }

                    if (lists.Count > 0)
                    {
                        bll.delete(lists);

                        querryList();
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("与数据库连接失败,请查看网络连接是否正常。如不能解决请与网络管理员联系!", "严重错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }