Esempio n. 1
0
        public static response ValidareColoane(object item, string fieldValueCollection)
        {
            response toReturn = new response(true, null, null, null, new List <Error>());

            try
            {
                Dictionary <string, string> changes = JsonConvert.DeserializeObject <Dictionary <string, string> >(fieldValueCollection);
                foreach (string fieldName in changes.Keys)
                {
                    bool           gasit = false;
                    PropertyInfo[] props = item.GetType().GetProperties();
                    foreach (PropertyInfo prop in props)
                    {
                        if (fieldName.ToUpper() == prop.Name.ToUpper())
                        {
                            gasit = true;
                            break;
                        }
                    }
                    if (!gasit)
                    {
                        Error err = ErrorParser.ErrorMessage("campInexistentInTabela");
                        return(new response(false, err.ERROR_MESSAGE, null, null, new List <Error>()
                        {
                            err
                        }));
                    }
                }
            }
            catch
            {
                Error err = ErrorParser.ErrorMessage("cannotConvertStringToTableColumns");
                return(new response(false, err.ERROR_MESSAGE, null, null, new List <Error>()
                {
                    err
                }));
            }
            return(toReturn);
        }
Esempio n. 2
0
        /// <summary>
        /// Metoda pentru executarea operatiilor de selectie a unui scalar din baza de date
        /// </summary>
        /// <returns>obiect scalar rezultat din selectie</returns>
        public response ExecuteScalarQuery()
        {
            response toReturn = new response();

            try
            {
                mySqlConnection.Open();
                object ret = mySqlCommand.ExecuteScalar();
                toReturn = new response(true, "", ret, null, null);
                mySqlConnection.Close();
            }
            catch (Exception exp)
            {
                //mySqlException.ToString();
                //toReturn = null;
                //throw exp;
                toReturn = new response(false, exp.Message, null, null, new List <Error>()
                {
                    new Error(exp)
                });
            }
            return(toReturn);
        }
Esempio n. 3
0
        public static response CreateZipFromDosar(Models.Dosar dosar, bool bulk) // bulk = false - fisiere grupate pe tip documente / bulk = true - fisiere la gramada
        {
            response r = new response();

            try
            {
                Models.DocumentScanat[] dss = (Models.DocumentScanat[])dosar.GetDocumente().Result;
                //Models.TipDocument[] tds = (Models.TipDocument[])dosar.GetDocumenteTipuri().Result;

                string zipFilePath = Path.Combine(CommonFunctions.GetTempFolder(), String.Format("{0}.zip", dosar.NR_DOSAR_CASCO));
                using (FileStream zipFile = new FileStream(zipFilePath, FileMode.Create))
                {
                    using (ZipArchive archive = new ZipArchive(zipFile, ZipArchiveMode.Create))
                    {
                        foreach (Models.DocumentScanat ds in dss)
                        {
                            try
                            {
                                if (ds.VIZA_CASCO)
                                {
                                    response        rg    = PdfGenerator.GeneratePdfWithSignatureFromDocument(ds);
                                    ZipArchiveEntry entry = null;
                                    if (!bulk)
                                    {
                                        //entry = archive.CreateEntry(String.Format("{0}/{1}", dosar.NR_DOSAR_CASCO, ds.DENUMIRE_FISIER), CompressionLevel.Optimal); // old version - fara semnatura digitala
                                        entry = archive.CreateEntry(String.Format("{0}/{1}", dosar.NR_DOSAR_CASCO, rg.Message), CompressionLevel.Optimal);
                                    }
                                    else
                                    {
                                        Models.TipDocument td = (Models.TipDocument)ds.GetTipDocument().Result;
                                        //entry = archive.CreateEntry(String.Format("{0}/{1}/{2}", dosar.NR_DOSAR_CASCO, td.DENUMIRE, ds.DENUMIRE_FISIER), CompressionLevel.Optimal); // old version - fara semnatura digitala
                                        entry = archive.CreateEntry(String.Format("{0}/{1}/{2}", dosar.NR_DOSAR_CASCO, td.DENUMIRE, rg.Message), CompressionLevel.Optimal);
                                    }
                                    using (BinaryWriter writer = new BinaryWriter(entry.Open()))
                                    {
                                        /*
                                         * ds.GetFileContent();
                                         * writer.Write(ds.FILE_CONTENT);
                                         * writer.Flush();
                                         */
                                        byte[] src = File.ReadAllBytes(rg.Result.ToString());
                                        writer.Write(src);
                                        writer.Flush();
                                        File.Delete(rg.Result.ToString());
                                    }
                                }
                            }catch (Exception exp)
                            {
                                LogWriter.Log(exp);
                            }
                        }
                    }
                }
                return(new response(true, zipFilePath, zipFilePath, null, null));
            }
            catch (Exception exp)
            {
                LogWriter.Log(exp);
                return(new response(false, exp.Message, null, null, new List <Error>()
                {
                    new Error(exp)
                }));
            }
        }
Esempio n. 4
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)
                        {
                            foreach (PropertyInfo pi in pis)
                            {
                                if (v.FieldName.ToUpper() == pi.Name.ToUpper())
                                {
                                    switch (v.ValidationType)
                                    {
                                    case "Mandatory":
                                        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 == null ? "" : 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 == null ? "" : 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);
        }
Esempio n. 5
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);
        }