Ejemplo n.º 1
0
        void grdPaymentHistory_CommandCellClick(object sender, EventArgs e)
        {
            try
            {
                GridCommandCellElement gridCell = (GridCommandCellElement)sender;
                if (gridCell.ColumnInfo.Name.ToLower() == "btndelete")
                {
                    if (DialogResult.Yes == RadMessageBox.Show("Are you sure you want to delete a Record ? ", "", MessageBoxButtons.YesNo, RadMessageIcon.Question))
                    {
                        long Id = grdPaymentHistory.CurrentRow.Cells["Id"].Value.ToLong();
                        if (grdPaymentHistory.CurrentRow != null && grdPaymentHistory.CurrentRow is GridViewDataRowInfo)
                        {
                            if (grdPaymentHistory.Rows.Count > 1 && Id < grdPaymentHistory.Rows.Where(c => c.Index != grdPaymentHistory.CurrentRow.Index)
                                .OrderByDescending((c => c.Cells["Id"].Value.ToLong())).FirstOrDefault().Cells["Id"].Value.ToLong())
                            {
                                ENUtils.ShowMessage("Expenses History will be Delete in Reverse Order");
                                return;
                            }
                        }

                        string  Type           = grdPaymentHistory.CurrentRow.Cells[COLS.Type].Value.ToStr().ToLower();
                        decimal Amount         = grdPaymentHistory.CurrentRow.Cells[COLS.Amount].Value.ToDecimal();
                        decimal CurrentBalance = numCurrBalance.Value.ToDecimal();
                        grdPaymentHistory.CurrentRow.Delete();
                        if (Type == "credit")
                        {
                            //if (CurrentBalance > 0)
                            //{
                            numCurrBalance.Value = (CurrentBalance + Amount);
                        }
                        else
                        {
                            //if (CurrentBalance > 0)
                            //{
                            numCurrBalance.Value = (CurrentBalance - Amount);
                        }
                        objDriverCommision.GetByPrimaryKey(CommissionId);
                        objDriverCommision.Edit();
                        objDriverCommision.Current.Balance = numCurrBalance.Value.ToDecimal();

                        objDriverCommision.Save();
                        using (TaxiDataContext db = new TaxiDataContext())
                        {
                            var query = db.Fleet_DriverCommissionExpenses.Single(c => c.Id == Id);
                            db.Fleet_DriverCommissionExpenses.DeleteOnSubmit(query);
                            db.SubmitChanges();
                        }
                        DisplayRecord();
                    }
                }
            }
            catch (Exception ex)
            {
                ENUtils.ShowMessage(ex.Message);
            }
        }
        void Grid_RowsChanging(object sender, GridViewCollectionChangingEventArgs e)
        {
            if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Remove)
            {
                objMaster = new DriverCommisionBO();

                try
                {
                    objMaster.GetByPrimaryKey(grdLister.CurrentRow.Cells["Id"].Value.ToInt());

                    string Transaction = grdLister.CurrentRow.Cells["TransNo"].Value.ToStr();
                    int    DriverId    = grdLister.CurrentRow.Cells["DriverID"].Value.ToInt();

                    var query = General.GetQueryable <Fleet_DriverCommision>(c => c.DriverId == DriverId).OrderByDescending(c => c.Id).FirstOrDefault();

                    if (query != null)
                    {
                        string Transno = query.TransNo.ToStr();

                        if (Transno == Transaction)
                        {
                            objMaster.Delete(objMaster.Current);
                        }
                        else
                        {
                            ENUtils.ShowMessage("You Can not delete a record..");
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (objMaster.Errors.Count > 0)
                    {
                        ENUtils.ShowMessage(objMaster.ShowErrors());
                    }
                    else
                    {
                        ENUtils.ShowMessage(ex.Message);
                    }
                    e.Cancel = true;
                }
            }
        }