using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Globalization;
using System.Data;

namespace CheckSheet
{
    public partial class saveimage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {

                string equid = string.Empty;
                string inspection = string.Empty;
                string inspectitem=string.Empty;
                string type = string.Empty;

                
                string imgbase64 = Page.Request["image"].ToString().Replace(" ", "+").Replace("sys*", "=");
               
                if(imgbase64.IndexOf("*")!=-1)
                {

                    string[] arr = imgbase64.Split('*');
                    imgbase64 = arr[0];
                    equid = arr[1];
                    inspection = arr[2];
                    type = arr[3];

                   



                }
                string UploadFolderPath = "~/piz/" + type + "/";
                string filename = equid + "_" + inspection +  "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss", new CultureInfo("en-US"));
                string path = Server.MapPath(UploadFolderPath) + filename + ".jpg";


                byte[] imageByteArray = Convert.FromBase64String(imgbase64);
                File.WriteAllBytes(path, imageByteArray);


                Response.Cookies["pizinfo"].Value = "../piz/" + type + "/" + filename + ".jpg";




            }

        }
    }
}