コード例 #1
0
    protected void dgCitys_DeleteCommand(object source, DataGridCommandEventArgs e)
    {
        int        iCityID     = Convert.ToInt32(dgCitys.DataKeys[e.Item.ItemIndex].ToString());
        CityMaster oCityMaster = new CityMaster();
        CityDTO    oCityData   = new CityDTO();

        oCityData.CityId = iCityID;
        oCityMaster.Delete(oCityData);
        txtCityName.Text = "";
        txtCityCode.Text = "";
        RefreshGrid();
        oCityData   = null;
        oCityMaster = null;
    }
コード例 #2
0
    private void Delete()
    {
        if (!base.ValidateIfCommandAllowed(Request.Url.AbsoluteUri, ENums.PageCommand.Delete))
        {
            return;
        }

        if (ValidateValues() == false)
        {
            return;
        }
        bool bActionCompleted = false;
        int  Id = 0;

        int.TryParse(hfId.Value, out Id);
        if (Id == 0)
        {
            lblStatus.Text = "Please click on edit button again.";
            return;
        }
        CityMaster oCityMaster = new CityMaster();
        CityDTO    oCityData   = new CityDTO();

        oCityData.CityId = Id;

        /*
         *
         * CHECK IF THE CITY WHICH IS TO BE DELETED HAS ANY ASSOCIATED RECORDS...IF YES, MOVE OUT OF THE FUNCTION ELSE PROCEED
         * IF THE OUTPUT OF sMessage IS "", THEN RECORD CAN BE DELETED, ELSE NOT
         *
         */
        string sMessage = "";

        GF.HasRecords(Convert.ToString(Id), "city", out sMessage);
        if (sMessage != "")
        {
            base.DisplayAlert(sMessage);
            btnDelete.Enabled = true;
        }
        else
        {
            bActionCompleted = oCityMaster.Delete(oCityData);
            if (bActionCompleted == true)
            {
                sMessage = "The record has been deleted successfully.";
                base.DisplayAlert(sMessage);
                txtCityName.Text = "";
                txtCityCode.Text = "";
                //lblStatus.Text = "Deleted";
            }
            else
            {
                sMessage = "Error Occured while deletion: Please refer to the error log.";
                base.DisplayAlert(sMessage);
            }
            //lblStatus.Text = "Error Occured while deletion: Please refer to the error log.";
        }
        RefreshGrid();
        oCityData   = null;
        oCityMaster = null;
    }