Exemple #1
0
        protected void Grid2_RowCommand(object sender, GridCommandEventArgs e)
        {
            int provinceID = GetSelectedDataKeyID(Grid1);

            object[] values = Grid2.DataKeys[e.RowIndex];
            int      cityID = Convert.ToInt32(values[0]);

            if (e.CommandName == "Delete")
            {
                // 在操作之前进行权限检查

                Infobasis.Data.DataEntity.City tobeRemoved = DB.Citys.Where(item => item.ProvinceID == provinceID && item.ID == cityID).FirstOrDefault();

                if (tobeRemoved != null)
                {
                    DB.Citys.Remove(tobeRemoved);
                    DB.SaveChanges();
                }

                BindGrid2();
            }
        }
        private void SaveItem()
        {
            int id  = GetQueryIntValue("id");
            int pid = GetQueryIntValue("pid");

            if (id > 0 && pid > 0)
            {
                Infobasis.Data.DataEntity.City city = DB.Citys.Find(id);
                city.Name           = tbxName.Text.Trim();
                city.Code           = ChinesePinyin.GetFirstPinyin(city.Name);
                city.IsActive       = tbxIsActive.Checked;
                city.DisplayOrder   = Change.ToInt(tbxDisplayOrder.Text);
                city.CreateDatetime = DateTime.Now;
            }
            else if (pid > 0)
            {
                Infobasis.Data.DataEntity.City item = new Infobasis.Data.DataEntity.City();
                item.ProvinceID         = pid;
                item.Name               = tbxName.Text.Trim();
                item.Code               = ChinesePinyin.GetFirstPinyin(item.Name);
                item.IsActive           = tbxIsActive.Checked;
                item.DisplayOrder       = Change.ToInt(tbxDisplayOrder.Text);
                item.LastUpdateDatetime = DateTime.Now;

                DB.Citys.Add(item);
            }
            else
            {
                Province item = new Province();
                item.Name               = tbxName.Text.Trim();
                item.Code               = ChinesePinyin.GetFirstPinyin(item.Name);
                item.IsActive           = tbxIsActive.Checked;
                item.LastUpdateDatetime = DateTime.Now;
                item.DisplayOrder       = Change.ToInt(tbxDisplayOrder.Text);
                DB.Provinces.Add(item);
            }
            DB.SaveChanges();
        }
        private void LoadData()
        {
            btnClose.OnClientClick = ActiveWindow.GetHideReference();
            int id  = GetQueryIntValue("id");
            int pid = GetQueryIntValue("pid");

            if (pid > 0)
            {
                Province province = DB.Provinces.Find(pid);
                if (province == null)
                {
                    // 参数错误,首先弹出Alert对话框然后关闭弹出窗口
                    Alert.Show("参数错误!", String.Empty, ActiveWindow.GetHideReference());
                    return;
                }
            }

            if (id > 0)
            {
                Infobasis.Data.DataEntity.City city = DB.Citys.Find(id);
                if (pid > 0)
                {
                    tbxName.Text         = city.Name;
                    tbxCode.Text         = city.Code;
                    tbxIsActive.Checked  = city.IsActive;
                    tbxDisplayOrder.Text = city.DisplayOrder.ToString();
                }
                else
                {
                    Province province = DB.Provinces.Find(pid);
                    tbxName.Text         = province.Name;
                    tbxCode.Text         = province.Code;
                    tbxIsActive.Checked  = province.IsActive;
                    tbxDisplayOrder.Text = province.DisplayOrder.ToString();
                }
            }
        }