private void ultraGrid1_BeforeExitEditMode(object sender, BeforeExitEditModeEventArgs e)
        {
            /// Validation for PeriodStartDate (Date picker)
            UltraGridCell objCell = this.ultraGrid1.ActiveCell;

            if (objCell == null)
            {
                return;
            }
            //   Get the UIElement associated with the active cell, which we will
            //   need so we can get the size and location of the cell
            if (objCell.IsDataCell && objCell.Column.Key == "PeriodStartDate" && objCell.Text.ToString()[0] != '_')
            {
                // Make sure date is not in the future
                //if (Regex.IsMatch(objCell.Text.ToString(), @"\d+\/\d+\/\d+"))
                //{
                DateTime newDate = DateTime.Parse(objCell.Text);
                if (objCell.Value.ToString() != "")
                {
                    DateTime oldDate = DateTime.Parse(objCell.Value.ToString());
                    if (oldDate.Month == newDate.Month && oldDate.Year == oldDate.Year)
                    {
                        return;
                    }
                }
                if (newDate > DateTime.Now)
                {
                    MessageBox.Show("Future data is not allowed!", "Data Entry Error");
                    objCell.Selected = true;
                    e.Cancel         = true;
                    return;
                }
                // Not in the future - now
                // Correct entered date to be first day of the month
                newDate = DateTime.Parse(newDate.ToString("yyyy/MM/" + "01 00:00:00"));
                DateTime firstdayofnextmonth = newDate.AddMonths(1);
                // Make sure that the month being entered does not already exist
                string sql = "SELECT * FROM Financials WHERE (PeriodStartDate >= #"
                             + newDate.ToString("yyyy/MM/") + "01 00:00:00#) AND (PeriodStartDate < #"
                             + firstdayofnextmonth.ToString("yyyy/MM/") + "01 00:00:00#) AND SiteID = " + VWA4Common.GlobalSettings.CurrentSiteID;
                DataTable dt_result = VWA4Common.DB.Retrieve(sql);
                if (dt_result.Rows.Count > 0)
                {     // duplicate
                    MessageBox.Show("Financial data already exists for specified month!", "Data Entry Error");
                    e.Cancel = true;
                    return;
                }
                // We have passed the tests - update cell with new value
                ultraGrid1.ActiveCell.Value = newDate;
                //}
            }
        }
Exemple #2
0
        private void listaBeforeExitEditMode(object sender, BeforeExitEditModeEventArgs e)
        {
            if (lista.ActiveCell.Column.Key == "DirittoReale" || lista.ActiveCell.Column.Key == "ModalitaConvocazione")
            {
                var valoreAttuale = lista.ActiveCell.Text;
                if (!string.IsNullOrEmpty(valoreAttuale) && lista.DisplayLayout.ValueLists[lista.ActiveCell.Column.Key].FindStringExact(valoreAttuale) == -1)
                    e.Cancel = true;
                else
                    e.Cancel = false;
            }

            if (lista.ActiveCell.Column.Key == "NumeratorePossesso" || lista.ActiveCell.Column.Key == "DenominatorePossesso")
            {
                var soggetto = lista.ActiveCell.Row.ListObject as SoggettoCondominioDTO;
                if (soggetto != null)
                {
                    if(!string.IsNullOrEmpty(lista.ActiveCell.Row.Cells["NumeratorePossesso"].Text) && !string.IsNullOrEmpty(lista.ActiveCell.Row.Cells["DenominatorePossesso"].Text))
                        soggetto.Possesso = string.Format("{0}/{1}", lista.ActiveCell.Row.Cells["NumeratorePossesso"].Text, lista.ActiveCell.Row.Cells["DenominatorePossesso"].Text);
                    else
                        soggetto.Possesso = string.Empty;
                }
            }
        }