using System;
using System.IO;
using System.Diagnostics;
using System.Xml;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace MYAPP.Manage.Project.Design.Scene
{
    [AjaxPro.AjaxNamespace("AjaxDemo")]
    public partial class List_TreeScene : MyApp.Web.UI.UserPage
    {
        public int PageRecord = 10000, NowPage, RecordCount, hRecordCount, MaxPage;
        public DataTable list_dt;
        public string _Tour_ID = "", _TypeID = "";
        protected override void AppInit()
        {
            try
            {
                _TypeID = Request.QueryString["TypeID"].Trim();
            }
            catch (Exception) { _TypeID = ""; }
            try
            {
                _Tour_ID = Request.QueryString["Tour_ID"].Trim();

            }
            catch (Exception)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert('错误!!!');history.back()</script>");
                return;
            }
            base.AppInit();
        }

        protected override void pl_register_script()
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(List_TreeScene));
            base.pl_register_script();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            MyApp.Components.NavUrl.SetUrl(2);
            try
            {
                Page.DataBind();
            }
            catch (Exception) { }

        }

        protected override void DataInit()
        {

            if (_TypeID == "-1")
            {
                list_dt = MyApp.Components.KRPano.Project.GetDirectorys(String.Format("{0}/Scene", _Tour_ID), "", PageRecord, ref NowPage, ref RecordCount, ref hRecordCount, ref MaxPage);
            }
            else
            {
                list_dt = MyApp.Components.KRPano.Project.GetDirectorys(String.Format("{0}/Scene", _Tour_ID), String.Format("Type='{0}'", _TypeID), PageRecord, ref NowPage, ref RecordCount, ref hRecordCount, ref MaxPage);
            }

            #region
            DataSet myds = new DataSet();
            DataTable dt_type = MyApp.Components.KRPano.Tour.Get_TypeTreeTable(_Tour_ID);
            myds.Tables.Add(dt_type);
            DataRow dr = dt_type.NewRow(); dr["id"] = "0"; dt_type.Rows.Add(dr);
            myds.Relations.Add("NodeRelation", dt_type.Columns["id"], dt_type.Columns["upid"]);
            PopulateSubTree(dr, 1, 0, "", true);
            #endregion
            this.TypeID.SelectedValue = _TypeID;
            base.DataInit();
        }

        private void PopulateSubTree(DataRow dbRow, int level, int _UpID, string ne, bool _enable_tf)
        {
            int len = dbRow.GetChildRows("NodeRelation").Length;
            int i = 0;
            string dr_head = "";
            foreach (DataRow dr in dbRow.GetChildRows("NodeRelation"))
            {
                if (level > -1)
                {
                    if (i == (len - 1))
                    {
                        dr_head = ne + "└";
                    }
                    else
                    {
                        dr_head = ne + "├";
                    }
                }

                if (_enable_tf)
                {
                    this.TypeID.Items.Add(new ListItem(dr_head + dr["name"].ToString(), dr["id"].ToString()));
                }
                else
                {
                    this.TypeID.Items.Add(new ListItem(dr_head + dr["name"].ToString(), "-" + dr["id"].ToString()));
                }
                if (i == len - 1)
                {
                    PopulateSubTree(dr, level + 1, Convert.ToInt32(dr["id"]), ne + "　", _enable_tf);
                }
                else
                {
                    PopulateSubTree(dr, level + 1, Convert.ToInt32(dr["id"]), ne + "│", _enable_tf);
                }
                i++;
            }
        }

        public string GetElemValueByPath(object _Scene_ID, string attribute)
        {
            return MyApp.Components.KRPano.Scene.GetValue(MyApp.Components.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, _Scene_ID), "/krpano", attribute);
        }

        public string GetElemValueByPath(object _Scene_ID, string path, string attribute)
        {
            return MyApp.Components.KRPano.Scene.GetValue(MyApp.Components.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, _Scene_ID), path, attribute);
        }

        [AjaxPro.AjaxMethod]
        public bool SetDefScene(object _Tour_ID, object scene_id)
        {
            try
            {
                XmlDocument xmldoc = MyApp.Components.XML.XmlDocument.Load(MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID));
                XmlElement elem_Project = (XmlElement)xmldoc.GetElementsByTagName("Project", "")[0];

                SetElemValue(elem_Project, "DefScene_ID", scene_id.ToString());

                MyApp.Components.XML.XmlDocument.WriteAllText(Server.MapPath(MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID)), xmldoc.OuterXml);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        [AjaxPro.AjaxMethod]
        public string akcube2sphere(object _Tour_ID)
        {
            var list_dt = MyApp.Components.KRPano.Project.GetDirectorysTable(String.Format("{0}/Scene", _Tour_ID));
            try
            {
                foreach (DataRow dr in list_dt.Rows)
                {
                    kcube2sphere(_Tour_ID, dr["Name"]);
                }
                return "true";
            }
            catch (Exception ex)
            {
                COE.Components.MyFun.ReturnName();
                return ex.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string kcube2sphere(object _Tour_ID, object _Scene_ID)
        {
            COE.Components.MyFun.ChangeName();

            try
            {
                Process process = new Process();
                process.StartInfo.FileName = MyApp.Components.File.FileManage.GetRootDir("\\pano\\kcube2sphere.exe");
                process.StartInfo.Arguments = string.Format("-l={0}/cube/b_l.jpg -f={0}/cube/b_f.jpg -r={0}/cube/b_r.jpg -b={0}/cube/b_b.jpg -u={0}/cube/b_u.jpg -d={0}/cube/b_d.jpg -o={0}/b.jpg", MyApp.Components.File.FileManage.GetRootDir(String.Format("/Project/{0}/scene/{1}/", _Tour_ID, _Scene_ID)));
                process.StartInfo.WorkingDirectory = MyApp.Components.File.FileManage.GetRootDir(String.Format("/Project/{0}/scene/{1}", _Tour_ID, _Scene_ID));
                process.Start();

                process.WaitForExit();

                #region 生成预览图
                process.StartInfo.FileName = MyApp.Components.File.FileManage.GetRootDir("\\pano\\kmakepreview.exe");
                process.StartInfo.Arguments = "b.jpg" + " -o=" + "s.jpg" + " -size=1024x512 -q -smooth=20";
                process.StartInfo.WorkingDirectory = MyApp.Components.File.FileManage.GetRootDir(String.Format("/Project/{0}/scene/{1}", _Tour_ID, _Scene_ID));
                process.Start();
                process.WaitForExit();
                #endregion

                COE.Components.MyFun.ReturnName();
                return "true";
            }
            catch (Exception ex)
            {
                COE.Components.MyFun.ReturnName();
                return ex.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string ExportSingleSwf(object _Tour_ID, object _Scene_ID)  //导出单个场景SWF文件
        {
            if (System.IO.Directory.Exists(Server.MapPath(String.Format(MyApp.Components.KRPano.Scene._Root_Dir + "/cube", _Tour_ID, _Scene_ID))))
            {
                COE.Components.MyFun.ChangeNameExport();

                Process process = new Process();
                try
                {
                    process.StartInfo.FileName = MyApp.Components.File.FileManage.GetRootDir("\\pano\\kprotectcl.exe");
                    process.StartInfo.Arguments = string.Format(" -o={2} -bf -xml={0} -filelist={1} -q", MyApp.Components.File.FileManage.GetRootDir("/Data/Config/SingleSceneTemplate.xml"), MyApp.Components.File.FileManage.GetRootDir("/Data/Config/filelist.txt"), MyApp.Components.File.FileManage.GetRootDir(String.Format("/Project/{0}/Export/{1}.swf", _Tour_ID, _Scene_ID)));
                    //process.StartInfo.Arguments += " -baseswf=krpano.swf ";

                    // process.StartInfo.Arguments = " -o=../../Export/" + _Scene_ID + ".swf  -bf -xml=" + MyApp.Components.File.FileManage.GetRootDir("/Data/Config/SingleSceneTemplate.xml") + " -q ";
                    process.StartInfo.WorkingDirectory = MyApp.Components.File.FileManage.GetRootDir(String.Format("/Project/{0}/scene/{1}", _Tour_ID, _Scene_ID));
                    process.Start();

                    process.WaitForExit();

                    COE.Components.MyFun.ReturnNameExport();
                    return "true";
                }
                catch (Exception ex)
                {
                    COE.Components.MyFun.ReturnNameExport();
                    return ex.ToString();
                }
            }
            else
            {
                return "六面体切块文件被删除,无法导出单个SWF场景文件!!!";
            }
        }

        [AjaxPro.AjaxMethod]
        public string ksphere2cube(object _Tour_ID, object _Scene_ID)
        {
            COE.Components.MyFun.ChangeName();

            try
            {
                Process process = new Process();
                #region 生成CUBE图
                process.StartInfo.FileName = MyApp.Components.File.FileManage.GetRootDir("\\pano\\ktransform.exe");
                process.StartInfo.Arguments = "cube6 b.jpg" + " cube/b.jpg";
                process.StartInfo.WorkingDirectory = MyApp.Components.File.FileManage.GetRootDir(String.Format("/Project/{0}/scene/{1}", _Tour_ID, _Scene_ID));
                process.Start();
                process.WaitForExit();
                #endregion

                #region
                XmlDocument xmldoc = MyApp.Components.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, _Scene_ID);
                XmlElement elem_Image = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/image");
                SetElemValue(elem_Image, "type", "CUBE");

                XmlDocument xml_b = MyApp.Components.XML.XmlDocument.Load("/Data/Templates/Scene/scene.xml");
                XmlElement elem_b = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xml_b, "/krpano/image");
                elem_Image.InnerXml = elem_b.InnerXml;
                MyApp.Components.XML.XmlDocument.WriteAllText(MyApp.Components.KRPano.Scene.GetSceneServerFilePath(_Tour_ID, _Scene_ID), xmldoc.OuterXml);
                #endregion

                COE.Components.MyFun.ReturnName();
                return "true";
            }
            catch (Exception ex)
            {
                COE.Components.MyFun.ReturnName();
                return ex.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string KMultires(object _Tour_ID, object _Scene_ID)
        {
            COE.Components.MyFun.ChangeName();

            XmlDocument xmldoc;
            xmldoc = MyApp.Components.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, _Scene_ID);

            try
            {
                Process process = new Process();
                process.StartInfo.FileName = MyApp.Components.File.FileManage.GetRootDir("\\pano\\kmakemultires.exe");
                if (System.IO.Directory.Exists(MyApp.Components.File.FileManage.GetRootDir(String.Format("/Project/{0}/scene/{1}/cube", _Tour_ID, _Scene_ID))))
                {
                    process.StartInfo.Arguments = String.Format(" templates\\multires.config {0}\\b_*.jpg", MyApp.Components.File.FileManage.GetRootDir(String.Format("/Project/{0}/scene/{1}/cube", _Tour_ID, _Scene_ID)));
                }
                else
                {
                    process.StartInfo.Arguments = "b.jpg";
                }

                process.StartInfo.Arguments += " quiet=false ";
                process.StartInfo.WorkingDirectory = MyApp.Components.File.FileManage.GetRootDir(String.Format("\\pano", _Tour_ID, _Scene_ID));
                process.Start();

                process.WaitForExit();
                //return process.StartInfo.FileName +" " +process.StartInfo.Arguments;

                #region 全景图
                XmlDocument xml_b = new XmlDocument();

                xml_b.Load(MyApp.Components.File.FileManage.GetRootDir(String.Format("/Project/{0}/scene/{1}/b.xml", _Tour_ID, _Scene_ID)));

                XmlElement elem_Image = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/image");
                XmlElement elem_b = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xml_b, "/krpano/image");

                elem_Image.SetAttribute("multires", elem_b.GetAttribute("multires"));
                elem_Image.SetAttribute("type", elem_b.GetAttribute("type"));
                elem_Image.SetAttribute("tilesize", elem_b.GetAttribute("tilesize"));

                elem_Image.InnerXml = elem_b.InnerXml;
                #endregion

                MyApp.Components.XML.XmlDocument.WriteAllText(MyApp.Components.KRPano.Scene.GetSceneServerFilePath(_Tour_ID, _Scene_ID), xmldoc.OuterXml);

                //MyApp.Components.XML.XmlDocument.WriteAllText(Server.MapPath(String.Format("/Project/{0}/scene/{1}/include_scene.xml", _Tour_ID, _Scene_ID)), xmldoc.ChildNodes[0].InnerXml);

                try
                {
                    System.IO.File.Delete(MyApp.Components.File.FileManage.GetRootDir(String.Format("/Project/{0}/scene/{1}/b.xml", _Tour_ID, _Scene_ID)));
                }
                catch (Exception) { }

                COE.Components.MyFun.ReturnName();
                return "true";
            }
            catch (Exception ex)
            {
                COE.Components.MyFun.ReturnName();
                return ex.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string KPreview(object _Tour_ID, object _Scene_ID)
        {
            COE.Components.MyFun.ChangeName();

            try
            {
                Process process = new Process();
                process.StartInfo.FileName = MyApp.Components.File.FileManage.GetRootDir("\\pano\\kmakepreview.exe");
                if (System.IO.Directory.Exists(MyApp.Components.File.FileManage.GetRootDir(String.Format("/Project/{0}/scene/{1}/cube", _Tour_ID, _Scene_ID))))
                {
                    process.StartInfo.Arguments = "-o=s.jpg -cs -l=cube/b_l.jpg -f=cube/b_f.jpg -r=cube/b_r.jpg -b=cube/b_b.jpg -u=cube/b_u.jpg -d=cube/b_d.jpg";
                }
                else
                {
                    return "生成失败:缺少CUBE六面体文件!!!";
                    //process.StartInfo.Arguments = "-o=s.jpg -cs b.jpg";
                }
                process.StartInfo.WorkingDirectory = MyApp.Components.File.FileManage.GetRootDir(String.Format("/Project/{0}/scene/{1}", _Tour_ID, _Scene_ID));
                process.Start();

                process.WaitForExit();

                COE.Components.MyFun.ReturnName();
                return "true";
            }
            catch (Exception ex)
            {
                COE.Components.MyFun.ReturnName();
                return ex.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public bool KPreviewAll(object _Tour_ID)
        {
            var list_dt = MyApp.Components.KRPano.Project.GetDirectorysTable(String.Format("{0}/Scene", _Tour_ID));
            try
            {
                foreach (DataRow dr in list_dt.Rows)
                {
                    KPreview(_Tour_ID, dr["Name"]);
                }
                return true;
            }
            catch (Exception) { return false; }
        }

        [AjaxPro.AjaxMethod]
        public bool KMultiresAll(object _Tour_ID)
        {
            var list_dt = MyApp.Components.KRPano.Project.GetDirectorysTable(String.Format("{0}/Scene", _Tour_ID));
            try
            {
                foreach (DataRow dr in list_dt.Rows)
                {
                    KMultires(_Tour_ID, dr["Name"]);
                }
                return true;
            }
            catch (Exception) { return false; }
        }

        public int Get_SPIC(string _Scene_ID)
        {
            if (MyApp.Components.KRPano.Scene.IsSceneExist("T", _Tour_ID, _Scene_ID))
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }

        [AjaxPro.AjaxMethod]
        public bool MoveScene(object _Tour_ID, string _Scene_ID, string _ToTypeID)
        {
            var list_dt = _Scene_ID.Split(',');
            try
            {
                foreach (string scene_id in list_dt)
                {
                    XmlDocument xmldoc = MyApp.Components.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, scene_id);
                    XmlElement elem_krpano = (XmlElement)xmldoc.GetElementsByTagName("krpano", "")[0];
                    SetElemValue(elem_krpano, "TypeID", _ToTypeID);

                    #region SSet
                    XmlElement elem_sset = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/SSet");
                    SetElemValue(elem_sset, "Scene_ID", scene_id);
                    SetElemValue(elem_sset, "TypeID", _ToTypeID);
                    SetElemValue(elem_sset, "GoogleMapTF", elem_krpano.GetAttribute("GoogleMapTF"));
                    #endregion

                    MyApp.Components.XML.XmlDocument.WriteAllText(MyApp.Components.KRPano.Scene.GetSceneServerFilePath(_Tour_ID, scene_id), xmldoc.OuterXml);
                }
                return true;
            }
            catch (Exception) { return false; }
        }

        [AjaxPro.AjaxMethod]
        public bool heading(object _Tour_ID, string _Scene_ID, string _heading)
        {
            decimal heading = 0;
            try
            {
                heading = Convert.ToDecimal(_heading);
            }
            catch (Exception) { heading = 0; }
            var list_dt = _Scene_ID.Split(',');
            try
            {
                foreach (string scene_id in list_dt)
                {
                    XmlDocument xmldoc = MyApp.Components.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, scene_id);
                    XmlElement elem_krpano = (XmlElement)xmldoc.GetElementsByTagName("krpano", "")[0];


                    #region Google


                    XmlElement elem_Google = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/Google");

                    try
                    {
                        SetElemValue(elem_Google, "heading", (Convert.ToDecimal(elem_Google.GetAttribute("heading")) + heading).ToString());
                    }
                    catch (Exception) { }
                    #endregion

                    MyApp.Components.XML.XmlDocument.WriteAllText(MyApp.Components.KRPano.Scene.GetSceneServerFilePath(_Tour_ID, scene_id), xmldoc.OuterXml);
                }
                return true;
            }
            catch (Exception) { return false; }
        }


        [AjaxPro.AjaxMethod]
        public bool MoveFov(object _Tour_ID, string _Scene_ID, string _fov, string _maxpixelzoom, string _fovmin, string _fovmax, string _hlookat, string _vlookat, string _vlookatmin, string _vlookatmax, string _hlookatmin, string _hlookatmax)
        {
            decimal fov = 0;
            decimal maxpixelzoom = 0;

            decimal fovmin = 0;
            decimal fovmax = 0;
            decimal hlookat = 0;
            decimal vlookat = 0;
            decimal vlookatmin = 0;
            decimal vlookatmax = 0;
            decimal hlookatmin = 0;
            decimal hlookatmax = 0;

            try
            {
                fov = Convert.ToDecimal(_fov);
            }
            catch
            {
                fov = 90;
            }
            try
            {
                maxpixelzoom = Convert.ToDecimal(_maxpixelzoom);
            }
            catch
            {
                maxpixelzoom = 90;
            }

            try
            {
                fovmin = Convert.ToDecimal(_fovmin); ;
            }
            catch
            {
                fovmin = 0;
            }
            try
            {
                fovmax = Convert.ToDecimal(_fovmax);
            }
            catch
            {
                fovmax = 0;
            }


            try
            {
                hlookat = Convert.ToDecimal(_hlookat);
            }
            catch
            {
                hlookat = 0;
            }
            try
            {
                vlookat = Convert.ToDecimal(_vlookat);
            }
            catch
            {
                vlookat = 0;
            }

            try
            {
                vlookatmin = Convert.ToDecimal(_vlookatmin);
            }
            catch
            {
                vlookatmin = 0;
            }
            try
            {
                vlookatmax = Convert.ToDecimal(_vlookatmax);
            }
            catch
            {
                vlookatmax = 0;
            }
            try
            {
                hlookatmin = Convert.ToDecimal(_hlookatmin);
            }
            catch
            {
                hlookatmin = 0;
            }
            try
            {
                hlookatmax = Convert.ToDecimal(_hlookatmax);
            }
            catch
            {
                hlookatmax = 0;
            }
            var list_dt = _Scene_ID.Split(',');
            try
            {
                foreach (string scene_id in list_dt)
                {
                    XmlDocument xmldoc = MyApp.Components.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, scene_id);
                    XmlElement elem_krpano = (XmlElement)xmldoc.GetElementsByTagName("krpano", "")[0];


                    #region View


                    XmlElement elem_view = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/view");

                    try
                    {
                        if (fov > 0)
                        {
                            SetElemValue(elem_view, "fov", fov.ToString());
                        }

                        if (_maxpixelzoom.Trim() != "")
                        {
                            SetElemValue(elem_view, "maxpixelzoom", maxpixelzoom.ToString());
                        }
                        if (_fovmin.Trim() != "")
                        {
                            SetElemValue(elem_view, "fovmin", fovmin.ToString());
                        }
                        if (_fovmax.Trim() != "")
                        {
                            SetElemValue(elem_view, "fovmax", fovmax.ToString());
                        }
                        if (_hlookat.Trim() != "")
                            SetElemValue(elem_view, "hlookat", hlookat.ToString());
                        if (_vlookat.Trim() != "")
                            SetElemValue(elem_view, "vlookat", vlookat.ToString());
                        if (_hlookatmin.Trim() != "")
                            SetElemValue(elem_view, "hlookatmin", hlookatmin.ToString());
                        if (_hlookatmax.Trim() != "")
                            SetElemValue(elem_view, "hlookatmax", hlookatmax.ToString());
                        if (_vlookatmin.Trim() != "")
                            SetElemValue(elem_view, "vlookatmin", vlookatmin.ToString());
                        if (_vlookatmax.Trim() != "")
                            SetElemValue(elem_view, "vlookatmax", vlookatmax.ToString());

                    }
                    catch (Exception) { }
                    #endregion

                    MyApp.Components.XML.XmlDocument.WriteAllText(MyApp.Components.KRPano.Scene.GetSceneServerFilePath(_Tour_ID, scene_id), xmldoc.OuterXml);
                }
                return true;
            }
            catch (Exception) { return false; }
        }

        [AjaxPro.AjaxMethod]
        public string ChangeValue(object _Tour_ID, string _Scene_ID, string _Path, string _Field, object _Value)
        {
            if ((_Path == "krpano") && (_Field == "Name"))//针对场景名称处理
            {
                _ChangeValue(_Tour_ID, _Scene_ID, "/krpano/SSet", "Scene_Name", _Value);
                return _ChangeValue(_Tour_ID, _Scene_ID, _Path, _Field, _Value);
            }
            else
            {
                return _ChangeValue(_Tour_ID, _Scene_ID, _Path, _Field, _Value);
            }
        }
        public string _ChangeValue(object _Tour_ID, string _Scene_ID, string _Path, string _Field, object _Value)
        {
            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc = MyApp.Components.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, _Scene_ID);

                #region KRPano
                XmlElement elem = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, _Path);
                SetElemValue(elem, _Field, _Value.ToString());
                #endregion

                MyApp.Components.XML.XmlDocument.WriteAllText(MyApp.Components.KRPano.Scene.GetSceneServerFilePath(_Tour_ID, _Scene_ID), xmldoc.OuterXml);
            }
            catch (Exception ex) { return ex.ToString(); }
            return "true";
        }

        public string GetDateYMD(string _time)
        {
            string _stime = "";

            string[] strs = _time.Split('/');
            if (strs.Length > 1)
            {
                try
                {
                    for (int i = strs.Length - 1; i >= 0; i--)
                    {
                        //_stime +=strs[i] + "-";
                        _stime += Convert.ToInt32(strs[i]).ToString("00") + "-";
                    }
                    _stime = _stime.TrimEnd('-');
                }
                catch
                {
                    _stime = DateTime.Now.ToString("yyyy-MM-dd");
                }
            }
            else if (_time.Split('-').Length > 1)
            {
                _stime = _time;
            }
            else
            {
                _stime = DateTime.Now.ToString("yyyy-MM-dd");
            }

            return _stime;
        }

    }
}