예제 #1
0
        public static response GenerateImgThumbNail(string sType, string path, string fileName, int width, int height)
        {
            FileInfo fi = new FileInfo(Path.Combine(path, fileName));
            //string outputFile = fileName.Replace(fi.Extension, sType == "s" ? "_s.gif" : "_m.gif");
            string outputFile = fileName.Replace(fi.Extension, "_" + sType + ".jpg");

            switch (fi.Extension.ToLower())
            {
            case ".pdf":
                try
                {
                    FileStream       fs   = new FileStream(Path.Combine(path, fileName), FileMode.Open, FileAccess.Read);
                    PdfFixedDocument pDoc = new PdfFixedDocument(fs);
                    fs.Dispose();
                    PdfPageRenderer     renderer = new PdfPageRenderer(pDoc.Pages[0]);
                    PdfRendererSettings s        = new PdfRendererSettings();
                    s.DpiX = s.DpiY = 96;

                    FileStream pngStream = File.OpenWrite(Path.Combine(path, fileName.Replace(".pdf", ".png")));
                    renderer.ConvertPageToImage(pngStream, PdfPageImageFormat.Png, s);
                    pngStream.Flush();
                    pngStream.Dispose();

                    response r = SaveThumbNail(sType, path, fileName.Replace(".pdf", ".png"), null, width, height);
                    try
                    {
                        File.Delete(Path.Combine(path, fileName.Replace(".pdf", ".png")));
                    }
                    catch { }
                    return(r);

                    //return new response(false, "eroare", null, 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)
                    })); }

            case ".jpg":
            case ".jpeg":
            case ".png":
            case ".bmp":
                try
                {
                    return(SaveThumbNail(sType, path, fileName, null, width, height));
                }
                catch (Exception exp) { LogWriter.Log(exp); return(new response(false, exp.ToString(), null, null, new System.Collections.Generic.List <Error>()
                    {
                        new Error(exp)
                    })); }

            default:
                Error err = ErrorParser.ErrorMessage("unsupportedFormat");
                return(new response(false, err.ERROR_MESSAGE, null, null, new System.Collections.Generic.List <Error>()
                {
                    err
                }));
            }
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
0
 public static string MySqlErrorParser(MySqlException mySqlException)
 {
     return(ErrorParser.ParseError(mySqlException));
 }
예제 #5
0
        public static response ExportDocumenteDosarToPdf(Models.Dosar dosar)
        {
            try
            {
                PdfFixedDocument        poDocument = new PdfFixedDocument();
                Models.DocumentScanat[] ds         = (Models.DocumentScanat[])dosar.GetDocumente().Result;
                foreach (Models.DocumentScanat dsj in ds)
                {
                    try
                    {
                        if (dsj.VIZA_CASCO)
                        {
                            //MemoryStream ms = new MemoryStream(dsj.FILE_CONTENT); // -- pt. citire content fisier din  BD
                            FileStream ms = File.Open(Path.Combine(CommonFunctions.GetScansFolder(), dsj.CALE_FISIER), FileMode.Open, FileAccess.Read);
                            switch (dsj.EXTENSIE_FISIER.Replace(".", "").ToLower())
                            {
                            case "pdf":
                                PdfFixedDocument pd = new PdfFixedDocument(ms);
                                for (int i = 0; i < pd.Pages.Count; i++)
                                {
                                    poDocument.Pages.Add(pd.Pages[i]);
                                }
                                break;

                            case "png":
                                Xfinium.Pdf.Graphics.PdfPngImage pngImg = new Xfinium.Pdf.Graphics.PdfPngImage(ms);
                                PdfPage       p   = new PdfPage();
                                ThumbNailSize tns = ThumbNails.ScaleImage(pngImg, p.Width - PDF_PAGE_MARGIN, p.Height - PDF_PAGE_MARGIN);
                                p.Graphics.DrawImage(pngImg, (p.Width - tns.Width) / 2, (p.Height - tns.Height) / 2, tns.Width, tns.Height);
                                //p.Graphics.DrawImage(pngImg, 0, 0, p.Width, p.Height);
                                poDocument.Pages.Add(p);
                                break;

                            case "jpg":
                            case "jpeg":
                                Xfinium.Pdf.Graphics.PdfJpegImage jpgImg = new Xfinium.Pdf.Graphics.PdfJpegImage(ms);
                                p   = new PdfPage();
                                tns = ThumbNails.ScaleImage(jpgImg, p.Width - PDF_PAGE_MARGIN, p.Height - PDF_PAGE_MARGIN);
                                p.Graphics.DrawImage(jpgImg, (p.Width - tns.Width) / 2, (p.Height - tns.Height) / 2, tns.Width, tns.Height);
                                //p.Graphics.DrawImage(jpgImg, 0, 0, p.Width, p.Height);
                                poDocument.Pages.Add(p);
                                break;

                            case "tiff":
                                Xfinium.Pdf.Graphics.PdfTiffImage tiffImg = new Xfinium.Pdf.Graphics.PdfTiffImage(ms);
                                p   = new PdfPage();
                                tns = ThumbNails.ScaleImage(tiffImg, p.Width - PDF_PAGE_MARGIN, p.Height - PDF_PAGE_MARGIN);
                                p.Graphics.DrawImage(tiffImg, (p.Width - tns.Width) / 2, (p.Height - tns.Height) / 2, tns.Width, tns.Height);
                                //p.Graphics.DrawImage(tiffImg, 0, 0, p.Width, p.Height);
                                poDocument.Pages.Add(p);
                                break;

                            default:
                                ms.Flush();
                                ms.Dispose();
                                throw new Exception("unsupportedFormat");
                            }
                            ms.Flush();
                            ms.Dispose();
                        }
                    }
                    catch (Exception exp) { LogWriter.Log(exp); }
                }
                if (poDocument.Pages.Count > 0)
                {
                    string     fileName = dosar.NR_DOSAR_CASCO.Replace('/', '_').Replace(' ', '_') + "_documente.pdf";
                    FileStream fs       = File.Open(Path.Combine(CommonFunctions.GetPdfsFolder(), fileName), FileMode.Create, FileAccess.ReadWrite);
                    poDocument.Save(fs);
                    fs.Flush();
                    fs.Dispose();
                    return(new response(true, Path.Combine(CommonFunctions.GetPdfsFolder(), fileName), Path.Combine(CommonFunctions.GetPdfsFolder(), fileName), null, null));
                }
                else
                {
                    return(new response(false, ErrorParser.ErrorMessage("dosarFaraDocumente").ERROR_MESSAGE, null, null, new List <Error>()
                    {
                        ErrorParser.ErrorMessage("dosarFaraDocumente")
                    }));
                }
            }
            catch (Exception exp) { LogWriter.Log(exp); return(new response(false, exp.Message, null, null, new System.Collections.Generic.List <Error>()
                {
                    new Error(exp)
                })); }
        }
예제 #6
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);
        }