Ejemplo n.º 1
0
        public override object GetData(int actionType)
        {
            //return base.GetData(actionType);
            ResponseObj = new TransObj();
            StringBuilder sql;
            ExcelLoader   exLoader;
            string        path;
            int           cat, i = 0;

            try
            {
                switch ((ActionType)actionType)
                {
                case ActionType.GetCatalog:
                    #region GetCatalog
                    GeneralController catController = new CatalogsController();
                    //cat = int.Parse(RequestObj.TransParms.Where(p => p.Key == "cat").FirstOrDefault().Value);
                    catController.RequestObj = this.RequestObj;
                    return(catController.GetData((int)CatalogsController.ActionType.GetCatalog));

                    #endregion
                case ActionType.GetWorksheets:
                    #region GetWorksheets
                    path     = JsonConvert.DeserializeObject <string>(RequestObj.TransParms.Where(p => p.Key == "fName").FirstOrDefault().Value);
                    exLoader = new ExcelLoader();
                    return(exLoader.LoadWorkSheets(path));

                    #endregion
                case ActionType.ImportDespachos:
                    #region ImportDespachos
                    path = JsonConvert.DeserializeObject <string>(RequestObj.TransParms.Where(p => p.Key == "fName").FirstOrDefault().Value);
                    string workSheet = JsonConvert.DeserializeObject <string>(RequestObj.TransParms.Where(p => p.Key == "workSheet").FirstOrDefault().Value);
                    exLoader      = new ExcelLoader();
                    DtDespachosIn = exLoader.LoadFile(path, workSheet);
                    return(true);

                    #endregion
                case ActionType.LoadRemitente:
                    #region LoadRemitente
                    var clts = Entities.Database.SqlQuery <GeneralCat>(SQL_GET_CLIENTES).ToList();
                    clts.Insert(0, new GeneralCat {
                        catId = -1, catVal = "Seleccione..."
                    });

                    return(clts);

                    #endregion
                case ActionType.LoadCitiesFullName:
                    #region LoadCitiesFullName
                    CitiesFullNames = Entities.Database.SqlQuery <GeneralCat>(SQL_CIUDADES).ToList();
                    #endregion
                    break;

                case ActionType.LoadProveedores:
                    #region LoadProveedores
                    Proveedores = Entities.Database.SqlQuery <GeneralCat>(string.Format(SQL_PROVEEDORES, ClienteID)).ToList();
                    #endregion
                    break;

                case ActionType.IsInDespacho:
                    #region IsInDespacho
                    ConsecCliente = Entities.Database.SqlQuery <string>(SQL_IS_IN_DESPACHO, ClienteID).ToList();
                    #endregion
                    break;

                case ActionType.InsertDespachos:
                    #region InsertDespachos
                    //int cId = JsonConvert.DeserializeObject<int>(RequestObj.TransParms.Where(p => p.Key == "cId").FirstOrDefault().Value);
                    DataRow r = null;
                    sql = new StringBuilder();
                    string s = "", conCliente = "";
                    try
                    {
                        for (i = 0; i < DtDespachosOut.Rows.Count; i++)
                        {
                            r = DtDespachosOut.Rows[i];
                            if (r[COL_CONSECUTIVO_CLIENTE].ToString().Trim().Length == 0)
                            {
                                continue;
                            }
                            conCliente = r[COL_CONSECUTIVO_CLIENTE].ToString();
                            var e = Entities.LGC_DESPACHO.
                                    Where(d => d.CONSECUTIVO_CLIENTE == conCliente)
                                    .FirstOrDefault();
                            if (e != null)
                            {
                                sql.Clear(); throw new GeneralControllerException(string.Format("El registro en la fila {0} ya existe.(Consec:{1})", i + 1, conCliente));
                            }
                            s = string.Format(SQL_IN_DESPACHO,
                                              ClienteID,
                                              EntUtils.GetStrFromDtRow(r, GV_COL_CONSECUTIVO),
                                              EntUtils.GetStrFromDtRow(r, GV_COL_CONSECUTVO_AVMK),
                                              EntUtils.GetStrFromDtRow(r, GV_COL_CONSECUTIVO_CLIENTE),
                                              EntUtils.GetDTFromDtRow(r, GV_COL_FECHA_ENVIO_ARCHIVO, false).Value.ToString("dd/MM/yyyy"),
                                              "",
                                              "",
                                              EntUtils.GetDTFromDtRow(r, GV_COL_FECHA_DE_REDENCION, false).Value.ToString("dd/MM/yyyy"),
                                              EntUtils.GetStrFromDtRow(r, GV_COL_CEDULA),
                                              EntUtils.GetStrFromDtRow(r, GV_COL_CLIENTE),
                                              EntUtils.GetStrFromDtRow(r, GV_COL_ENTREGAR_A),
                                              EntUtils.GetStrFromDtRow(r, GV_COL_DIRECCION),
                                              EntUtils.GetStrFromDtRow(r, GV_COL_CIUDAD),
                                              EntUtils.GetIntFromDtRow(r, GV_COL_DEPARTAMENTO),
                                              EntUtils.GetStrFromDtRow(r, GV_COL_TELEFONO),
                                              EntUtils.GetStrFromDtRow(r, GV_COL_CELULAR),
                                              EntUtils.GetStrFromDtRow(r, GV_COL_CORREO_ELECTRONICO),
                                              EntUtils.GetStrFromDtRow(r, GV_COL_CODIGO_PREMIO),
                                              EntUtils.GetStrFromDtRow(r, GV_COL_PREMIO),
                                              EntUtils.GetStrFromDtRow(r, GV_COL_ESPECIFICACIONES),
                                              EntUtils.GetIntFromDtRow(r, GV_COL_PROVEEDOR),
                                              EntUtils.GetIntFromDtRow(r, GV_COL_CANTIDAD),
                                              EntUtils.GetIntFromDtRow(r, GV_COL_VALOR),
                                              ClienteID);
                            sql.Append(s);
                        }
                        DataBaseUtils dbUtils = new DataBaseUtils();
                        return(dbUtils.RunScriptFromStngBldr(sql, Entities));
                    }
                    catch (Exception ex)
                    {
                        string rData = "";
                        if (r != null)
                        {
                            rData = string.Join("|", r.ItemArray);
                        }
                        throw new Exception(string.Format("Error en fila {0}. [{1}] ", i + 1, rData) + ex.Message);
                    }

                    #endregion
                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(ResponseObj);
        }