public static bool CheckReviewCompatibility(EbWebForm webForm)
        {
            if (webForm.TableRowId <= 0)
            {
                throw new FormException("Bad Request. [34]", (int)HttpStatusCode.BadRequest, "Review operation failed due to invalid data id", "EbReviewHelper -> CheckReviewCompatibility");
            }

            EbReview ebReview = (EbReview)webForm.FormSchema.ExtendedControls.Find(e => e is EbReview);

            if (ebReview == null)
            {
                throw new FormException("Review control not found! Contact Admin.", (int)HttpStatusCode.BadRequest, "check the form refid and review control", "EbReviewHelper -> CheckReviewCompatibility");
            }
            bool ok = false;

            if (webForm.FormData?.MultipleTables.ContainsKey(ebReview.TableName) == true)
            {
                SingleTable Table = webForm.FormData.MultipleTables[ebReview.TableName];
                if (Table != null && Table.Count > 0)
                {
                    Table.RemoveAll(e => e.RowId > 0);
                    if (Table.Count == 1)
                    {
                        ok = true;
                    }
                }
            }
            if (!ok)
            {
                throw new FormException("Bad review request", (int)HttpStatusCode.BadRequest, "check the form refid and review control", "EbReviewHelper -> CheckReviewCompatibility");
            }
            return(true);
        }
Beispiel #2
0
        public static FG_Root GetCSharpFormGlobals_NEW(EbWebForm _this, WebformData _formdata, WebformData _formdataBkUp, IDatabase DataDB, DbConnection DbCon, bool isSrcForm)
        {
            FG_User   fG_User   = new FG_User(_this.UserObj.UserId, _this.UserObj.FullName, _this.UserObj.Email, _this.UserObj.Roles);
            FG_System fG_System = new FG_System();
            FG_DataDB fG_DataDB = null;

            if (DataDB != null)
            {
                DelegateTest OutDelObj = new DelegateTest(DataDB, DbCon);
                fG_DataDB = new FG_DataDB(OutDelObj.ExecuteScalar);
            }
            WebformData _formdataEmpty = _this.GetEmptyModel();

            if (_formdata == null)
            {
                _formdata = _formdataEmpty;
            }
            else
            {
                _formdata.DGsRowDataModel = _formdataEmpty.DGsRowDataModel;
            }
            FG_Locations fG_Locations = Get_FG_Locations(_this.SolutionObj.Locations);
            int          createdBy    = _this.TableRowId <= 0 ? _this.UserObj.UserId : _formdata.CreatedBy;
            string       createdAt    = _this.TableRowId <= 0 ? DateTime.UtcNow.ConvertFromUtc(_this.UserObj.Preference.TimeZone).ToString(FormConstants.yyyyMMdd_HHmmss, CultureInfo.InvariantCulture) : _formdata.CreatedAt;
            FG_WebForm   fG_WebForm   = new FG_WebForm(_this.TableName, _this.TableRowId, _this.LocationId, _this.RefId, createdBy, createdAt);

            GetCSharpFormGlobalsRec_NEW(fG_WebForm, _this, _formdata, _formdataBkUp);

            return(new FG_Root(fG_WebForm, fG_User, fG_System, isSrcForm, fG_DataDB, fG_Locations));
        }
        internal EbReviewHelper_inner(EbWebForm webForm, IDatabase DataDB, List <DbParameter> param, bool isInsert, Service service)
        {
            this.ebReview = (EbReview)webForm.FormSchema.ExtendedControls.FirstOrDefault(e => e is EbReview);
            if (this.ebReview == null || this.ebReview.FormStages.Count == 0)
            {
                this.ReviewNotFound = true;
                return;
            }

            this.webForm  = webForm;
            this.DataDB   = DataDB;
            this.param    = param;
            this.isInsert = isInsert;
            this.service  = service;
            this.globals  = null;

            if (this.webForm.FormData?.MultipleTables.ContainsKey(this.ebReview.TableName) == true)
            {
                this.Table = this.webForm.FormData.MultipleTables[this.ebReview.TableName];
            }
            else
            {
                this.Table = new SingleTable();
            }

            if (this.webForm.FormDataBackup?.MultipleTables.ContainsKey(this.ebReview.TableName) == true)
            {
                this.TableBkUp = this.webForm.FormDataBackup.MultipleTables[this.ebReview.TableName];
            }
            else
            {
                this.TableBkUp = new SingleTable();
            }
        }
Beispiel #4
0
        public static _FG_WebForm GetCSharpFormGlobals(EbWebForm _this, WebformData _formdata)
        {
            _FG_WebForm fG_WebForm = new _FG_WebForm();

            GetCSharpFormGlobalsRec(fG_WebForm, _this, _formdata);
            return(fG_WebForm);
        }
 public PsDmHelper(EbWebForm ebForm, List <EbControl> drPsList, WebformData _FormData, Service service)
 {
     this.ebForm    = ebForm;
     this.drPsList  = drPsList;
     this._FormData = _FormData;
     this.service   = service;
 }
