示例#1
0
 public static string converRut(string rut, int opcion)
 {
     try
     {
         if (opcion == 1) //convierte de rut cualquiera a tipo ficha
         {
             rut = rut.Replace(".", "").Replace("-", "");
             var cant = rut.ToCharArray().Count();
             var Rut  = rut.Substring(0, cant - 1);
             var flag = true;
             while (flag)
             {
                 flag = false;
                 if (Rut.StartsWith("0"))
                 {
                     Rut  = Rut.Substring(1, cant - 2);
                     flag = true;
                 }
             }
             return(Rut);
         }
         else if (opcion == 2) //convierte rut ingresado a formato softland
         {
             var cant = rut.ToCharArray().Count();
             while (cant < 13)
             {
                 rut  = rut.Insert(0, "0");
                 cant = rut.ToCharArray().Count();
             }
             return(rut);
         }
         else // convierte rut a formato visible
         {
             while (rut.StartsWith("0"))
             {
                 rut = rut.Substring(1);
             }
             return(rut);
         }
     }
     catch (Exception e)
     {
         ErrorService.LogError(e);
         return("");
     }
 }
示例#2
0
        public string createFile(HttpPostedFileBase file, string tipo_documento, string cliente)
        {
            Random       random        = new Random();
            const string chars         = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
            string       fileName      = new string(Enumerable.Repeat(chars, 5).Select(s => s[random.Next(s.Length)]).ToArray());
            DateTime     dateTime      = DateTime.Now;
            string       year          = dateTime.ToString("yyyy");
            string       month         = dateTime.ToString("MM");
            string       relative_path = "";
            string       path          = "";
            string       route         = "";

            try
            {
                // if (!IsValidDocument(file)) { return null; }

                fileName      = tipo_documento + "_" + dateTime.ToString("yyyyMMddHHmmssfff") + "_" + fileName + Path.GetExtension(file.FileName);
                relative_path = "~/Files/" + cliente + "/" + tipo_documento + "/" + fileName;
                path          = System.Web.Hosting.HostingEnvironment.MapPath("~/Files/" + cliente + "/" + tipo_documento + "/" + fileName);
                route         = System.Web.Hosting.HostingEnvironment.MapPath("~/Files/" + cliente + "/" + tipo_documento);

                Directory.CreateDirectory(route);
                var data = new byte[file.ContentLength];
                file.InputStream.Read(data, 0, file.ContentLength);
                using (var sw = new FileStream(path, FileMode.Create))
                {
                    sw.Write(data, 0, data.Length);
                }
                return(relative_path);
            }
            catch (Exception ex)
            {
                ErrorService.LogError(ex);
                return(null);
            }
        }