public ModelCancelEventArgs(Model model, bool cancel)
     : this(model)
 {
     Cancel = cancel;
 }
Ejemplo n.º 2
0
 public ModelEventArgs(Model model)
 {
     Model = model;
 }
 public ModelCancelEventArgs(Model model)
     : base(model)
 {
 }
Ejemplo n.º 4
0
 public virtual void CreateTable(Model model)
 {
     ExecuteNonQuery(ToSqlCreateStatement(model), null);
 }
Ejemplo n.º 5
0
        public virtual bool Delete(Model model)
        {
            QParam pkParam = new QParam(model.ModelPKName, model.PK, 1);

            string deleteSql = string.Format("DELETE FROM {0} WHERE {1}={2}",
                model.ModelDbName,
                model.ModelPKName,
                pkParam.Id);

            ExecuteNonQuery(deleteSql, new QParam[] { pkParam });
            return true;
        }
Ejemplo n.º 6
0
 protected string ToFieldValuesList(Model model)
 {
     return string.Join(",", model.Fields.Select(field => ToSqlFormat(field)));
 }
Ejemplo n.º 7
0
 protected abstract string ToSqlCreateStatement(Model model);
Ejemplo n.º 8
0
        public virtual bool Update(Model model)
        {
            List<QParam> qParams = QParamsFromModel(model);
            string update_set_expr = "";
            QParam pkParam = null;

            for (int i = 0; i < qParams.Count; i++)
            {
                if (qParams[i].FieldName == model.ModelPKName){
                    pkParam = qParams[i];
                    continue;
                }

                if (update_set_expr != "")
                    update_set_expr += ",";
                update_set_expr += qParams[i].FieldName + "=" + qParams[i].Id;
            }

            string updateSql = string.Format("UPDATE {0} SET {1} WHERE {2}={3}",
                model.ModelDbName,
                update_set_expr,
                model.ModelPKName,
                pkParam.Id);

            ExecuteNonQuery(updateSql, qParams);
            return true;
        }
Ejemplo n.º 9
0
        protected List<QParam> QParamsFromModel(Model model)
        {
            List<QParam> qparams = new List<QParam>();
            List<Field> fields = model.Fields;
            for (int i = 0; i < fields.Count; i++)
            {
                qparams.Add(new QParam(fields[i].DbName, fields[i].Value, i + 1));
            }

            return qparams;
        }
Ejemplo n.º 10
0
        protected virtual bool OnSaving(Model model)
        {
            bool cancel = false;
            ModelCancelEventHandler ceSaving = ModelSaving;
            if (ceSaving != null)
            {
                ModelCancelEventArgs mcea = new ModelCancelEventArgs(model, cancel);
                ceSaving(this, mcea);
                cancel = mcea.Cancel;
            }

            return cancel;
        }
Ejemplo n.º 11
0
        public virtual int Insert(Model model)
        {
            List<QParam> qParams = QParamsFromModel(model);
            string paramsListAsString = "";
            for (int i = 0; i < qParams.Count; i++)
            {
                if (i > 0)
                    paramsListAsString += ",";
                paramsListAsString += qParams[i].Id;
            }

            string insertSql = string.Format("INSERT INTO {0} ({1}) VALUES ({2})",
                model.ModelDbName,
                ToFieldNamesList(model, removeAlias:true),
                paramsListAsString);

            return Convert.ToInt32(ExecuteNonQuery(insertSql, qParams, true));
        }
Ejemplo n.º 12
0
 protected virtual void OnSaved(Model model)
 {
     ModelEventHandler eSaved = ModelSaved;
     if (eSaved != null)
         eSaved(this, new ModelEventArgs(model));
 }
Ejemplo n.º 13
0
 protected virtual void OnDeleted(Model model)
 {
     ModelEventHandler eDeleted = ModelDeleted;
     if (eDeleted != null)
         eDeleted(this, new ModelEventArgs(model));
 }
Ejemplo n.º 14
0
        public bool Save(Model model)
        {
            int insertedId = -1;
            bool updated = false;

            if (model.ModelType == ModelInfo.ModelType)
                if (!OnSaving(model))
                {
                    if (model.Status == ModelStatus.New)
                    {
                        insertedId = DbEngine.Insert(model);
                        if (insertedId != -1)
                            model[model.ModelPKName] = insertedId;
                    }
                    else
                    {
                        updated = DbEngine.Update(model);
                    }

                    if (insertedId != -1 || updated)
                    {
                        model.Status = ModelStatus.Loaded;
                        OnSaved(model);
                    }
                }

            return insertedId != -1 || updated;
        }
Ejemplo n.º 15
0
        public bool Delete(Model model)
        {
            bool result = false;

            if (model.ModelType == ModelInfo.ModelType)
                if (!OnDeleting(model))
                    if ((result = DbEngine.Delete(model)))
                    {
                        model.Status = ModelStatus.Deleted;
                        OnDeleted(model);
                    }

            return result;
        }
Ejemplo n.º 16
0
        public ModelInfo(Model model)
        {
            _model = model;

            Fields = new List<FieldInfo>();
            foreach (Field field in _model.Fields)
            {
                if (field == _model.PKField)
                    PKField = new FieldInfo(field);

                Fields.Add(new FieldInfo(field));
            }
        }