Beispiel #6
0
 public static void InsertOrUpdateAsync(IDatabase DataDB, EbWebForm _webForm, Service service)
 {
     Task.Run(() =>
     {
         try
         {
             Console.WriteLine("EbWebForm.Save.InsertOrUpdate Global Search Async start");
             _webForm.DbConnection = null;
             _webForm.RefreshFormData(DataDB, service, false, false);
             string _data = GetJsonData(_webForm);
             if (string.IsNullOrEmpty(_data))
             {
                 if (ExistsIndexControls(_webForm))
                 {
                     Delete(DataDB, _webForm.RefId, _webForm.TableRowId);
                 }
             }
             else
             {
                 InsertOrUpdate(DataDB, _data, _webForm.RefId, _webForm.TableRowId, _webForm.UserObj.UserId, _webForm.DisplayName);
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine($"Exception in async insert/update global search data. Message: {ex.Message}\nStackTrace: {ex.StackTrace}");
         }
     });
 }
Beispiel #7
0
        public static string GetJsonData(EbWebForm _webForm)
        {
            if (_webForm.FormData == null)
            {
                return(string.Empty);
            }
            Dictionary <string, string> _data = new Dictionary <string, string>();

            foreach (TableSchema _table in _webForm.FormSchema.Tables)
            {
                if (_webForm.FormData.MultipleTables.TryGetValue(_table.TableName, out SingleTable Table))
                {
                    if (_table.TableType == WebFormTableTypes.Normal || _table.TableType == WebFormTableTypes.Grid)
                    {
                        foreach (SingleRow Row in Table)
                        {
                            foreach (SingleColumn Column in Row.Columns.FindAll(e => e.Control?.Index == true))
                            {
                                AddValue(_data, Column);
                            }
                        }
                    }
                }
            }
            if (_data.Count == 0)
            {
                return(string.Empty);
            }
            return(JsonConvert.SerializeObject(_data));
        }
Beispiel #8
0
        public static string GetInsertQuery_Batch(EbWebForm _this, IDatabase DataDB, string tblName)
        {
            EbSystemColumns    ebs  = _this.SolutionObj.SolutionSettings.SystemColumns;
            EbDataPusherConfig conf = _this.DataPusherConfig;
            string             _qry;

            if (tblName.Equals(_this.TableName))
            {
                _qry = $@"
INSERT INTO {tblName} 
    ({{0}} 
    {ebs[SystemColumns.eb_created_by]}, 
    {ebs[SystemColumns.eb_created_at]}, 
    {ebs[SystemColumns.eb_loc_id]}, 
    {ebs[SystemColumns.eb_ver_id]}, 
    {ebs[SystemColumns.eb_src_ver_id]}, 
    {ebs[SystemColumns.eb_src_id]}, 
    {ebs[SystemColumns.eb_push_id]}, 
    {ebs[SystemColumns.eb_lock]}, 
    {ebs[SystemColumns.eb_signin_log_id]},
    {ebs[SystemColumns.eb_ro]},
    {conf.SourceTable}_id,
    {conf.GridTableName}_id)
VALUES
    ({{1}}
    @eb_createdby,
    {DataDB.EB_CURRENT_TIMESTAMP},
    @eb_loc_id,
    @{_this.TableName}_eb_ver_id,
    @{conf.SourceTable}_eb_ver_id,
    {conf.SourceRecId},
    {(conf.MultiPushId == null ? "null" : $"'{conf.MultiPushId}'")},
Beispiel #9
0
        public static string GetDeleteQuery(EbWebForm _this, IDatabase DataDB)
        {
            string          FullQry = string.Empty;
            EbSystemColumns ebs     = _this.SolutionObj.SolutionSettings.SystemColumns;

            foreach (EbWebForm ebWebForm in _this.FormCollection)
            {
                WebFormSchema _schema = ebWebForm.FormSchema;
                foreach (TableSchema _table in _schema.Tables.FindAll(e => e.TableType != WebFormTableTypes.Review && !e.DoNotPersist))
                {
                    string autoIdBckUp = string.Empty;
                    //if (ebWebForm.AutoId != null && ebWebForm.AutoId.TableName == _table.TableName) // uncomment this and check the autoid reassignment
                    //    autoIdBckUp = string.Format(", {0}_ebbkup = {0}, {0} = CONCAT({0}, '_ebbkup')", ebWebForm.AutoId.Name);

                    string Qry = string.Format("UPDATE {0} SET {1} = {6}, {2} = @eb_lastmodified_by, {3} = {4} {5} ",
                                               _table.TableName,
                                               ebs[SystemColumns.eb_del],
                                               ebs[SystemColumns.eb_lastmodified_by],
                                               ebs[SystemColumns.eb_lastmodified_at],
                                               DataDB.EB_CURRENT_TIMESTAMP,
                                               autoIdBckUp,
                                               ebs.GetBoolTrue(SystemColumns.eb_del));

                    if (ebWebForm.DataPusherConfig == null)
                    {
                        Qry += string.Format("WHERE {0} = @{1}_id AND COALESCE({2}, {3}) = {3};",
                                             _table.TableName == _schema.MasterTable ? "id" : (_schema.MasterTable + "_id"),
                                             _schema.MasterTable,
                                             ebs[SystemColumns.eb_del],
                                             ebs.GetBoolFalse(SystemColumns.eb_del));
                    }
                    else
                    {
                        EbDataPusherConfig _conf  = ebWebForm.DataPusherConfig;
                        string             _pshId = _conf.MultiPushId == null ? string.Empty : $"AND {ebs[SystemColumns.eb_push_id]} = '{_conf.MultiPushId}'";
                        if (_table.TableName == _schema.MasterTable)
                        {
                            Qry += string.Format("WHERE {0}_id = @{0}_id {1} AND COALESCE({2}, {3}) = {3};",
                                                 _conf.SourceTable,
                                                 _pshId,
                                                 ebs[SystemColumns.eb_del],
                                                 ebs.GetBoolFalse(SystemColumns.eb_del));
                        }
                        else
                        {
                            Qry += string.Format("WHERE {0}_id = (SELECT id FROM {0} WHERE {1}_id = @{1}_id {2} AND COALESCE({3}, {4}) = {4} LIMIT 1) AND COALESCE({3}, {4}) = {4};",
                                                 _schema.MasterTable,
                                                 _conf.SourceTable,
                                                 _pshId,
                                                 ebs[SystemColumns.eb_del],
                                                 ebs.GetBoolFalse(SystemColumns.eb_del));
                        }
                    }
                    FullQry = Qry + FullQry;
                }
            }
            return(FullQry);
        }
        public static string GetMyActionInsertUpdateQueryxx(EbWebForm webForm, IDatabase DataDB, List <DbParameter> param, ref int i, Service service)
        {
            EbReviewHelper_inner inner = new EbReviewHelper_inner(webForm, DataDB, param, false, service);

            if (inner.ReviewNotFound)
            {
                return(string.Empty);
            }
            return(inner.GetMyActionInsertUpdateQueryxx(ref i));
        }
        internal static WebFormSchema GetWebFormSchema(EbWebForm _this)
        {
            WebFormSchema _formSchema = new WebFormSchema();

            _formSchema.FormName    = _this.Name;
            _formSchema.MasterTable = _this.TableName.ToLower();
            EbSystemColumns ebs = _this.SolutionObj?.SolutionSettings?.SystemColumns;

            _formSchema      = GetWebFormSchemaRec(_this, _formSchema, _this, _this.TableName.ToLower(), ebs);
            _this.FormSchema = _formSchema;
            return(_formSchema);
        }
Beispiel #12
0
        //send notifications and email etc
        public static void PostProcessGlobals(EbWebForm _this, FG_Root _globals, Service services)
        {
            if (_globals.system == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(_this.RefId) || _this.TableRowId <= 0)
            {
                return;
            }

            if (_globals.system.Notifications.Count > 0)
            {
                EbFnGateway.SendSystemNotifications(_this, _globals, services);
            }

            if (_globals.system.EmailNotifications.Count > 0)
            {
                if (_this.Notifications == null)
                {
                    _this.Notifications = new List <EbFormNotification>();
                }

                foreach (FG_EmailNotification notification in _globals.system.EmailNotifications)
                {
                    _this.Notifications.Add(new EbFnEmail()
                    {
                        RefId = notification.RefId
                    });
                }
            }

            if (_globals.system.PushNotifications.Count > 0)
            {
                if (_this.Notifications == null)
                {
                    _this.Notifications = new List <EbFormNotification>();
                }

                foreach (FG_Notification notification in _globals.system.PushNotifications)
                {
                    _this.Notifications.Add(new EbFnMobile()
                    {
                        IsDirectNotification = true,
                        NotifyUserId         = notification.UserId,
                        ProcessedMsgTitle    = notification.Title ?? _this.DisplayName,
                        ProcessedMessage     = notification.Message ?? string.Empty
                    });
                }
            }
        }
Beispiel #13
0
        //Excel Import
        public static FG_Root GetCSharpFormGlobals_NEW(EbWebForm _this, EbDataTable Data, int index)
        {
            Dictionary <string, FG_NV_List> dict = new Dictionary <string, FG_NV_List>();

            foreach (EbDataColumn dc in Data.Columns)
            {
                if (!dict.ContainsKey(dc.TableName))
                {
                    dict.Add(dc.TableName, new FG_NV_List());
                }
                dict[dc.TableName].Add(new FG_NV(dc.ColumnName, Data.Rows[index][dc.ColumnIndex]));
            }
            return(new FG_Root(new FG_Params(dict)));
        }
Beispiel #14
0
        //public static string GetCancelQuery(EbWebForm _this, IDatabase DataDB)
        //{
        //    string query = string.Empty;
        //    foreach (TableSchema _table in _this.FormSchema.Tables)
        //    {
        //        string _id = "id";
        //        if (_table.TableName != _this.FormSchema.MasterTable)
        //            _id = _this.FormSchema.MasterTable + "_id";
        //        query += string.Format("UPDATE {0} SET eb_void='T',eb_lastmodified_by = @eb_lastmodified_by, eb_lastmodified_at = " + DataDB.EB_CURRENT_TIMESTAMP + " WHERE {1} = @id AND COALESCE(eb_void, 'F') = 'F' AND COALESCE(eb_del, 'F') = 'F';", _table.TableName, _id);
        //    }
        //    return query;
        //}

        public static string GetLockOrUnlockQuery(EbWebForm _this, IDatabase DataDB, bool Lock)
        {
            EbSystemColumns ebs = _this.SolutionObj.SolutionSettings.SystemColumns;

            string Qry = string.Format("UPDATE {0} SET {1} = {6}, {2} = @eb_lastmodified_by, {3} = {4} WHERE id = @{0}_id AND COALESCE({1}, {5}) = {7};",
                                       _this.TableName,
                                       ebs[SystemColumns.eb_lock],                                                               //1
                                       ebs[SystemColumns.eb_lastmodified_by],                                                    //2
                                       ebs[SystemColumns.eb_lastmodified_at],                                                    //3
                                       DataDB.EB_CURRENT_TIMESTAMP,                                                              //4
                                       ebs.GetBoolFalse(SystemColumns.eb_lock),                                                  //5
                                       Lock ? ebs.GetBoolTrue(SystemColumns.eb_lock) : ebs.GetBoolFalse(SystemColumns.eb_lock),  //6
                                       Lock ? ebs.GetBoolFalse(SystemColumns.eb_lock) : ebs.GetBoolTrue(SystemColumns.eb_lock)); //7

            return(Qry);
        }
Beispiel #15
0
        public static List <FG_WebForm> GetEmptyDestinationModelGlobals(List <EbWebForm> DestForms)
        {
            List <FG_WebForm> fG_WebFormsList = new List <FG_WebForm>();

            for (int i = 0; i < DestForms.Count; i++)
            {
                EbWebForm   Form       = DestForms[i];
                WebformData _formdata  = Form.GetEmptyModel();
                int         createdBy  = Form.TableRowId <= 0 ? Form.UserObj.UserId : _formdata.CreatedBy;
                string      createdAt  = Form.TableRowId <= 0 ? DateTime.UtcNow.ConvertFromUtc(Form.UserObj.Preference.TimeZone).ToString(FormConstants.yyyyMMdd_HHmmss, CultureInfo.InvariantCulture) : _formdata.CreatedAt;
                FG_WebForm  fG_WebForm = new FG_WebForm(Form.TableName, Form.TableRowId, Form.LocationId, Form.RefId, createdBy, createdAt);
                GetCSharpFormGlobalsRec_NEW(fG_WebForm, Form, _formdata, null);
                fG_WebFormsList.Add(fG_WebForm);
            }
            return(fG_WebFormsList);
        }
Beispiel #16
0
        public static bool ExistsIndexControls(EbWebForm _webForm)
        {
            bool indexCtrlFound = false;

            foreach (TableSchema _table in _webForm.FormSchema.Tables)
            {
                if (_table.TableType == WebFormTableTypes.Normal)
                {
                    indexCtrlFound = _table.Columns.Exists(e => e.Control.Index);
                    if (indexCtrlFound)
                    {
                        break;
                    }
                }
            }
            return(indexCtrlFound);
        }
Beispiel #17
0
        //get formdata as globals for c# script engine
        public static FormAsGlobal GetFormAsGlobal(EbWebForm _this, WebformData _formData, EbControlContainer _container = null, FormAsGlobal _globals = null)
        {
            if (_container == null)
            {
                _container = _this;
            }
            if (_globals == null)
            {
                _globals = new FormAsGlobal {
                    Name = _this.Name
                }
            }
            ;

            ListNTV listNTV = new ListNTV();

            if (_formData.MultipleTables.ContainsKey(_container.TableName))
            {
                for (int i = 0; i < _formData.MultipleTables[_container.TableName].Count; i++)
                {
                    foreach (EbControl control in _container.Controls)
                    {
                        if (control is EbControlContainer)
                        {
                            FormAsGlobal g = new FormAsGlobal();
                            g.Name = (control as EbControlContainer).Name;
                            _globals.AddContainer(g);
                            g = GetFormAsGlobal(_this, _formData, control as EbControlContainer, g);
                        }
                        else
                        {
                            NTV n = GetNtvFromFormData(_formData, _container.TableName, i, control.Name);
                            if (n != null)
                            {
                                listNTV.Columns.Add(n);
                            }
                        }
                    }
                }
                _globals.Add(listNTV);
            }
            return(_globals);
        }
Beispiel #18
0
        public static string GetDynamicGridSelectQuery(EbWebForm _this, IDatabase DataDB, Service _service, string _prntTbl, string[] _targetTbls, out string _queryPs, out int _qryCount)
        {
            string query = string.Empty;

            _queryPs  = string.Empty;
            _qryCount = 0;
            EbSystemColumns ebs = _this.SolutionObj.SolutionSettings.SystemColumns;

            for (int i = 0; i < _targetTbls.Length; i++)
            {
                TableSchema _table = _this.FormSchema.Tables.Find(e => e.TableName == _targetTbls[i] && e.IsDynamic && e.TableType == WebFormTableTypes.Grid);
                string      _cols  = string.Format("{0}, id, {1}",
                                                   ebs[SystemColumns.eb_loc_id],
                                                   ebs[SystemColumns.eb_row_num]);

                IEnumerable <ColumnSchema> _columns = _table.Columns.Where(x => !x.Control.DoNotPersist || x.Control.IsSysControl || _table.TableType == WebFormTableTypes.Review);
                if (_columns.Count() > 0)
                {
                    _cols += ", " + string.Join(", ", _columns.Select(x => { return(x.Control.IsSysControl ? ebs[x.ColumnName] : x.ColumnName); }));
                }

                query += string.Format("SELECT {0} FROM {1} WHERE {2}_id = @{2}_id AND {3}_id = @{3}_id AND COALESCE({4}, {6}) = {6} {5}; ",
                                       _cols,
                                       _table.TableName,
                                       _this.FormSchema.MasterTable,
                                       _prntTbl,
                                       ebs[SystemColumns.eb_del],
                                       "ORDER BY " + ebs[SystemColumns.eb_row_num] + (_table.DescOdr ? " DESC" : string.Empty),
                                       ebs.GetBoolFalse(SystemColumns.eb_del));

                _qryCount++;

                foreach (ColumnSchema Col in _table.Columns.FindAll(e => !e.Control.DoNotPersist && e.Control is EbDGPowerSelectColumn && !(e.Control as EbDGPowerSelectColumn).IsDataFromApi))
                {
                    _queryPs += (Col.Control as EbDGPowerSelectColumn).GetSelectQuery123(DataDB, _service, _table.TableName, Col.ColumnName, _prntTbl, _this.FormSchema.MasterTable);
                }
            }
            return(query);
        }
Beispiel #19
0
 public static void InsertOrUpdate(IDatabase DataDB, EbWebForm _webForm)
 {
     try
     {
         string _data = GetJsonData(_webForm);
         if (string.IsNullOrEmpty(_data))
         {
             if (ExistsIndexControls(_webForm))
             {
                 Task.Run(() => Delete(DataDB, _webForm.RefId, _webForm.TableRowId));
             }
         }
         else
         {
             Task.Run(() => InsertOrUpdate(DataDB, _data, _webForm.RefId, _webForm.TableRowId, _webForm.UserObj.UserId, _webForm.DisplayName));
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Exception in insert/update global search data. Message: {ex.Message}\nStackTrace: {ex.StackTrace}");
     }
 }
Beispiel #20
0
        private List <AuditTrailEntry> GetTrailEntries(EbWebForm _webForm, TableSchema _table, SingleRow Row, SingleRow RowBkup)
        {
            string _newVal, _oldVal;
            bool   isUpdate = RowBkup != null && Row != null;
            List <AuditTrailEntry> trailEntries = new List <AuditTrailEntry>();
            string relation = string.Concat(_webForm.TableRowId, "-", Row != null ? Row.RowId : RowBkup.RowId);

            if (_webForm.FormSchema.MasterTable.Equals(_table.TableName))
            {
                relation = _webForm.TableRowId.ToString();
            }

            if (_table.TableType == WebFormTableTypes.Normal)
            {
                foreach (ColumnSchema _column in _table.Columns)
                {
                    if (_column.Control.DoNotPersist)
                    {
                        continue;
                    }
                    _newVal = null; _oldVal = null;

                    if (Row != null)
                    {
                        _newVal = Row[_column.ColumnName]?.ToString() ?? null;
                    }
                    if (RowBkup != null)
                    {
                        _oldVal = RowBkup[_column.ColumnName]?.ToString() ?? null;
                    }
                    if (isUpdate && _newVal == _oldVal)
                    {
                        continue;
                    }
                    trailEntries.Add(new AuditTrailEntry
                    {
                        Name      = _column.ColumnName,
                        NewVal    = _newVal,
                        OldVal    = _oldVal,
                        DataRel   = relation,
                        TableName = _table.TableName
                    });
                }
            }
            else
            {
                bool isChangeFound = false;
                Dictionary <string, string> dict4new = new Dictionary <string, string>();
                Dictionary <string, string> dict4old = new Dictionary <string, string>();
                foreach (ColumnSchema _column in _table.Columns)
                {
                    if (_column.Control.DoNotPersist)
                    {
                        continue;
                    }
                    if (Row != null)
                    {
                        dict4new.Add(_column.ColumnName, Row[_column.ColumnName]?.ToString() ?? null);
                    }
                    if (RowBkup != null)
                    {
                        dict4old.Add(_column.ColumnName, RowBkup[_column.ColumnName]?.ToString() ?? null);
                    }
                    if (isUpdate && dict4new[_column.ColumnName] != dict4old[_column.ColumnName])
                    {
                        isChangeFound = true;
                    }
                }
                if (isUpdate && !isChangeFound)//no changes
                {
                    return(trailEntries);
                }
                _newVal = null; _oldVal = null;
                if (Row != null)
                {
                    _newVal = JsonConvert.SerializeObject(dict4new);
                }
                if (RowBkup != null)
                {
                    _oldVal = JsonConvert.SerializeObject(dict4old);
                }

                trailEntries.Add(new AuditTrailEntry
                {
                    Name      = "RowData",
                    NewVal    = _newVal,
                    OldVal    = _oldVal,
                    DataRel   = relation,
                    TableName = _table.TableName
                });
            }

            return(trailEntries);
        }
Beispiel #21
0
        public IActionResult Eb_formBuilder(int i, int objtype)
        {
            //var req = this.HttpContext.Request.Form;
            //ViewBag.Objtype = req["objtype"];
            //ViewBag.Objid = req["objid"];

            //BuilderType _BuilderType = (BuilderType)Convert.ToInt32(ViewBag.Objtype);

            //EbObjectWrapper FormObj = GetFormObj(req["objid"].ToString(), Convert.ToInt32(req["objtype"]));
            //ViewBag.Json = FormObj.Json;
            //ViewBag.Name = FormObj.Name;
            //ViewBag.html = GetHtml2Render(_BuilderType, ViewBag.Objid);
            //return View();

            //================

            ViewBag.Header = "Edit WebForm";
            var req    = this.HttpContext.Request.Form;
            int obj_id = Convert.ToInt32(req["objid"]);

            ViewBag.Obj_id = obj_id;
            var resultlist = this.ServiceClient.Get <EbObjectExploreObjectResponse>(new EbObjectExploreObjectRequest {
                Id = obj_id
            });
            var rlist = resultlist.Data;

            foreach (var element in rlist)
            {
                ObjectLifeCycleStatus[]      array     = (ObjectLifeCycleStatus[])Enum.GetValues(typeof(ObjectLifeCycleStatus));
                List <ObjectLifeCycleStatus> lifeCycle = new List <ObjectLifeCycleStatus>(array);
                ViewBag.LifeCycle     = lifeCycle;
                ViewBag.IsNew         = "false";
                ViewBag.ObjType       = objtype;
                ViewBag.ObjectName    = element.Name;
                ViewBag.ObjectDesc    = element.Description;
                ViewBag.Status        = element.Status;
                ViewBag.VersionNumber = element.VersionNumber;
                ViewBag.Icon          = "fa fa-database";
                ViewBag.Refid         = element.RefId;
                ViewBag.Majorv        = element.Dashboard_Tiles.MajorVersionNumber;
                ViewBag.Minorv        = element.Dashboard_Tiles.MinorVersionNumber;
                ViewBag.Patchv        = element.Dashboard_Tiles.PatchVersionNumber;

                if (String.IsNullOrEmpty(element.Json_wc) && !String.IsNullOrEmpty(element.Json_lc))
                {
                    EbWebForm dsobj = EbSerializers.Json_Deserialize <EbWebForm>(element.Json_lc);
                    ViewBag.Name = dsobj.Name;
                    ViewBag.Json = element.Json_lc;
                    ViewBag.html = dsobj.GetHtml();
                }
                else
                {
                    EbWebForm dsobj = EbSerializers.Json_Deserialize <EbWebForm>(element.Json_wc);
                    ViewBag.Name = dsobj.Name;
                    ViewBag.Json = element.Json_wc;
                    ViewBag.html = dsobj.GetHtml();
                }
            }

            return(View());
        }
        private static WebFormSchema GetWebFormSchemaRec(EbWebForm _this, WebFormSchema _schema, EbControlContainer _container, string _parentTable, EbSystemColumns ebs)
        {
            IEnumerable <EbControl> _flatControls = _container.Controls.Get1stLvlControls();
            string      curTbl = _container.TableName.ToLower();
            TableSchema _table = _schema.Tables.FirstOrDefault(tbl => tbl.TableName == curTbl);

            if (_table == null)
            {
                if (_container is EbReview)
                {
                    _table = new TableSchema {
                        TableName = curTbl, ParentTable = _parentTable, TableType = WebFormTableTypes.Review, Title = _container.Label, ContainerName = _container.Name
                    };
                    _schema.ExtendedControls.Add(_container);
                }
                else if (_container is EbDataGrid dg)
                {
                    _table = new TableSchema {
                        TableName = curTbl, ParentTable = _parentTable, TableType = WebFormTableTypes.Grid, Title = _container.Label, ContainerName = _container.Name, IsDynamic = _container.IsDynamicTabChild, DescOdr = !dg.AscendingOrder, DoNotPersist = dg.DoNotPersist
                    }
                }
                ;
                else
                {
                    _table = new TableSchema {
                        TableName = curTbl, ParentTable = _parentTable, TableType = WebFormTableTypes.Normal, ContainerName = _container.Name
                    }
                };
                _schema.Tables.Add(_table);
            }

            foreach (EbControl control in _flatControls)
            {
                //if (control.IsSysControl && ebs != null && !(_container is EbReview))
                //{
                //    control.Name = ebs[control.Name];
                //}

                if (control is EbFileUploader)
                {
                    _schema.ExtendedControls.Add(control);
                }
                else if (control is EbProvisionUser)
                {
                    EbProvisionUser ctrl = control as EbProvisionUser;
                    ctrl.FuncParam.First(e => e.Name == "isolution_id").Value = _this.SolutionObj?.SolutionID ?? string.Empty;
                    int idx = _schema.ExtendedControls.FindIndex(e => e is EbProvisionLocation);
                    if (idx >= 0)
                    {
                        ctrl.AddLocConstraint = true;
                    }
                    _table.Columns.Add(new ColumnSchema {
                        ColumnName = control.Name, EbDbType = (int)control.EbDbType, Control = control
                    });
                }
                else if (control is EbProvisionLocation)
                {
                    foreach (object temp in _schema.ExtendedControls.FindAll(e => e is EbProvisionUser))
                    {
                        (temp as EbProvisionUser).AddLocConstraint = true;
                    }
                    _table.Columns.Add(new ColumnSchema {
                        ColumnName = control.Name, EbDbType = (int)control.EbDbType, Control = control
                    });
                }
                else if (control is EbDGUserControlColumn)
                {
                    foreach (EbControl _ctrl in (control as EbDGUserControlColumn).Columns)
                    {
                        _table.Columns.Add(new ColumnSchema {
                            ColumnName = _ctrl.Name, EbDbType = (int)_ctrl.EbDbType, Control = _ctrl
                        });
                    }
                }
                else if (control is EbSysLocation && !control.IsDisable)
                {
                    _this.IsLocEditable = true;
                    _table.Columns.Add(new ColumnSchema {
                        ColumnName = control.Name, EbDbType = (int)control.EbDbType, Control = control
                    });
                }
                else
                {
                    _table.Columns.Add(new ColumnSchema {
                        ColumnName = control.Name, EbDbType = (int)control.EbDbType, Control = control
                    });
                    if (control is EbAutoId)
                    {
                        _this.AutoId           = control as EbAutoId;
                        _this.AutoId.TableName = _table.TableName;
                    }
                }

                if (control is IEbExtraQryCtrl)
                {
                    (control as IEbExtraQryCtrl).TableName = curTbl;
                    _schema.ExtendedControls.Add(control);
                }
                else if (control is EbPhone _phCtrl && _phCtrl.Sendotp)
                {
                    _phCtrl.FormRefId   = _this.RefId;
                    _phCtrl.RedisClient = _this.RedisClient;
                }
                else if (control is EbEmailControl _emCtrl && _emCtrl.Sendotp)
                {
                    _emCtrl.FormRefId   = _this.RefId;
                    _emCtrl.RedisClient = _this.RedisClient;
                }
Beispiel #23
0
        public static string GetSelectQuery(EbWebForm _this, IDatabase DataDB, Service _service, out int _qryCount)
        {
            string query    = string.Empty;
            string extquery = string.Empty;

            _qryCount = 0;
            EbSystemColumns ebs = _this.SolutionObj.SolutionSettings.SystemColumns;

            foreach (TableSchema _table in _this.FormSchema.Tables)
            {
                if (_table.IsDynamic || _table.DoNotPersist)
                {
                    continue;
                }
                string _cols = $"{ebs[SystemColumns.eb_loc_id]}, id";
                string _id   = "id";

                if (_table.TableName == _this.FormSchema.MasterTable)
                {
                    _cols = string.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, id",
                                          ebs[SystemColumns.eb_loc_id],           //0
                                          ebs[SystemColumns.eb_ver_id],           //1
                                          ebs[SystemColumns.eb_lock],             //2
                                          ebs[SystemColumns.eb_push_id],          //3 //need only for slave forms in datapusher
                                          ebs[SystemColumns.eb_src_id],           //4
                                          ebs[SystemColumns.eb_created_by],       //5
                                          ebs[SystemColumns.eb_void],             //6
                                          ebs[SystemColumns.eb_created_at],       //7
                                          ebs[SystemColumns.eb_src_ver_id],       //8
                                          ebs[SystemColumns.eb_ro],               //9
                                          ebs[SystemColumns.eb_lastmodified_by],  //10
                                          ebs[SystemColumns.eb_lastmodified_at]); //11
                }
                else if (_table.TableType == WebFormTableTypes.Review)
                {
                    _id   = $"eb_ver_id = @{_this.FormSchema.MasterTable}_eb_ver_id AND eb_src_id";
                    _cols = "eb_loc_id, id";
                }
                else
                {
                    _id = _this.FormSchema.MasterTable + "_id";
                }

                if (_table.TableType == WebFormTableTypes.Grid)
                {
                    _cols = $"{ebs[SystemColumns.eb_loc_id]}, id, {ebs[SystemColumns.eb_row_num]}";
                }

                IEnumerable <ColumnSchema> _columns = _table.Columns.Where(x => !x.Control.DoNotPersist || x.Control.IsSysControl || _table.TableType == WebFormTableTypes.Review);
                if (_columns.Count() > 0)
                {
                    _cols += ", " + String.Join(", ", _columns.Select(x => { return(x.Control.IsSysControl ? ebs[x.ColumnName] : x.ColumnName); }));
                    IEnumerable <ColumnSchema> _ph_em_cols =
                        _columns.Where(x => (x.Control is EbPhone _phCtrl && _phCtrl.Sendotp) || (x.Control is EbEmailControl _emCtrl && _emCtrl.Sendotp));
                    if (_ph_em_cols.Count() > 0)
                    {
                        _cols += ", " + String.Join(", ", _ph_em_cols.Select(x => x.ColumnName + FormConstants._verified));
                    }
                }

                if (_this.DataPusherConfig == null)// master form
                {
                    query += string.Format("SELECT {0} FROM {1} WHERE {2} = @{3}_id AND COALESCE({5}, {6}) = {6} {4};",
                                           _cols,
                                           _table.TableName,
                                           _id,
                                           _this.FormSchema.MasterTable,
                                           _table.TableType == WebFormTableTypes.Grid ? ("ORDER BY " + ebs[SystemColumns.eb_row_num] + (_table.DescOdr ? " DESC" : string.Empty)) : "ORDER BY id",
                                           _table.TableType == WebFormTableTypes.Review ? SystemColumns.eb_del : ebs[SystemColumns.eb_del],
                                           _table.TableType == WebFormTableTypes.Review ? "'F'" : ebs.GetBoolFalse(SystemColumns.eb_del));
                }
                else
                {
                    string _pshId = _this.DataPusherConfig.MultiPushId == null ? string.Empty : $"AND {ebs[SystemColumns.eb_push_id]} = '{_this.DataPusherConfig.MultiPushId}'";

                    if (_table.TableName == _this.FormSchema.MasterTable)
                    {
                        query += string.Format("SELECT {0} FROM {1} WHERE {2}_id = @{2}_id {3} AND COALESCE({4}, {5}) = {5};",
                                               _cols,                                   //0
                                               _table.TableName,                        //1
                                               _this.DataPusherConfig.SourceTable,      //2
                                               _pshId,                                  //3
                                               ebs[SystemColumns.eb_del],               //4
                                               ebs.GetBoolFalse(SystemColumns.eb_del)); //5
                    }
                    else
                    {
                        query += string.Format("SELECT {0} FROM {1} WHERE {2}_id = (SELECT id FROM {2} WHERE {3}_id = @{3}_id {4} AND COALESCE({6}, {7}) = {7} LIMIT 1) AND COALESCE({8}, {9}) = {9} {5};",
                                               _cols,                                                                                                                                                  //0
                                               _table.TableName,                                                                                                                                       //1
                                               _this.FormSchema.MasterTable,                                                                                                                           //2
                                               _this.DataPusherConfig.SourceTable,                                                                                                                     //3
                                               _pshId,                                                                                                                                                 //4
                                               _table.TableType == WebFormTableTypes.Grid ? ("ORDER BY " + ebs[SystemColumns.eb_row_num] + (_table.DescOdr ? " DESC" : string.Empty)) : "ORDER BY id", //5
                                               ebs[SystemColumns.eb_del],                                                                                                                              //6
                                               ebs.GetBoolFalse(SystemColumns.eb_del),                                                                                                                 //7
                                               _table.TableType == WebFormTableTypes.Review ? SystemColumns.eb_del : ebs[SystemColumns.eb_del],                                                        //8
                                               _table.TableType == WebFormTableTypes.Review ? "'F'" : ebs.GetBoolFalse(SystemColumns.eb_del));                                                         //9
                    }
                }
                _qryCount++;
            }
            bool MuCtrlFound = false;//multiple ctrl found

            foreach (EbControl Ctrl in _this.FormSchema.ExtendedControls)
            {
                if (Ctrl is EbProvisionUser)
                {
                    if (!MuCtrlFound)
                    {
                        extquery   += (Ctrl as IEbExtraQryCtrl).GetSelectQuery(DataDB, _this.FormSchema.MasterTable);
                        MuCtrlFound = true;
                        _qryCount++;
                    }
                    extquery += (Ctrl as EbProvisionUser).GetMappedUserQuery(_this.FormSchema.MasterTable, ebs[SystemColumns.eb_del], ebs.GetBoolFalse(SystemColumns.eb_del));
                    _qryCount++;
                }
                else if (Ctrl is IEbExtraQryCtrl)
                {
                    extquery += (Ctrl as IEbExtraQryCtrl).GetSelectQuery(DataDB, _this.FormSchema.MasterTable);
                    _qryCount++;
                }
            }
            return(query + extquery);
        }
Beispiel #24
0
        public static string GetUpdateQuery(EbWebForm _this, IDatabase DataDB, string tblName, bool isDel)
        {
            string             _qry;
            EbSystemColumns    ebs  = _this.SolutionObj.SolutionSettings.SystemColumns;
            EbDataPusherConfig conf = _this.DataPusherConfig;

            if (conf == null)
            {
                if (tblName.Equals(_this.TableName))
                {
                    _qry = string.Format("UPDATE {0} SET {7} {6}{1} = @eb_modified_by, {2} = {3} WHERE id = {8} AND COALESCE({4}, {5}) = {5}; ",
                                         tblName,                                //0
                                         ebs[SystemColumns.eb_lastmodified_by],  //1
                                         ebs[SystemColumns.eb_lastmodified_at],  //2
                                         DataDB.EB_CURRENT_TIMESTAMP,            //3
                                         ebs[SystemColumns.eb_del],              //4
                                         ebs.GetBoolFalse(SystemColumns.eb_del), //5
                                         _this.LockOnSave ? $"{ebs[SystemColumns.eb_lock]} = {ebs.GetBoolTrue(SystemColumns.eb_lock)}, " : string.Empty,
                                         "{0}",
                                         "{1}");
                }
                else
                {
                    _qry = string.Format("UPDATE {0} SET {7} {1} = @eb_modified_by, {2} = {3} WHERE id = {8} AND {4}_id = @{4}_id AND COALESCE({5}, {6}) = {6}; ",
                                         tblName,                                //0
                                         ebs[SystemColumns.eb_lastmodified_by],  //1
                                         ebs[SystemColumns.eb_lastmodified_at],  //2
                                         DataDB.EB_CURRENT_TIMESTAMP,            //3
                                         _this.TableName,                        //4
                                         ebs[SystemColumns.eb_del],              //5
                                         ebs.GetBoolFalse(SystemColumns.eb_del), //6
                                         isDel ? $"{ebs[SystemColumns.eb_del]} = {ebs.GetBoolTrue(SystemColumns.eb_del)}, " : "{0}",
                                         "{1}");
                }
            }
            else
            {
                // if isDel is true then consider lines table also
                string parentTbl = _this.TableName;
                string pushIdChk = string.Empty;
                string cxt       = _this.CrudContext;
                if (tblName.Equals(_this.TableName))
                {
                    cxt       = string.Empty;
                    parentTbl = conf.SourceTable;
                    pushIdChk = conf.MultiPushId == null ? string.Empty : $"AND {ebs[SystemColumns.eb_push_id]} = '{conf.MultiPushId}'";
                }
                _qry = string.Format("UPDATE {0} SET {8} {1} = @eb_modified_by, {2} = {3} WHERE id = {10} AND {4}_id = @{4}_id{9} AND COALESCE({5}, {6}) = {6} {7}; ",
                                     tblName,                                                                                    //0
                                     ebs[SystemColumns.eb_lastmodified_by],                                                      //1
                                     ebs[SystemColumns.eb_lastmodified_at],                                                      //2
                                     DataDB.EB_CURRENT_TIMESTAMP,                                                                //3
                                     parentTbl,                                                                                  //4
                                     ebs[SystemColumns.eb_del],                                                                  //5
                                     ebs.GetBoolFalse(SystemColumns.eb_del),                                                     //6
                                     pushIdChk,                                                                                  //7
                                     isDel ? $"{ebs[SystemColumns.eb_del]} = {ebs.GetBoolTrue(SystemColumns.eb_del)}, " : "{0}", //8
                                     cxt,                                                                                        //9
                                     "{1}");
            }
            return(_qry);
        }
Beispiel #25
0
        public static string GetInsertQuery(EbWebForm _this, IDatabase DataDB, string tblName, bool isIns)
        {
            string             _qry = string.Empty;
            EbSystemColumns    ebs = _this.SolutionObj.SolutionSettings.SystemColumns;
            EbDataPusherConfig conf = _this.DataPusherConfig;
            string             currencyCols = string.Empty, currencyVals = string.Empty;
            TableSchema        _table = _this.FormSchema.Tables.Find(e => e.TableName == tblName);

            if (_table != null)
            {
                if (_table.Columns.Exists(e => !e.Control.DoNotPersist && !e.Control.IsSysControl &&
                                          ((e.Control is EbNumeric numCtrl && numCtrl.InputMode == NumInpMode.Currency) ||
                                           (e.Control is EbDGNumericColumn numCol && numCol.InputMode == NumInpMode.Currency))))
                {
                    currencyCols = $", {ebs[SystemColumns.eb_currency_id]}, {ebs[SystemColumns.eb_currency_xid]}, {ebs[SystemColumns.eb_xrate1]}, {ebs[SystemColumns.eb_xrate2]}";
                    currencyVals = $", 1, 'AED', 1, 1";
                }
            }

            if (tblName.Equals(_this.TableName))
            {
                if (conf == null)
                {
                    //if (_this.AutoId != null)
                    //    _qry = $"LOCK TABLE ONLY {_this.AutoId.TableName} IN EXCLUSIVE MODE; ";

                    _qry += string.Format("INSERT INTO {0} ({18} {1}, {2}, {3}, {4}, {5}, {10}, {11}, {12}, {13}{8}) VALUES ({19} @eb_createdby, {6}, @eb_loc_id, @{7}_eb_ver_id, @eb_signin_log_id, {14}, {15}, {16}, {17}{9}); ",
                                          tblName,                                                                                             //0
                                          ebs[SystemColumns.eb_created_by],                                                                    //1
                                          ebs[SystemColumns.eb_created_at],                                                                    //2
                                          ebs[SystemColumns.eb_loc_id],                                                                        //3
                                          ebs[SystemColumns.eb_ver_id],                                                                        //4
                                          ebs[SystemColumns.eb_signin_log_id],                                                                 //5
                                          DataDB.EB_CURRENT_TIMESTAMP,                                                                         //6
                                          _this.TableName,                                                                                     //7
                                          currencyCols,                                                                                        //8
                                          currencyVals,                                                                                        //9
                                          ebs[SystemColumns.eb_void],                                                                          //10
                                          ebs[SystemColumns.eb_del],                                                                           //11
                                          ebs[SystemColumns.eb_lock],                                                                          //12
                                          ebs[SystemColumns.eb_ro],                                                                            //13
                                          ebs.GetBoolFalse(SystemColumns.eb_void),                                                             //14
                                          ebs.GetBoolFalse(SystemColumns.eb_del),                                                              //15
                                          _this.LockOnSave ? ebs.GetBoolTrue(SystemColumns.eb_lock) : ebs.GetBoolFalse(SystemColumns.eb_lock), //16
                                          ebs.GetBoolFalse(SystemColumns.eb_ro),                                                               //17
                                          "{0}",                                                                                               //18
                                          "{1}");                                                                                              //19
                }
                else
                {
                    string srcRef = conf.SourceRecId <= 0 ? $"(SELECT eb_currval('{conf.SourceTable}_id_seq'))" : $"@{conf.SourceTable}_id";

                    _qry = string.Format(@"INSERT INTO {0} ({24} {1}, {2}, {3}, {4}, {9}_id, {5}, {6}, {7}, {8}, {15}, {16}, {20}, {21}{18}) 
                                    VALUES ({25} @eb_createdby, {10}, @eb_loc_id, @{11}_eb_ver_id, {12}, {12}, {13}, {14}, @eb_signin_log_id, @{9}_eb_ver_id, {17}, {22}, {23}{19}); ",
                                         tblName,                                                     //0
                                         ebs[SystemColumns.eb_created_by],                            //1
                                         ebs[SystemColumns.eb_created_at],                            //2
                                         ebs[SystemColumns.eb_loc_id],                                //3
                                         ebs[SystemColumns.eb_ver_id],                                //4
                                         ebs[SystemColumns.eb_src_id],                                //5
                                         ebs[SystemColumns.eb_push_id],                               //6
                                         ebs[SystemColumns.eb_lock],                                  //7
                                         ebs[SystemColumns.eb_signin_log_id],                         //8
                                         conf.SourceTable,                                            //9
                                         DataDB.EB_CURRENT_TIMESTAMP,                                 //10
                                         _this.TableName,                                             //11
                                         srcRef,                                                      //12
                                         conf.MultiPushId == null ? "null" : $"'{conf.MultiPushId}'", //13
                                         ebs.GetBoolTrue(SystemColumns.eb_lock),                      //14
                                         ebs[SystemColumns.eb_src_ver_id],                            //15
                                         ebs[SystemColumns.eb_ro],                                    //16
                                         ebs.GetBoolTrue(SystemColumns.eb_ro),                        //17
                                         currencyCols,                                                //18
                                         currencyVals,                                                //19
                                         ebs[SystemColumns.eb_void],                                  //20
                                         ebs[SystemColumns.eb_del],                                   //21
                                         ebs.GetBoolFalse(SystemColumns.eb_void),                     //22
                                         ebs.GetBoolFalse(SystemColumns.eb_del),                      //23
                                         "{0}",                                                       //24
                                         "{1}");                                                      //25
                }

                if (DataDB.Vendor == DatabaseVendors.MYSQL)
                {
                    _qry += $"SELECT eb_persist_currval('{tblName}_id_seq'); ";
                }
                if (_this.IsLocEditable)
                {
                    _qry = _qry.Replace($", {ebs[SystemColumns.eb_loc_id]}", string.Empty).Replace(", @eb_loc_id", string.Empty);
                }
            }
            //else if (tblName.Equals("eb_approval_lines"))
            //{
            //    _qry = $@"INSERT INTO eb_approval_lines ({{0}} eb_created_by, eb_created_at, eb_loc_id, eb_src_id, eb_ver_id, eb_signin_log_id)
            //                VALUES ({{1}} @eb_createdby, {DataDB.EB_CURRENT_TIMESTAMP}, @eb_loc_id, @{_this.TableName}_id, @{_this.TableName}_eb_ver_id, @eb_signin_log_id); ";
            //    if (DataDB.Vendor == DatabaseVendors.MYSQL)
            //        _qry += "SELECT eb_persist_currval('eb_approval_lines_id_seq'); ";
            //    // eb_approval - update eb_approval_lines_id
            //    _qry += $@"UPDATE eb_approval SET eb_approval_lines_id = (SELECT eb_currval('eb_approval_lines_id_seq')), eb_lastmodified_by = @eb_modified_by, eb_lastmodified_at = {DataDB.EB_CURRENT_TIMESTAMP}
            //                   WHERE eb_src_id = @{_this.TableName}_id AND eb_ver_id =  @{_this.TableName}_eb_ver_id AND COALESCE(eb_del, 'F') = 'F'; ";
            //}
            else
            {
                string srcRef = isIns ? $"(SELECT eb_currval('{_this.TableName}_id_seq'))" : $"@{_this.TableName}_id" + (conf == null ? string.Empty : _this.CrudContext);
                _qry = $@"
INSERT INTO {tblName} (
    {{0}} 
    {ebs[SystemColumns.eb_created_by]}, 
    {ebs[SystemColumns.eb_created_at]}, 
    {ebs[SystemColumns.eb_loc_id]}, 
    {_this.TableName}_id, 
    {ebs[SystemColumns.eb_signin_log_id]},
    {ebs[SystemColumns.eb_void]},
    {ebs[SystemColumns.eb_del]}
    {currencyCols}
) 
VALUES (
    {{1}} 
    @eb_createdby, 
    {DataDB.EB_CURRENT_TIMESTAMP}, 
    @eb_loc_id , 
    {srcRef}, 
    @eb_signin_log_id,
    {ebs.GetBoolFalse(SystemColumns.eb_void)},
    {ebs.GetBoolFalse(SystemColumns.eb_del)}
    {currencyVals}
); ";
                if (isIns && DataDB.Vendor == DatabaseVendors.MYSQL)
                {
                    _qry += $"SELECT eb_persist_currval('{tblName}_id_seq'); ";
                }
            }

            return(_qry);
        }
Beispiel #26
0
        public static string GetSelectQuery_Batch(EbWebForm _this, out int _qryCount)
        {
            _qryCount = 0;
            string             query  = string.Empty;
            EbSystemColumns    ebs    = _this.SolutionObj.SolutionSettings.SystemColumns;
            EbDataPusherConfig conf   = _this.DataPusherConfig;
            string             _pshId = conf.MultiPushId == null ? string.Empty : $"AND {ebs[SystemColumns.eb_push_id]} = '{conf.MultiPushId}'";

            foreach (TableSchema _table in _this.FormSchema.Tables)
            {
                string _cols = string.Empty;
                IEnumerable <ColumnSchema> _columns = _table.Columns.Where(x => !x.Control.DoNotPersist || x.Control.IsSysControl || _table.TableType == WebFormTableTypes.Review);
                if (_columns.Count() > 0)
                {
                    _cols = ", " + String.Join(", ", _columns.Select(x => { return(x.Control.IsSysControl ? ebs[x.ColumnName] : x.ColumnName); }));
                    IEnumerable <ColumnSchema> _em_ph_cols = _columns.Where(x => (x.Control is EbPhone _phCtrl && _phCtrl.Sendotp) || (x.Control is EbEmailControl _emCtrl && _emCtrl.Sendotp));
                    if (_em_ph_cols.Count() > 0)
                    {
                        _cols += ", " + String.Join(", ", _em_ph_cols.Select(x => x.ColumnName + FormConstants._verified));
                    }
                }

                if (_table.TableName == _this.FormSchema.MasterTable)
                {
                    //imp: column order is same as normal primary table
                    query += $@"
SELECT
    {ebs[SystemColumns.eb_loc_id]},
    {ebs[SystemColumns.eb_ver_id]},
    {ebs[SystemColumns.eb_lock]},
    {ebs[SystemColumns.eb_push_id]},
    {ebs[SystemColumns.eb_src_id]},
    {ebs[SystemColumns.eb_created_by]},
    {ebs[SystemColumns.eb_void]},
    {ebs[SystemColumns.eb_created_at]},
    {ebs[SystemColumns.eb_src_ver_id]},
    {ebs[SystemColumns.eb_ro]},
    {ebs[SystemColumns.eb_lastmodified_by]},
    {ebs[SystemColumns.eb_lastmodified_at]},
    id 
    {_cols},
    {conf.GridTableName}_id
FROM
    {_table.TableName}
WHERE
    {conf.SourceTable}_id = {conf.SourceRecId} AND
    COALESCE({ebs[SystemColumns.eb_del]}, {ebs.GetBoolFalse(SystemColumns.eb_del)}) = {ebs.GetBoolFalse(SystemColumns.eb_del)} {_pshId}; ";
                }
                else
                {
                    if (_table.TableType == WebFormTableTypes.Grid)
                    {
                        _cols = $"{ebs[SystemColumns.eb_loc_id]}, id, {ebs[SystemColumns.eb_row_num]}" + _cols;
                    }
                    else
                    {
                        _cols = $"{ebs[SystemColumns.eb_loc_id]}, id" + _cols;
                    }

                    query += $@"
SELECT 
    {_cols},
    {_this.FormSchema.MasterTable}_id
FROM 
    {_table.TableName} 
WHERE 
    {_this.FormSchema.MasterTable}_id IN (
        SELECT id FROM {_this.FormSchema.MasterTable} 
        WHERE {conf.SourceTable}_id = {conf.SourceRecId} AND 
            COALESCE({ebs[SystemColumns.eb_del]}, {ebs.GetBoolFalse(SystemColumns.eb_del)}) = {ebs.GetBoolFalse(SystemColumns.eb_del)}) AND 
    COALESCE({ebs[SystemColumns.eb_del]}, {ebs.GetBoolFalse(SystemColumns.eb_del)}) = {ebs.GetBoolFalse(SystemColumns.eb_del)} {_pshId} 
{(_table.TableType == WebFormTableTypes.Grid ? ("ORDER BY " + ebs[SystemColumns.eb_row_num] + (_table.DescOdr ? " DESC" : "")) : "")}; ";
                }

                _qryCount++;
            }
            return(query);
        }
Beispiel #27
0
 public EbAuditTrail(EbWebForm ebWebForm, IDatabase dataDB, Service service = null)
 {
     this.WebForm = ebWebForm;
     this.DataDB  = dataDB;
     this.Service = service;
 }
        public static InsertDataFromWebformResponse SubmitErrorAndGetResponse(IDatabase DataDB, EbWebForm Form, InsertDataFromWebformRequest request, Exception ex)
        {
            try
            {
                Console.WriteLine("SaveErrorSubmission start");
                Dictionary <string, string> MetaData = new Dictionary <string, string>();

                string Qry = $@"
INSERT INTO eb_form_drafts 
(
    title, 
    form_data_json, 
    form_ref_id, 
    message, 
    stack_trace, 
    is_submitted, 
    eb_loc_id, 
    eb_created_by, 
    eb_created_at, 
    eb_del,
    draft_type,
    eb_signin_log_id
)
VALUES 
(
    @title, 
    @form_data_json, 
    @form_ref_id, 
    @error_message, 
    @error_stacktrace, 
    'F', 
    {request.CurrentLoc}, 
    {request.UserId}, 
    {DataDB.EB_CURRENT_TIMESTAMP}, 
    'F',
    {(int)FormDraftTypes.ErrorBin},
    {Form.UserObj.SignInLogId}
); 
SELECT eb_currval('eb_form_drafts_id_seq');";

                string message, stackTrace;
                if (ex is FormException formEx)
                {
                    message    = formEx.Message + "; " + formEx.MessageInternal;
                    stackTrace = formEx.StackTrace + "; " + formEx.StackTraceInternal;
                }
                else
                {
                    message    = ex.Message;
                    stackTrace = ex.StackTrace;
                }

                DbParameter[] parameters = new DbParameter[]
                {
                    DataDB.GetNewParameter("title", EbDbTypes.String, Form.DisplayName),
                    DataDB.GetNewParameter("form_data_json", EbDbTypes.String, request.FormData),
                    DataDB.GetNewParameter("form_ref_id", EbDbTypes.String, Form.RefId),
                    DataDB.GetNewParameter("error_message", EbDbTypes.String, message),
                    DataDB.GetNewParameter("error_stacktrace", EbDbTypes.String, stackTrace)
                };

                EbDataSet ds  = DataDB.DoQueries(Qry, parameters);
                int       _id = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
                Console.WriteLine("SaveErrorSubmission returning");

                return(new InsertDataFromWebformResponse()
                {
                    Message = "Error submission saved",
                    RowId = _id,
                    RowAffected = 1000,
                    AffectedEntries = "Error submission id: " + _id,
                    Status = (int)HttpStatusCode.OK,
                    MetaData = MetaData
                });
            }
            catch (Exception _ex)
            {
                Console.WriteLine("Exception in SubmitErrorAndGetResponse\nMessage" + ex.Message + "\nStackTrace" + ex.StackTrace);

                if (ex is FormException formEx)
                {
                    return(new InsertDataFromWebformResponse()
                    {
                        Message = formEx.Message,
                        Status = formEx.ExceptionCode,
                        MessageInt = formEx.MessageInternal + ": " + _ex.Message,
                        StackTraceInt = formEx.StackTraceInternal
                    });
                }
                else
                {
                    return(new InsertDataFromWebformResponse()
                    {
                        Message = FormErrors.E0132 + ex.Message,
                        Status = (int)HttpStatusCode.InternalServerError,
                        MessageInt = "Exception in SubmitErrorAndGetResponse[service]: " + _ex.Message,
                        StackTraceInt = ex.StackTrace
                    });
                }
            }
        }
Beispiel #29
0
        public static FormAsGlobal GetFormAsFlatGlobal(EbWebForm _this, WebformData _formdata)
        {
            Dictionary <string, string> grid = new Dictionary <string, string>();

            EbControl[] Allctrls = _this.Controls.FlattenAllEbControls();
            for (int i = 0; i < Allctrls.Length; i++)
            {
                if (Allctrls[i] is EbDataGrid)
                {
                    grid.Add((Allctrls[i] as EbDataGrid).TableName, (Allctrls[i] as EbDataGrid).Name);
                }
            }

            FormAsGlobal _globals = new FormAsGlobal {
                Name = _this.Name
            };
            ListNTV listNTV = new ListNTV();

            try
            {
                foreach (KeyValuePair <string, SingleTable> item in _formdata.MultipleTables)
                {
                    if (grid.ContainsKey(item.Key))
                    {
                        FormAsGlobal _grid = new FormAsGlobal {
                            Name = grid[item.Key]
                        };
                        for (int j = 0; j < item.Value.Count; j++)
                        {
                            ListNTV _gridline = new ListNTV();
                            foreach (SingleColumn col in item.Value[j].Columns)
                            {
                                if (col.Name != "id" && col.Name != "eb_row_num")
                                {
                                    NTV n = GetNtvFromFormData(_formdata, item.Key, j, col.Name);
                                    if (n != null)
                                    {
                                        _gridline.Columns.Add(n);
                                    }
                                }
                            }
                            _grid.Add(_gridline);
                        }
                        _globals.AddContainer(_grid);
                    }
                    else
                    {
                        foreach (SingleColumn col in item.Value[0].Columns)
                        {
                            if (!(col.Name == "id" && item.Key != _formdata.MasterTable) && item.Value.Count == 1)
                            {
                                NTV n = GetNtvFromFormData(_formdata, item.Key, 0, col.Name);
                                if (n != null)
                                {
                                    listNTV.Columns.Add(n);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception in GetFormAsFlatGlobal. Message : " + ex.Message);
                Console.WriteLine(ex.StackTrace);
            }

            _globals.Add(listNTV);
            return(_globals);
        }
Beispiel #30
0
        //public static string GetDeleteQuery(EbWebForm _this, IDatabase DataDB)
        //{
        //    string query = string.Empty;
        //    foreach (TableSchema _table in _this.FormSchema.Tables)
        //    {
        //        string _id = "id";
        //        string _dupcols = string.Empty;
        //        if (_table.TableName != _this.FormSchema.MasterTable)
        //            _id = _this.FormSchema.MasterTable + "_id";
        //        foreach (ColumnSchema _column in _table.Columns)
        //        {
        //            if (_column.Control is EbAutoId)
        //            {
        //                _dupcols += string.Format(", {0}_ebbkup = {0}, {0} = CONCAT({0}, '_ebbkup')", _column.ColumnName);
        //            }
        //        }
        //        query += string.Format("UPDATE {0} SET eb_del='T',eb_lastmodified_by = @eb_lastmodified_by, eb_lastmodified_at = " + DataDB.EB_CURRENT_TIMESTAMP + " {1} WHERE {2} = @id AND COALESCE(eb_del, 'F') = 'F';", _table.TableName, _dupcols, _id);
        //    }
        //    return query;
        //}

        public static string GetCancelQuery(EbWebForm _this, IDatabase DataDB, bool Cancel)
        {
            string          FullQry = string.Empty;
            EbSystemColumns ebs     = _this.SolutionObj.SolutionSettings.SystemColumns;

            foreach (EbWebForm ebWebForm in _this.FormCollection)
            {
                WebFormSchema _schema = ebWebForm.FormSchema;
                foreach (TableSchema _table in _schema.Tables.FindAll(e => e.TableType != WebFormTableTypes.Review && !e.DoNotPersist))
                {
                    string Qry = string.Format("UPDATE {0} SET {1} = {5}, {2} = @eb_lastmodified_by, {3} = {4} ",
                                               _table.TableName,                                                                           //0
                                               ebs[SystemColumns.eb_void],                                                                 //1
                                               ebs[SystemColumns.eb_lastmodified_by],                                                      //2
                                               ebs[SystemColumns.eb_lastmodified_at],                                                      //3
                                               DataDB.EB_CURRENT_TIMESTAMP,                                                                //4
                                               Cancel ? ebs.GetBoolTrue(SystemColumns.eb_void) : ebs.GetBoolFalse(SystemColumns.eb_void)); //5

                    if (ebWebForm.DataPusherConfig == null)
                    {
                        Qry += string.Format("WHERE {0} = @{1}_id AND COALESCE({2}, {4}) = {4} AND COALESCE({3}, {5}) = {6};",
                                             _table.TableName == _schema.MasterTable ? "id" : (_schema.MasterTable + "_id"),             //0
                                             _schema.MasterTable,                                                                        //1
                                             ebs[SystemColumns.eb_del],                                                                  //2
                                             ebs[SystemColumns.eb_void],                                                                 //3
                                             ebs.GetBoolFalse(SystemColumns.eb_del),                                                     //4
                                             ebs.GetBoolFalse(SystemColumns.eb_void),                                                    //5
                                             Cancel ? ebs.GetBoolFalse(SystemColumns.eb_void) : ebs.GetBoolTrue(SystemColumns.eb_void)); //6
                    }
                    else
                    {
                        EbDataPusherConfig _conf  = ebWebForm.DataPusherConfig;
                        string             _pshId = _conf.MultiPushId == null ? string.Empty : $"AND {ebs[SystemColumns.eb_push_id]} = '{_conf.MultiPushId}'";
                        if (_table.TableName == _schema.MasterTable)
                        {
                            Qry += string.Format("WHERE {0}_id = @{0}_id {1} AND COALESCE({2}, {4}) = {4} AND COALESCE({3}, {5}) = {6};",
                                                 _conf.SourceTable,                                                                          //0
                                                 _pshId,                                                                                     //1
                                                 ebs[SystemColumns.eb_del],                                                                  //2
                                                 ebs[SystemColumns.eb_void],                                                                 //3
                                                 ebs.GetBoolFalse(SystemColumns.eb_del),                                                     //4
                                                 ebs.GetBoolFalse(SystemColumns.eb_void),                                                    //5
                                                 Cancel ? ebs.GetBoolFalse(SystemColumns.eb_void) : ebs.GetBoolTrue(SystemColumns.eb_void)); //6
                        }
                        else
                        {
                            Qry += string.Format("WHERE {0}_id = (SELECT id FROM {0} WHERE {1}_id = @{1}_id {2} AND COALESCE({3}, {5}) = {5} AND COALESCE({4}, {6}) = {7} LIMIT 1) AND COALESCE({3}, {5}) = {5} AND COALESCE({4}, {6}) = {7};",
                                                 _schema.MasterTable,                                                                        //0
                                                 _conf.SourceTable,                                                                          //1
                                                 _pshId,                                                                                     //2
                                                 ebs[SystemColumns.eb_del],                                                                  //3
                                                 ebs[SystemColumns.eb_void],                                                                 //4
                                                 ebs.GetBoolFalse(SystemColumns.eb_del),                                                     //5
                                                 ebs.GetBoolFalse(SystemColumns.eb_void),                                                    //6
                                                 Cancel ? ebs.GetBoolFalse(SystemColumns.eb_void) : ebs.GetBoolTrue(SystemColumns.eb_void)); //7
                        }
                    }
                    FullQry = Qry + FullQry;
                }
            }
            return(FullQry);
        }