public virtual void UpdateWebApplication(WebApplication webApplication)
 {
     webApplicationDao.Update(webApplication);
 }
 public virtual void InsertWebApplication(WebApplication webApplication)
 {
     webApplicationDao.Insert(webApplication);
 }
        private void _SMC_PackageExtInternalRelease(SMC_PackageExt ext)
        {
            if (ext == null)
                return;

            string tableName = ext.TableName.ToLower();
            int tableId = ext.TableID;
            List<KeyValuePair<string, object>> pars = new List<KeyValuePair<string, object>>();
            switch (tableName)
            {
                case "webapplication":
                    pars.Add(new KeyValuePair<string, object>("id", tableId));
                    WebApplication webApplication = daoWebApplication.Get(pars);
                    if (webApplication == null)
                    {
                        webApplication = new WebApplication();
                        CopyPackageExt2WebApplication(ext, webApplication);
                        daoWebApplication.Insert(webApplication);
                        ext.TableID = webApplication.ID;
                    }
                    else
                    {
                        CopyPackageExt2WebApplication(ext, webApplication);
                        daoWebApplication.Update(webApplication);
                    }
                    break;
                case "package4ai":
                    pars.Add(new KeyValuePair<string, object>("id", tableId));
                    Package4AI package4AI = daoPackage4AI.Get(pars);
                    if (package4AI == null)
                    {
                        package4AI = new Package4AI();
                        CopyPackageExt2Package4AI(ext, package4AI);
                        daoPackage4AI.Insert(package4AI);
                        ext.TableID = package4AI.ID;
                    }
                    else
                    {
                        CopyPackageExt2Package4AI(ext, package4AI);
                        daoPackage4AI.Update(package4AI);
                    }

                    try
                    {
                        _AddApp4AI(package4AI, ext);
                    }
                    catch (Exception ex)
                    {
                        Log4NetHelper.Error(ex);
                    }

                    try
                    {
                        _AddAction4Android(package4AI, ext);
                    }
                    catch (Exception ex)
                    {
                        Log4NetHelper.Error(ex);
                    }

                    break;
                case "smc_package4out":
                    pars.Add(new KeyValuePair<string, object>("po_ID", tableId));
                    SMC_Package4Out package4Out = daoSMC_Package4Out.Get(pars);
                    if (package4Out == null)
                    {
                        package4Out = new SMC_Package4Out();
                        CopyPackageExt2SMC_Package4Out(ext, package4Out);
                        daoSMC_Package4Out.Insert(package4Out);
                        ext.TableID = package4Out.po_ID;
                    }
                    else
                    {
                        CopyPackageExt2SMC_Package4Out(ext, package4Out);
                        daoSMC_Package4Out.Update(package4Out);
                    }
                    break;
            }

            daoSMC_PackageExt.Update(ext);
            _CopyExtFileToUpdateFilesFolder(ext);
        }
 protected WebApplication CopyPackageExt2WebApplication(SMC_PackageExt ext, WebApplication webApplication)
 {
     //webApplication.AppID = ext.pe_ApplicationCode;
     webApplication.ClientType = ext.pe_ClientType;
     webApplication.CreateTime = ext.pe_CreatedTime;
     webApplication.CreateUid = ext.pe_CreateUid;
     webApplication.ShortName = ext.pe_Name;
     webApplication.Unit = ext.pe_UnitCode;
     webApplication.UpdateTime = ext.pe_UpdateTime;
     webApplication.UpdateUid = ext.pe_UpdateUid;
     //webApplication.Uri = ext.
     return webApplication;
 }
        public JsonResult EditWebApplication(WebApplication webApplication, string pe_IsTJ, string pe_IsBB, string id)
        {
            JsonReturnMessages data = new JsonReturnMessages() { IsSuccess = true, Msg = "操作成功" };
            webApplication.UpdateTime = DateTime.Now;
            webApplication.UpdateUid = CurrentUser.UserUId;
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(webApplication.ID)) || webApplication.ID == 0)
                {//新增
                    webApplication.CreateTime = DateTime.Now;
                    webApplication.CreateUid = CurrentUser.UserUId;
                    BoFactory.GetVersionTrackBo.InsertWebApplication(webApplication);

                    //插入packageExt
                    SMC_PackageExt pe = new SMC_PackageExt();
                    pe.pe_id = BoFactory.GetVersionTrackBo.GetMaxPackageExtId() + 1;
                    pe.pe_IsTJ = pe_IsTJ;
                    pe.pe_IsBB = pe_IsBB;
                    pe.pe_PictureUrl = webApplication.IconUri;
                    pe.pe_ClientType = webApplication.ClientType;
                    pe.pe_DownloadUri = webApplication.Uri;
                    pe.TableName = "WebApplication";
                    pe.TableID = webApplication.ID;
                    pe.pe_UnitCode = webApplication.Unit;
                    pe.pe_ApplicationCode = Request.Form["ApplicationID"];

                    if (!String.IsNullOrEmpty(pe.pe_ApplicationCode))
                    {
                        string[] appIds = pe.pe_ApplicationCode.Split(",".ToCharArray());
                        string appNames = "";
                        foreach (string appid in appIds)
                        {
                            Application application = Bo.BoFactory.GetVersionTrackBo.GetApplication(appid);
                            if (application != null)
                            {
                                appNames += application.DisplayName + ",";
                            }
                        }
                        pe.pe_ApplicationName = appNames;
                    }

                    pe.pe_UnitName = BoFactory.GetSMC_UnitBo.Get(pe.pe_UnitCode).Unit_Name;
                    pe.pe_CreatedTime = webApplication.CreateTime;
                    pe.pe_CreateUid = webApplication.CreateUid;
                    pe.pe_UpdateTime = webApplication.UpdateTime;
                    pe.pe_LastVersion = "";
                    pe.pe_Version = "";
                    pe.pe_BuildVer = "";
                    pe.pe_Type = "web";
                    pe.pe_CategoryID = webApplication.AppID.ToString();
                    pe.pe_ClientType = webApplication.ClientType;
                    pe.pe_Category = BoFactory.GetVersionTrackBo.GetApplicationCategory(webApplication.AppID.ToString()).DisplayName;
                    pe.pe_DisplayName = webApplication.ShortName;
                    pe.pe_Description = webApplication.ShortName;
                    pe.pe_Name = webApplication.ShortName;
                    pe.pe_Firmware = "";
                    GlobalParam parm = Bo.BoFactory.GetGlobalParamBO.GetGlobalParam("app_sj_need_auth");
                    if (parm.ConfigValue == "1")
                    {
                        //需要审核
                        pe.pe_AuthStatus = 0;//待审核
                        pe.pe_AuthSubmitTime = DateTime.Now;
                        pe.pe_AuthSubmitName = CurrentUser.FullName;
                        pe.pe_AuthSubmitUID = CurrentUser.UserUId;
                        pe.pe_Direction = "发布";
                        pe.pe_UsefulStstus = "0";
                        pe.pe_UsefulTime = DateTime.Now;
                        pe.pe_UsefulOperatorUID = CurrentUser.UserUId;
                        pe.pe_UsefulOperatorName = CurrentUser.FullName;
                    }
                    else
                    {
                        pe.pe_AuthStatus = 1;//审核通过
                        pe.pe_AuthSubmitTime = DateTime.Now;
                        pe.pe_AuthTime = DateTime.Now;
                        pe.pe_AuthSubmitName = CurrentUser.FullName;
                        pe.pe_AuthSubmitUID = CurrentUser.UserUId;
                        pe.pe_AuthManUID = CurrentUser.UserUId;
                        pe.pe_AuthMan = CurrentUser.FullName;
                        pe.pe_SyncStatus = 0;
                        pe.pe_Direction = "发布";
                        pe.pe_UsefulStstus = "1";
                        pe.pe_UsefulTime = DateTime.Now;
                        pe.pe_UsefulOperatorUID = CurrentUser.UserUId;
                        pe.pe_UsefulOperatorName = CurrentUser.FullName;
                    }

                    string pe_2dPictureUrl = Save2DPicture(pe.pe_id, pe.pe_DownloadUri);
                    pe.pe_2dPictureUrl = pe_2dPictureUrl;

                    int i = Request.Files.Count;
                    if (i > 0)
                    {
                        HttpPostedFileBase icon = null;
                        int packageId = pe.pe_id;
                        string conSolePath = HttpRuntime.AppDomainAppPath;//服务器路径
                        string pDir = SAVEOUTPATH + @"\" + packageId.ToString();//相对路径 用安装包ID做文件夹名
                        string saveDir = conSolePath + pDir;
                        //图标文件
                        icon = Request.Files[0];
                        string iconFileName = "AppIcon.png";
                        string savePath = System.IO.Path.Combine(saveDir, iconFileName);
                        if (!System.IO.Directory.Exists(saveDir))
                        {
                            System.IO.Directory.CreateDirectory(saveDir);
                        }
                        if (System.IO.File.Exists(savePath))
                        {
                            System.IO.File.Delete(savePath);
                        }
                        icon.SaveAs(savePath);

                        pe.pe_PictureUrl = @"~/" + pDir + "/AppIcon.png";
                        pe.pe_PictureUrl = pe.pe_PictureUrl.Replace(@"\\", "/");
                    }
                    BoFactory.GetVersionTrackBo.InsertPackageExt(pe);

                    if (parm.ConfigValue == "0")
                    {
                        //不需要审核,直接同步到应用中心
                        //同步至外网数据
                        _SyncPackageExt(pe);
                    }

                }
                else
                {  //修改
                    BoFactory.GetVersionTrackBo.UpdateWebApplication(webApplication);
                    string pe_id = BoFactory.GetVersionTrackBo.GetPeId(webApplication.ID.ToString(), "WebApplication");
                    SMC_PackageExt pe = BoFactory.GetVersionTrackBo.GetPackageExt(pe_id);
                    pe.pe_IsBB = pe_IsBB;
                    pe.pe_IsTJ = pe_IsTJ;
                    pe.pe_UpdateTime = DateTime.Now;
                    pe.pe_UpdateUid = CurrentUser.UserUId;
                    pe.pe_CategoryID = webApplication.AppID.ToString();
                    pe.pe_ClientType = webApplication.ClientType;
                    pe.pe_Category = BoFactory.GetVersionTrackBo.GetApplicationCategory(webApplication.AppID.ToString()).DisplayName;
                    pe.pe_DisplayName = webApplication.ShortName;
                    pe.pe_Description = webApplication.ShortName;
                    pe.pe_Name = webApplication.ShortName;
                    pe.pe_UnitCode = webApplication.Unit;
                    pe.pe_UnitName = BoFactory.GetSMC_UnitBo.Get(pe.pe_UnitCode).Unit_Name;

                    int i = Request.Files.Count;
                    pe.pe_ApplicationCode = Request.Form["ApplicationID"];
                    if (!String.IsNullOrEmpty(pe.pe_ApplicationCode))
                    {
                        string[] appIds = pe.pe_ApplicationCode.Split(",".ToCharArray());
                        string appNames = "";
                        foreach (string appid in appIds)
                        {
                            Application application = Bo.BoFactory.GetVersionTrackBo.GetApplication(appid);
                            if (application != null)
                            {
                                appNames += application.DisplayName + ",";
                            }
                        }
                        pe.pe_ApplicationName = appNames;
                    }

                    GlobalParam parm = Bo.BoFactory.GetGlobalParamBO.GetGlobalParam("app_sj_need_auth");
                    if (parm.ConfigValue == "1")
                    {
                        //需要审核
                        pe.pe_AuthStatus = 0;//待审核
                        pe.pe_AuthSubmitTime = DateTime.Now;
                        pe.pe_AuthSubmitName = CurrentUser.FullName;
                        pe.pe_AuthSubmitUID = CurrentUser.UserUId;
                        pe.pe_Direction = "发布";
                        pe.pe_Type = "web";
                        pe.pe_UsefulStstus = "0";
                        pe.pe_UsefulTime = DateTime.Now;
                        pe.pe_UsefulOperatorUID = CurrentUser.UserUId;
                        pe.pe_UsefulOperatorName = CurrentUser.FullName;
                    }
                    else
                    {
                        pe.pe_AuthStatus = 1;//审核通过
                        pe.pe_AuthSubmitTime = DateTime.Now;
                        pe.pe_AuthTime = DateTime.Now;
                        pe.pe_AuthSubmitName = CurrentUser.FullName;
                        pe.pe_AuthSubmitUID = CurrentUser.UserUId;
                        pe.pe_AuthManUID = CurrentUser.UserUId;
                        pe.pe_AuthMan = CurrentUser.FullName;
                        pe.pe_SyncStatus = 0;
                        pe.pe_Direction = "发布";
                        pe.pe_Type = "web";
                        pe.pe_UsefulStstus = "1";
                        pe.pe_UsefulTime = DateTime.Now;
                        pe.pe_UsefulOperatorUID = CurrentUser.UserUId;
                        pe.pe_UsefulOperatorName = CurrentUser.FullName;
                    }

                    string pe_2dPictureUrl = Save2DPicture(pe.pe_id, pe.pe_DownloadUri);
                    pe.pe_2dPictureUrl = pe_2dPictureUrl;

                    if (i > 0)
                    {
                        HttpPostedFileBase icon = null;
                        int packageId = pe.pe_id;
                        string conSolePath = HttpRuntime.AppDomainAppPath;//服务器路径
                        string pDir = SAVEOUTPATH + @"\" + packageId.ToString();//相对路径 用安装包ID做文件夹名
                        string saveDir = conSolePath + pDir;
                        //图标文件
                        icon = Request.Files[0];
                        string iconFileName = "AppIcon.png";
                        string savePath = System.IO.Path.Combine(saveDir, iconFileName);
                        if (!System.IO.Directory.Exists(saveDir))
                        {
                            System.IO.Directory.CreateDirectory(saveDir);
                        }
                        if (System.IO.File.Exists(savePath))
                        {
                            System.IO.File.Delete(savePath);
                        }
                        icon.SaveAs(savePath);

                        pe.pe_PictureUrl = @"~/" + pDir + "/AppIcon.png";
                        pe.pe_PictureUrl = pe.pe_PictureUrl.Replace(@"\\", "/");
                    }
                    pe.pe_ClientType = webApplication.ClientType;
                    BoFactory.GetVersionTrackBo.UpdatePackageExt(pe);

                    if (parm.ConfigValue == "0")
                    {
                        //不需要审核,直接同步到应用中心
                        //同步至外网数据
                        _SyncPackageExt(pe);
                    }
                }
            }
            catch (Exception ex)
            {
                Log4NetHelper.Error(ex);
                data.IsSuccess = false;
                data.Msg = ex.Message;
            }
            return Json(data, "text/html");
        }
        public ActionResult EditWebApplication(string id)
        {
            id = Request.QueryString["id"];
            List<SelectListItem> unitList = new List<SelectListItem>();
            //获取当前用户的本单位
            IList<SmartBox.Console.Common.Entities.SMC_Unit> js = GetUnitData();

            foreach (SmartBox.Console.Common.Entities.SMC_Unit r in js)
            {
                //unitList.Add(new SelectListItem { Text = "全局", Value = "" });
                unitList.Add(new SelectListItem { Text = r.Unit_Name, Value = r.Unit_ID });
            }
            ViewData["Application"] = BoFactory.GetVersionTrackBo.QueryApplicationList().ToDataTable();
            //Dictionary<string, string> unitInfo = BoFactory.GetSMC_UserListBo.GetUnitByUL_UID(CurrentUser.UserUId);
            //if (unitInfo.Count > 0)
            //{
            //    string unitName = "本单位-" + unitInfo.ElementAt(0).Key;
            //    string unitId = unitInfo.ElementAt(0).Value;
            //    unitList.Add(new SelectListItem { Text = unitName, Value = unitId, Selected = true });
            //}
            //if (BoFactory.GetVersionTrackBo.IsSystemManager(CurrentUser.UserUId))
            //{
            //    //加入所有单位列表
            //    PageView view = new PageView();
            //    view.PageSize = 15;
            //    JsonFlexiGridData units = BoFactory.GetSMC_UnitBo.QueryUnitByUpperUnitCode(view, "");
            //    foreach (FlexiGridRow r in units.rows)
            //    {
            //        //unitList.Add(new SelectListItem { Text = "全局", Value = "" });
            //        unitList.Add(new SelectListItem { Text = r.cell[1], Value = r.id });
            //    }
            //}
            List<SelectListItem> IsRecom = new List<SelectListItem>();
            IsRecom.Add(new SelectListItem { Text = "推荐", Value = "1", Selected = true });
            IsRecom.Add(new SelectListItem { Text = "不推荐", Value = "0" });

            List<SelectListItem> IsMust = new List<SelectListItem>();
            IsMust.Add(new SelectListItem { Text = "必备", Value = "1", Selected = true });
            IsMust.Add(new SelectListItem { Text = "不必备", Value = "0" });

            WebApplication webApplication;
            SMC_PackageExt entity = null;
            if (string.IsNullOrEmpty(id))
            {
                webApplication = new WebApplication();
                webApplication.Seq = 1;
            }
            else
            {
                webApplication = BoFactory.GetVersionTrackBo.GetWebApplication(id);
                entity = BoFactory.GetAppCenterBO.GetPackage("webapplication", id);
                string unit = "";
                if (webApplication != null)
                {
                    unit = webApplication.Unit;
                    if (entity.pe_IsTJ == "False")
                    {
                        IsRecom[1].Selected = true;
                    }
                    else
                    {
                        IsRecom[0].Selected = true;
                    }
                    if (entity.pe_IsBB == "False")
                    {
                        IsMust[1].Selected = true;
                    }
                    else
                    {
                        IsMust[0].Selected = true;
                    }

                }
                else
                {
                    if (entity != null && !String.IsNullOrEmpty(entity.pe_UnitCode))
                        unit = entity.pe_UnitCode;
                }

                foreach (SelectListItem item in unitList)
                {
                    if (item.Value == unit)
                    {
                        item.Selected = true;
                        break;
                    }
                }
            }

            ViewData["pe_IsTJ"] = IsRecom;
            ViewData["pe_IsBB"] = IsMust;

            if (entity != null && !String.IsNullOrEmpty(entity.pe_PictureUrl))
            {
                ViewData["IconUrl"] = entity.pe_PictureUrl;
            }
            else
            {
                ViewData["IconUrl"] = "";
            }
            ViewData["entity"] = entity;
            if (webApplication != null && string.IsNullOrEmpty(webApplication.ClientType))
            {
                webApplication.ClientType = string.Empty;
            }
            SelectHelper ddlApplicationSelect = new SelectHelper(BoFactory.GetVersionTrackBo.QueryApplicationCategoryList().ToDataTable());
            SelectHelper chkClientTypeSelect = new SelectHelper(BoFactory.GetVersionTrackBo.QueryClientTypeList().ToDataTable());
            int appId = 0;
            if (webApplication != null)
                appId = webApplication.AppID;
            else
            {
                if (entity != null)
                    appId = Convert.ToInt32(entity.pe_CategoryID);
            }
            ViewData["AppID"] = ddlApplicationSelect.GetSelectList("DisplayName", "ID", appId, false);
            if (webApplication == null)
            {
                List<string> vals = new List<string>();

                if (entity != null && !String.IsNullOrEmpty(entity.pe_ClientType))
                    vals.Add(entity.pe_ClientType);

                ViewData["ClientType"] = chkClientTypeSelect.GetSelectListItem("DisplayName", "ClientType", vals, false);
            }
            else
            {
                ViewData["ClientType"] = chkClientTypeSelect.GetSelectListItem("DisplayName", "ClientType", webApplication.ClientType.Split('|').ToList(), false);
            }
            ViewData["Unit"] = unitList;
            return View(webApplication);
        }