Example #1
0
 public response Avizare(bool _avizat)
 {
     try
     {
         DataAccess da = new DataAccess(authenticatedUserId, connectionString, CommandType.StoredProcedure, "DOCUMENTE_SCANATEsp_Avizare", new object[] { new MySqlParameter("_ID", this.ID), new MySqlParameter("_AVIZAT", _avizat) });
         response   r  = da.ExecuteUpdateQuery();
         if (r.Status)
         {
             try
             {
                 MesajeRepository mr          = new MesajeRepository(authenticatedUserId, connectionString);
                 string           partial_sub = String.Format("DOCUMENT {0}", _avizat ? "NOU" : "ELIMINAT DIN DOSAR");
                 string           subiect     = String.Format("{0} ({1})", partial_sub, ((Nomenclator) new NomenclatoareRepository(authenticatedUserId, connectionString).Find("tip_document", Convert.ToInt32(this.ID_TIP_DOCUMENT)).Result).DENUMIRE);
                 Dosar            d           = new Dosar(authenticatedUserId, connectionString, Convert.ToInt32(this.ID_DOSAR));
                 if (d.IsAvizat())
                 {
                     mr.GenerateAndSendMessage(this.ID_DOSAR, DateTime.Now, subiect, subiect, partial_sub, authenticatedUserId, (int)Importanta.Low);
                 }
             }
             catch { }
         }
         return(new response(true, null, r, 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 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)
                }));
            }
        }