Exemple #1
0
        public response Delete()
        {
            response  toReturn    = new response(false, "", null, null, new List <Error>());;
            ArrayList _parameters = new ArrayList();

            _parameters.Add(new MySqlParameter("_ID", this.ID));
            DataAccess da = new DataAccess(authenticatedUserId, connectionString, CommandType.StoredProcedure, "PLATIsp_soft_delete", _parameters.ToArray());

            toReturn = da.ExecuteDeleteQuery();
            if (toReturn.Status)
            {
                try
                {
                    Dosar d = new Dosar(authenticatedUserId, connectionString, Convert.ToInt32(this.ID_DOSAR));
                    d.UpdateCounterPlati(-1);
                }
                catch (Exception exp) { LogWriter.Log(exp); }

                try
                {
                    Dosar d = new Dosar(this.authenticatedUserId, this.connectionString, Convert.ToInt32(this.ID_DOSAR));
                    d.REZERVA_DAUNA += this.SUMA;
                    d.GetNewStatus(false);
                    response r = d.Update();
                    if (!r.Status)
                    {
                        toReturn = r;
                    }
                }
                catch (Exception exp)
                {
                    toReturn = new response(false, exp.ToString(), null, null, new List <Error>()
                    {
                        new Error(exp)
                    });
                    LogWriter.Log(exp);
                }
            }
            return(toReturn);
        }
Exemple #2
0
        public response Insert()
        {
            response toReturn = Validare();

            if (!toReturn.Status)
            {
                return(toReturn);
            }
            PropertyInfo[] props       = this.GetType().GetProperties();
            ArrayList      _parameters = new ArrayList();

            var col = CommonFunctions.table_columns(authenticatedUserId, connectionString, "plati");

            foreach (PropertyInfo prop in props)
            {
                if (col != null && col.ToUpper().IndexOf(prop.Name.ToUpper()) > -1) // ca sa includem in Array-ul de parametri doar coloanele tabelei, nu si campurile externe si/sau alte proprietati
                {
                    string propName  = prop.Name;
                    string propType  = prop.PropertyType.ToString();
                    object propValue = prop.GetValue(this, null);
                    propValue = propValue ?? DBNull.Value;
                    if (propType != null)
                    {
                        if (propName.ToUpper() != "ID") // il vom folosi doar la Edit!
                        {
                            _parameters.Add(new MySqlParameter(String.Format("_{0}", propName.ToUpper()), propValue));
                        }
                    }
                }
            }
            DataAccess da = new DataAccess(authenticatedUserId, connectionString, CommandType.StoredProcedure, "PLATIsp_insert", _parameters.ToArray());

            toReturn = da.ExecuteInsertQuery();
            if (toReturn.Status)
            {
                this.ID = toReturn.InsertedId;

                if (toReturn.Status)
                {
                    try
                    {
                        Dosar d = new Dosar(authenticatedUserId, connectionString, Convert.ToInt32(this.ID_DOSAR));
                        d.UpdateCounterPlati(1);
                    }
                    catch (Exception exp) { LogWriter.Log(exp); }
                }

                if (toReturn.Status)
                {
                    try
                    {
                        Dosar d = new Dosar(this.authenticatedUserId, this.connectionString, Convert.ToInt32(this.ID_DOSAR));
                        d.REZERVA_DAUNA -= this.SUMA;
                        d.GetNewStatus(false);
                        response r = d.Update();
                        if (!r.Status)
                        {
                            toReturn = r;
                        }
                    }
                    catch (Exception exp)
                    {
                        toReturn = new response(false, exp.ToString(), null, null, new List <Error>()
                        {
                            new Error(exp)
                        });
                        LogWriter.Log(exp);
                    }
                }
            }
            return(toReturn);
        }