Beispiel #1
0
        private void gvAssetList_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            try
            {
                if (e.Column.Caption == "Edit")
                {
                    Int64 nKitID = 0;
                    var   row    = gvAssetList.GetFocusedDataRow();

                    lblKitAssetID.Text    = Convert.ToString(row[1]);
                    lblKitID.Text         = Convert.ToString(row[2]);
                    lblAssetID.Text       = Convert.ToString(row[3]);
                    lblAssetCodeID.Text   = Convert.ToString(row[4]);
                    lblAssetCodeName.Text = Convert.ToString(row[7]);
                    DataTable dtAssetList = (DataTable)cmbAssetList.DataSource;
                    DataRow   drAsset     = dtAssetList.NewRow();
                    drAsset["nAssetCodeID"]   = lblAssetCodeID.Text;
                    drAsset["sAssetCodeName"] = Convert.ToString(row[7]);
                    dtAssetList.Rows.InsertAt(drAsset, 0);

                    cmbAssetList.DataSource    = dtAssetList;
                    cmbAssetList.DisplayMember = "sAssetCodeName";
                    cmbAssetList.ValueMember   = "nAssetCodeID";
                    cmbAssetList.SelectedIndex = 0;
                    btnAddAsset.Text           = "Edit";
                }
                if (e.Column.Caption == "Delete")
                {
                    var row = gvAssetList.GetFocusedDataRow();
                    int n   = Convert.ToString(gvAssetList.GetRowCellValue(e.RowHandle, "IsUsed")) == "" || Convert.ToString(gvAssetList.GetRowCellValue(e.RowHandle, "IsUsed")) == "0" ? 0 : 1;

                    if (n == 1)
                    {
                        return;
                    }
                    if (Convert.ToInt64(lblKitID.Text) > 0)
                    {
                        Int64    nKitAssetID = Convert.ToInt64(row["nKitAssetID"]);
                        KitAsset oKitAsset   = new KitAsset();
                        oKitAsset.nKitAssetID = nKitAssetID;
                        if (oKitAsset.DeleteKitAsset() > 0)
                        {
                            MessageBox.Show("Asset code deleted successfully.", clsGlobal.MessageboxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Asset code not deleted.", clsGlobal.MessageboxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        FillAssetCode(Convert.ToInt64(lblKitID.Text));

                        if (oKitAsset != null)
                        {
                            oKitAsset.Dispose();
                            oKitAsset = null;
                        }
                    }
                    else
                    {
                        Int64     nAssetCodeID = Convert.ToInt64(row["nAssetCodeID"]);
                        DataRow[] drDelete     = dtAssetCode.Select("nAssetCodeID=" + Convert.ToInt64(nAssetCodeID));
                        foreach (DataRow dr in drDelete)
                        {
                            dr.Delete();
                        }
                        dtAssetCode.AcceptChanges();
                        int nRow = 0;
                        foreach (DataRow dr in dtAssetCode.Rows)
                        {
                            nRow++;
                            dr["RowNo"] = nRow;
                        }
                        //gvAssetList.GridControl.DataSource = dtAssetCode;
                        //gvAssetList.RefreshData();
                    }
                    gvAssetList.GridControl.DataSource = dtAssetCode;
                    gvAssetList.RefreshData();
                    FillAllAsset();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error : " + ex, clsGlobal.MessageboxCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }