Example #1
0
 /// <summary>
 /// Metoda pt. popularea Tipului mesajului
 /// </summary>
 /// <returns>SOCISA.NomenclatorJson</returns>
 public response GetTipMesaj()
 {
     try
     {
         Nomenclator toReturn = new Nomenclator(authenticatedUserId, connectionString, "tip_mesaje", (Convert.ToInt32(this.ID_TIP_MESAJ)));
         return(new response(true, Newtonsoft.Json.JsonConvert.SerializeObject(toReturn, CommonFunctions.JsonSerializerSettings), toReturn, null, null));
     }
     catch (Exception exp) { LogWriter.Log(exp); return(new response(false, exp.ToString(), null, null, new List <Error>()
         {
             new Error(exp)
         })); }
 }
Example #2
0
 public Mesaj(int _authenticatedUserId, string _connectionString, int?IdDosar, DateTime Data, string Subiect, string Body, string TipMesaj, int IdSender, int Importanta)
 {
     authenticatedUserId = _authenticatedUserId;
     connectionString    = _connectionString;
     ID_DOSAR            = IdDosar;
     DATA         = Data;
     SUBIECT      = Subiect;
     BODY         = Body;
     ID_SENDER    = IdSender;
     ID_TIP_MESAJ = new Nomenclator(authenticatedUserId, connectionString, "tip_mesaje").GetIdByName("tip_mesaje", TipMesaj);
     IMPORTANTA   = Importanta;
 }
Example #3
0
 public response Find(string tableName, string _denumire)
 {
     try
     {
         Nomenclator item = new Nomenclator(authenticatedUserId, connectionString, tableName, _denumire);
         return(new response(true, JsonConvert.SerializeObject(item, CommonFunctions.JsonSerializerSettings), item, null, null));
     }
     catch (Exception exp) { LogWriter.Log(exp); return(new response(false, exp.ToString(), null, null, new System.Collections.Generic.List <Error>()
         {
             new Error(exp)
         })); }
 }
Example #4
0
        public response GetFiltered(string tableName, string _sort, string _order, string _filter, string _limit)
        {
            try
            {
                try
                {
                    string newFilter = Filtering.GenerateFilterFromJsonObject(typeof(Nomenclator), _filter, authenticatedUserId, connectionString);
                    _filter = newFilter == null ? _filter : newFilter;
                }
                catch { }
                DataAccess da = new DataAccess(authenticatedUserId, connectionString, CommandType.StoredProcedure, String.Format("{0}sp_select", tableName.ToUpper()), new object[] {
                    new MySqlParameter("_SORT", _sort),
                    new MySqlParameter("_ORDER", _order),
                    new MySqlParameter("_FILTER", _filter),
                    new MySqlParameter("_LIMIT", _limit)
                });

                /*
                 * ArrayList aList = new ArrayList();
                 * MySqlDataReader r = da.ExecuteSelectQuery();
                 * while (r.Read())
                 * {
                 *  Nomenclator a = new Nomenclator(authenticatedUserId, connectionString, tableName, (IDataRecord)r);
                 *  aList.Add(a);
                 * }
                 * r.Close(); r.Dispose(); da.CloseConnection();
                 * Nomenclator[] toReturn = new Nomenclator[aList.Count];
                 * for (int i = 0; i < aList.Count; i++)
                 *  toReturn[i] = (Nomenclator)aList[i];
                 * return new response(true, JsonConvert.SerializeObject(toReturn, CommonFunctions.JsonSerializerSettings), toReturn, null, null);
                 */
                List <Nomenclator> aList = new List <Nomenclator>();
                MySqlDataReader    r     = da.ExecuteSelectQuery();
                while (r.Read())
                {
                    Nomenclator a = new Nomenclator(authenticatedUserId, connectionString, tableName, (IDataRecord)r);
                    aList.Add(a);
                }
                r.Close(); r.Dispose(); da.CloseConnection();
                return(new response(true, JsonConvert.SerializeObject(aList.ToArray(), CommonFunctions.JsonSerializerSettings), aList.ToArray(), null, null));
            }
            catch (Exception exp) { LogWriter.Log(exp); return(new response(false, exp.ToString(), null, null, new System.Collections.Generic.List <Error>()
                {
                    new Error(exp)
                })); }
        }
Example #5
0
        public response GetPlatiFromExcel(string sheet, string fileName)
        {
            try
            {
                FileInfo       fi  = new FileInfo(File.Exists(fileName) ? fileName : Path.Combine(CommonFunctions.GetImportsFolder(), fileName));
                ExcelPackage   ep  = new ExcelPackage(fi);
                ExcelWorksheet ews = ep.Workbook.Worksheets[sheet];

                Dictionary <string, int> columnNames = new Dictionary <string, int>();
                int colIndex = 1;
                foreach (var firstRowCell in ews.Cells[1, 1, 1, ews.Dimension.End.Column])
                {
                    columnNames.Add(firstRowCell.Text, colIndex);
                    colIndex++;
                }
                List <object[]> toReturnList = new List <object[]>();
                //TO DO: trebuie stabilita maparea exacta cu coloanele din Excel !!!

                Nomenclator TipPlata = new Nomenclator(authenticatedUserId, connectionString, "tip_plata", "DIRECTA");

                Dosar dosar = null;

                for (var rowNumber = 2; rowNumber <= ews.Dimension.End.Row; rowNumber++)
                {
                    try
                    {
                        response             toReturn = new response(true, "", null, null, new List <Error>());;
                        response             r        = new response();
                        List <PlataExtended> plati    = new List <PlataExtended>();

                        try
                        {
                            dosar = new Dosar(authenticatedUserId, connectionString, ews.Cells[rowNumber, columnNames["DOSAR"]].Text.Trim());
                            if (dosar == null || dosar.ID == null)
                            {
                                Error        err  = ErrorParser.ErrorMessage("dosarInexistent");
                                List <Error> errs = new List <Error>();
                                errs.Add(err);
                                r = new response(false, err.ERROR_MESSAGE, null, null, errs);
                                toReturn.AddResponse(r);
                            }
                            else
                            {
                                if (!dosar.IsAvizat())
                                {
                                    Error        err  = ErrorParser.ErrorMessage("dosarNeavizat");
                                    List <Error> errs = new List <Error>();
                                    errs.Add(err);
                                    r = new response(false, err.ERROR_MESSAGE, null, null, errs);
                                    toReturn.AddResponse(r);
                                }
                            }
                        }
                        catch (Exception exp)
                        {
                            LogWriter.Log(exp);
                        }

                        for (int i = 1; i < 6; i++) // platile in Excel sunt pe coloane si consideram maxim 5 plati
                        {
                            try
                            {
                                if (!String.IsNullOrWhiteSpace(ews.Cells[rowNumber, columnNames["DOCUMENT_PLATA" + i.ToString()]].Text.Trim()) && Double.TryParse(ews.Cells[rowNumber, columnNames["SUMA_RECUPERATA" + i.ToString()]].Text.Trim(), out double tmpSuma) && CommonFunctions.SwitchBackFormatedDate(ews.Cells[rowNumber, columnNames["DATA_PLATA" + i.ToString()]].Text.Trim()) != null)
                                {
                                    Plata plata = new Plata(authenticatedUserId, connectionString);
                                    try { plata.NR_DOCUMENT = ews.Cells[rowNumber, columnNames["DOCUMENT_PLATA" + i.ToString()]].Text.Trim(); }
                                    catch { }
                                    try { plata.DATA_DOCUMENT = CommonFunctions.SwitchBackFormatedDate(ews.Cells[rowNumber, columnNames["DATA_PLATA" + i.ToString()]].Text.Trim()); }
                                    catch { }
                                    try { plata.SUMA = Convert.ToDouble(ews.Cells[rowNumber, columnNames["SUMA_RECUPERATA" + i.ToString()]].Text.Trim()); }
                                    catch { }
                                    try { plata.ID_DOSAR = dosar.ID; }
                                    catch { }
                                    try { plata.ID_TIP_PLATA = TipPlata.ID; }
                                    catch { }
                                    plati.Add(new PlataExtended(plata));
                                }
                            }
                            catch { }
                        }

                        foreach (PlataExtended plataExtended in plati)
                        {
                            Plata tmpPlata = new Plata(authenticatedUserId, connectionString, plataExtended.Plata);
                            if (tmpPlata != null && tmpPlata.ID != null)
                            {
                                Error        err  = ErrorParser.ErrorMessage("plataExistenta");
                                List <Error> errs = new List <Error>();
                                errs.Add(err);
                                r = new response(false, err.ERROR_MESSAGE, null, null, errs);
                                toReturn.AddResponse(r);
                            }
                            r = plataExtended.Plata.Validare();
                            if (!r.Status)
                            {
                                toReturn.AddResponse(r);
                            }
                            //pt. cazul in care avem duplicate in excel si platile nu sunt inca in baza de date !
                            for (int i = 0; i < toReturnList.Count; i++)
                            {
                                tmpPlata = ((PlataExtended)toReturnList[i][1]).Plata;
                                if (tmpPlata.NR_DOCUMENT == plataExtended.Plata.NR_DOCUMENT && tmpPlata.DATA_DOCUMENT == plataExtended.Plata.DATA_DOCUMENT && tmpPlata.SUMA == plataExtended.Plata.SUMA && tmpPlata.ID_DOSAR == plataExtended.Plata.ID_DOSAR)
                                {
                                    Error    err = new Error();
                                    response nr  = new response(false, null, null, null, new List <Error>());
                                    nr.Status     = false;
                                    err           = ErrorParser.ErrorMessage("plataExistenta");
                                    nr.Message    = string.Format("{0}{1};", nr.Message ?? "", err.ERROR_MESSAGE);
                                    nr.InsertedId = null;
                                    nr.Error.Add(err);
                                    toReturn.AddResponse(nr);
                                    break;
                                }
                            }
                            toReturnList.Add(new object[] { toReturn, plataExtended });
                        }
                    }
                    catch (Exception exp)
                    {
                        LogWriter.Log(exp);
                    }
                }
                return(new response(true, JsonConvert.SerializeObject(toReturnList.ToArray(), CommonFunctions.JsonSerializerSettings), toReturnList.ToArray(), null, null));
            }
            catch (Exception exp)
            {
                LogWriter.Log(exp);
                return(new response(false, exp.Message, null, null, new List <Error>()
                {
                    new Error(exp)
                }));
            }
        }
Example #6
0
 public int?GetIdByName(Nomenclator item, string tableName, string denumire)
 {
     return(item.GetIdByName(tableName, denumire));
 }
Example #7
0
 public response GetChildren(Nomenclator item, string childTableName, int childrenId)
 {
     return(item.GetChildren(childTableName, childrenId));
 }
Example #8
0
 public response GetChildrens(Nomenclator item, string childTableName)
 {
     return(item.GetChildrens(childTableName));
 }
Example #9
0
 public response Delete(Nomenclator item)
 {
     return(item.Delete());
 }
Example #10
0
 public response Update(Nomenclator item)
 {
     return(item.Update());
 }
Example #11
0
 public response Insert(Nomenclator item)
 {
     return(item.Insert());
 }
Example #12
0
        public static response Validate(int authenticatedUserId, string connectionString, object obj, string tableName, out bool succes)
        {
            succes = false;
            response toReturn = new response(true, "", null, null, new List <Error>());
            Error    err      = new Error();

            try
            {
                Validation[] validations = Validator.GetTableValidations(tableName);
                if (validations != null && validations.Length > 0) // daca s-au citit validarile din fisier mergem pe fisier
                {
                    PropertyInfo[] pis = obj.GetType().GetProperties();
                    foreach (Validation v in validations)
                    {
                        if (v.Active)
                        {
                            if (v.ValidationType == "Duplicate" && v.FieldName.IndexOf(',') > -1 && obj.GetType().GetProperty("ID").GetValue(obj) == null)  // pentru cautare duplicate dupa campuri (cheie) compusa, doar la Insert
                            {
                                string[] fields = v.FieldName.Replace(" ", "").Split(',');
                                if (!Validator.ObjectIsUniqueByMultipleFields(authenticatedUserId, connectionString, fields, obj, tableName))
                                {
                                    toReturn.Status     = false;
                                    err                 = ErrorParser.ErrorMessage(v.ErrorCode);
                                    toReturn.Message    = string.Format("{0}{1};", toReturn.Message ?? "", err.ERROR_MESSAGE);
                                    toReturn.InsertedId = null;
                                    toReturn.Error.Add(err);
                                }
                            }
                            else
                            {
                                foreach (PropertyInfo pi in pis)
                                {
                                    if (v.FieldName.ToUpper() == pi.Name.ToUpper())
                                    {
                                        bool applyCondition = true;
                                        switch (v.ValidationType)
                                        {
                                        case "Mandatory":
                                            if (!(v.Conditions == null || v.Conditions.Length == 0))
                                            {
                                                foreach (ValidationCondition vc in v.Conditions)
                                                {
                                                    if (vc.Active)
                                                    {
                                                        if (String.IsNullOrWhiteSpace(vc.ExternalTable))
                                                        {
                                                            if (!ValidatePropertyValue(vc.FieldName, vc.FieldValue, obj, vc.Operator))
                                                            {
                                                                applyCondition = false;
                                                                break;     //una dintre conditii nu e indeplinita
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (vc.Nomenclature)
                                                            {
                                                                Models.Nomenclator n   = new Models.Nomenclator(authenticatedUserId, connectionString, vc.ExternalTable, vc.FieldValue);
                                                                PropertyInfo       pin = obj.GetType().GetProperty(vc.FieldName);
                                                                //if (!(Convert.ToInt32(n.ID) == Convert.ToInt32(pin.GetValue(obj))))
                                                                if (!ValidatePropertyValue(vc.FieldName, n.ID, obj, vc.Operator))
                                                                {
                                                                    applyCondition = false;
                                                                    break;
                                                                }
                                                            }
                                                            else
                                                            {
                                                                // TO DO: conditie pt. altele decat nomenclatoare
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                            if (applyCondition)
                                            {
                                                if (pi.GetValue(obj) == null || pi.GetValue(obj).ToString().Trim() == "")
                                                {
                                                    toReturn.Status     = false;
                                                    err                 = ErrorParser.ErrorMessage(v.ErrorCode);
                                                    toReturn.Message    = string.Format("{0}{1};", toReturn.Message ?? "", err.ERROR_MESSAGE);
                                                    toReturn.InsertedId = null;
                                                    toReturn.Error.Add(err);
                                                }
                                            }
                                            break;

                                        case "Confirmation":
                                            // ... TO DO ...
                                            break;

                                        case "Duplicate":
                                            try
                                            {
                                                Type typeOfThis   = obj.GetType();
                                                Type propertyType = pi.GetValue(obj).GetType();
                                                //ConstructorInfo[] cis = typeOfThis.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                                                ConstructorInfo ci = typeOfThis.GetConstructor(new Type[] { Type.GetType("System.Int32"), Type.GetType("System.String"), propertyType });

                                                if (ci != null && obj.GetType().GetProperty("ID").GetValue(obj) == null)     // doar la insert verificam dublura
                                                {
                                                    //Dosar dj = new Dosar(authenticatedUserId, connectionString, pi.GetValue(this).ToString()); // trebuie sa existe constructorul pt. campul trimis ca parametru !!!
                                                    dynamic dj = Activator.CreateInstance(typeOfThis, new object[] { authenticatedUserId, connectionString, pi.GetValue(obj) });
                                                    if (dj != null && dj.ID != null)
                                                    {
                                                        toReturn.Status     = false;
                                                        err                 = ErrorParser.ErrorMessage(v.ErrorCode);
                                                        toReturn.Message    = string.Format("{0}{1};", toReturn.Message ?? "", err.ERROR_MESSAGE);
                                                        toReturn.InsertedId = null;
                                                        toReturn.Error.Add(err);
                                                    }
                                                }
                                            }
                                            catch { }
                                            break;
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    succes = true;
                }
                else
                {
                    succes = false;
                }
            }catch { succes = false; }
            return(toReturn);
        }