public void InstallPackageCore(ModuleInfo module, XmlDocument doc, ref  ArrayList dllFiles, ref  string _unistallScriptFile)
        {
            #region "Module Creation Logic"

            // add into module table
            int[] outputValue;
            ModuleController objProvider = new ModuleController();
            outputValue = objProvider.AddModules(module, false, 0, true, DateTime.Now, GetPortalID, GetUsername);
            module.ModuleID = outputValue[0];
            module.ModuleDefID = outputValue[1];
            _newModuleID = module.ModuleID;
            _newModuleDefID = module.ModuleDefID;


            //insert into ProtalModule table
            _newPortalmoduleID = objProvider.AddPortalModules(GetPortalID, _newModuleID, true, DateTime.Now, GetUsername);

            //install permission for the installed module in ModuleDefPermission table with ModuleDefID and PermissionID
            try
            {
                // get the default module VIEW permissions
                int _permissionIDView = objProvider.GetPermissionByCodeAndKey("SYSTEM_VIEW", "VIEW");

                //insert into module permissions i.e., ModuleDefPermission and PortalModulePermission
                objProvider.AddModulePermission(_newModuleDefID, _permissionIDView, GetPortalID, _newPortalmoduleID, true, GetUsername, true, DateTime.Now, GetUsername);

                // get the default module EDIT permissions
                int _permissionIDEdit = objProvider.GetPermissionByCodeAndKey("SYSTEM_EDIT", "EDIT");

                //insert into module permissions i.e., ModuleDefPermission and PortalModulePermission
                objProvider.AddModulePermission(_newModuleDefID, _permissionIDEdit, GetPortalID, _newPortalmoduleID, true, GetUsername, true, DateTime.Now, GetUsername);
            }
            catch (Exception ex)
            {
                Exceptions += ex.Message;
                return;
            }

            XmlNodeList xnList2 = doc.SelectNodes("sageframe/folders/folder/modules/module/controls/control");
            foreach (XmlNode xn2 in xnList2)
            {
                string _moduleControlKey = null;
                if (xn2["key"] != null)
                {
                    _moduleControlKey = xn2["key"].InnerXml;// exists
                }
                string _moduleControlTitle = xn2["title"].InnerXml;
                string _moduleControlSrc = xn2["src"].InnerXml;
                string _controlType = xn2["type"].InnerXml;
                string _moduleControlHelpUrl = xn2["helpurl"].InnerXml;
                bool _moduleSupportsPartialRendering = false;
                if (xn2["supportspartialrendering"] != null)
                {
                    string _moduleControlSupportsPartialRendering = xn2["supportspartialrendering"].InnerXml;

                    if (_moduleControlSupportsPartialRendering == "true")
                    {
                        _moduleSupportsPartialRendering = true;
                    }
                }
                int controlType = 0;
                controlType = checkControlType(_controlType);
                string IconFile = "";

                //add into module control table
                objProvider.AddModuleCoontrols(_newModuleDefID, _moduleControlKey, _moduleControlTitle, _moduleControlSrc,
                                           IconFile, controlType, 0, _moduleControlHelpUrl, _moduleSupportsPartialRendering, true, DateTime.Now,
                                           GetPortalID, GetUsername);
            }
            XmlNodeList xnList3 = doc.SelectNodes("sageframe/folders/folder/files/file");
            if (xnList3.Count != 0)
            {
                #region CheckValidDataSqlProvider
                string moduleFile = GetSqlDataProviderFile(module.TempFolderPath);
                if (moduleFile.Trim().Length < 2)
                    moduleFile = module.Version;

               
                #endregion

                bool orderSpecified = (from XmlNode xn3 in xnList3 select xn3.Attributes["order"]).Select(order => order != null).FirstOrDefault();

                if (orderSpecified)
                {

                    var sortedItems = xnList3.OfType<XmlElement>()
                        .OrderBy(item => int.Parse(item.GetAttribute("order")));

                    foreach (var item in sortedItems)
                    {
                        string _fileName = item["name"].InnerXml;

                        try
                        {
                            #region ReadSqlProviderfile

                            if (!String.IsNullOrEmpty(moduleFile) && !_fileName.Contains("Uninstall.SqlDataProvider") && _fileName.Contains(".SqlDataProvider"))
                            {
                                Exceptions = ReadSQLFile(module.TempFolderPath, _fileName);
                            }

                            #endregion

                            #region CheckAlldllFiles

                            if (!String.IsNullOrEmpty(_fileName) && _fileName.Contains(".dll"))
                            {
                                dllFiles.Add(_fileName);
                            }

                            #endregion

                            #region ReadUninstall SQL FileName

                            if (!String.IsNullOrEmpty(_fileName) && _fileName.Contains("Uninstall.SqlDataProvider"))
                            {
                                _unistallScriptFile = _fileName;
                            }

                            #endregion
                        }
                        catch (Exception ex)
                        {
                            Exceptions += ex.Message;
                            break;
                        }
                    }

                }
                else
                {


                    foreach (XmlNode xn3 in xnList3)
                    {


                        string _fileName = xn3["name"].InnerXml;



                        try
                        {
                            #region ReadSqlProviderfile

                            if (!String.IsNullOrEmpty(moduleFile) && !_fileName.Contains("Uninstall.SqlDataProvider") && _fileName.Contains(".SqlDataProvider"))
                            {
                                Exceptions = ReadSQLFile(module.TempFolderPath, moduleFile + ".SqlDataProvider");
                            }

                            #endregion

                            #region CheckAlldllFiles

                            if (!String.IsNullOrEmpty(_fileName) && _fileName.Contains(".dll"))
                            {
                                dllFiles.Add(_fileName);
                            }

                            #endregion

                            #region ReadUninstall SQL FileName

                            if (!String.IsNullOrEmpty(_fileName) && _fileName.Contains("Uninstall.SqlDataProvider"))
                            {
                                _unistallScriptFile = _fileName;
                            }

                            #endregion
                        }
                        catch (Exception ex)
                        {
                            Exceptions += ex.Message;
                            break;
                        }
                    }
                }
            }
            XmlNodeList xnList4 = doc.SelectNodes("sageframe/folders/folder/templates/template");
             if (xnList4 != null && xnList4.Count != 0)
             {
                  foreach (XmlNode xn4 in xnList4)
                  {
                       string _templateName = xn4["name"].InnerXml;
                      #region Read Template file
                       if (!String.IsNullOrEmpty(_templateName))
                      {
                          string templateName = _templateName;
                          AddTemplateZip(templateName, module.TempFolderPath);
                      }
                      #endregion
                  }

             }
             XmlNodeList directrylist = doc.SelectNodes("sageframe/folders/folder/move/directories/directory");

             if (directrylist != null && directrylist.Count != 0)
             {
                 foreach (XmlNode directory in directrylist)
                 {
                   
                     if (directory["from"] != null && directory["to"]!=null)
                     {
                         string fromdirectory = module.TempFolderPath + "\\" + directory["from"].InnerXml;
                         string todirectory = HttpContext.Current.Server.MapPath(@"~/" + directory["to"].InnerXml);
                         MoveDirectory(fromdirectory, todirectory);

                     }
                    
                 }
             }

             XmlNodeList fileList = doc.SelectNodes("sageframe/folders/folder/move/files/file");

             if (fileList != null && fileList.Count != 0)
             {
                 foreach (XmlNode file in fileList)
                 {

                     if (file["to"] != null && file["name"]!=null)
                     {
                         string fileName = file["name"] != null ? file["name"].InnerXml : "";
                         string fromLocation = module.TempFolderPath + "\\" + file["from"].InnerXml;
                         string toLocation = HttpContext.Current.Server.MapPath(@"~/" + file["to"].InnerXml);
                         MoveFile(fileName, fromLocation, toLocation);
                     }

                 }
             }

            if (Exceptions != string.Empty)
            {
                if (module.ModuleID.ToString() != null && module.ModuleID > 0 && _newModuleDefID != null && _newModuleDefID > 0)
                {
                    //Run unstallScript
                    if (_unistallScriptFile != "")
                    {
                        Exceptions = ReadSQLFile(module.TempFolderPath, _unistallScriptFile);
                    }
                    //Delete Module info from data base
                    ModulesRollBack(module.ModuleID, GetPortalID);
                    module.ModuleID = -1;
                }
            }
            #endregion

        }
        private string ImportControl(string controlSrc)
        {
            string ExtensionMessage = string.Empty;
            if (!string.IsNullOrEmpty(controlSrc))
            {
                DropDownList ddlFirst = ((DropDownList)PackageDetails1.FindControl("ddlFirst"));
                DropDownList ddlSecond = ((DropDownList)PackageDetails1.FindControl("ddlSecond"));
                DropDownList ddlLast = ((DropDownList)PackageDetails1.FindControl("ddlLast"));
                DropDownList ddlIcon = ((DropDownList)ModuleControlsDetails1.FindControl("ddlIcon"));

                TextBox txtKey = ((TextBox)ModuleControlsDetails1.FindControl("txtKey"));
                TextBox txtTitle = ((TextBox)ModuleControlsDetails1.FindControl("txtTitle"));
                TextBox txtHelpURL = ((TextBox)ModuleControlsDetails1.FindControl("txtHelpURL"));
                TextBox txtDisplayOrder = ((TextBox)ModuleControlsDetails1.FindControl("txtDisplayOrder"));
                //CheckBox chkSupportsPartialRendering = ((CheckBox)ModuleControlsDetails1.FindControl("chkSupportsPartialRendering"));
                DropDownList ddlType = ((DropDownList)ModuleControlsDetails1.FindControl("ddlType"));

                ModuleInfo objModule = new ModuleInfo();
                Installers install = new Installers();
                try
                {
                    string folder = RemoveTrailingSlash(GetSourceFolder());
                    string friendlyName = PackageDetails1.PackageName;
                    string name = GetClassName();
                    string moduleControl = "Modules/" + folder + "/" + controlSrc;

                    //add module and package tables
                    objModule.ModuleName = name;
                    objModule.Name = name;
                    objModule.FriendlyName = friendlyName;
                    objModule.Description = PackageDetails1.Description;
                    objModule.FolderName = folder;
                    objModule.Version = ddlFirst.SelectedValue + "." + ddlSecond.SelectedValue + "." + ddlLast.SelectedValue;//"01.00.00"; //new Version(1, 0, 0);
                    objModule.Owner = PackageDetails1.Owner;
                    objModule.Organization = PackageDetails1.Organization;
                    objModule.URL = PackageDetails1.Url;
                    objModule.Email = PackageDetails1.Email;
                    objModule.ReleaseNotes = PackageDetails1.ReleaseNotes;
                    objModule.License = PackageDetails1.License;
                    objModule.PackageType = "Module";
                    objModule.isPremium = true;
                    objModule.supportedFeatures = 0;
                    objModule.BusinessControllerClass = "";
                    objModule.CompatibleVersions = "";
                    objModule.dependencies = "";
                    objModule.permissions = "";
                    ModuleController objController = new ModuleController();
                    try
                    {
                        int[] outputValue;
                        outputValue = objController.AddModules(objModule, false, 0, true, DateTime.Now, GetPortalID, GetUsername);
                        objModule.ModuleID = outputValue[0];
                        objModule.ModuleDefID = outputValue[1];
                        _newModuleID = objModule.ModuleID;
                        _newModuleDefID = objModule.ModuleDefID;
                    }
                    catch (Exception ex)
                    {
                        ProcessException(ex);
                    }

                    try
                    {
                        //insert into ProtalModule table
                        _newPortalmoduleID = objController.AddPortalModules(GetPortalID, _newModuleID, true, DateTime.Now, GetUsername);
                    }
                    catch (Exception ex)
                    {
                        ProcessException(ex);
                    }
                    //install permission for the installed module in ModuleDefPermission table with ModuleDefID and PermissionID
                    try
                    {
                        // get the default module VIEW permissions
                        int _permissionIDView = objController.GetPermissionByCodeAndKey("SYSTEM_VIEW", "VIEW");
                        objController.AddModulePermission(_newModuleDefID, _permissionIDView, GetPortalID, _newPortalmoduleID, true, GetUsername, true, DateTime.Now, GetUsername);
                        int _permissionIDEdit = objController.GetPermissionByCodeAndKey("SYSTEM_EDIT", "EDIT");
                        objController.AddModulePermission(_newModuleDefID, _permissionIDEdit, GetPortalID, _newPortalmoduleID, true, GetUsername, true, DateTime.Now, GetUsername);
                    }
                    catch (Exception ex)
                    {
                        Exceptions += ex.Message;
                    }

                    try
                    {
                        //Logic for modulecontrol installation
                        string _moduleControlKey = txtKey.Text;
                        string _moduleControlTitle = txtTitle.Text;
                        string _moduleControlSrc = moduleControl;
                        string _moduleControlHelpUrl = txtHelpURL.Text;
                        //bool _moduleSupportsPartialRendering = chkSupportsPartialRendering.Checked;
                        bool _moduleSupportsPartialRendering = false;
                        int _controlType = int.Parse(ddlType.SelectedItem.Value);
                        string _iconFile = "";
                        if (ddlIcon.SelectedIndex != -1)
                        {
                            _iconFile = ddlIcon.SelectedItem.Value;
                        }
                        int _displayOrder = int.Parse(txtDisplayOrder.Text);

                        _moduleControlID = objController.AddModuleCoontrols(_newModuleDefID, _moduleControlKey, _moduleControlTitle, _moduleControlSrc,
                            _iconFile, _controlType, _displayOrder, _moduleControlHelpUrl, _moduleSupportsPartialRendering, true, DateTime.Now,
                            GetPortalID, GetUsername);
                        ExtensionMessage = GetSageMessage("Extensions", "ModuleExtensionIsAddedSuccessfully");
                    }
                    catch (Exception ex)
                    {
                        Exceptions = ex.Message;
                    }

                    if (Exceptions != string.Empty)
                    {
                        if (objModule.ModuleID > 0 && _newModuleDefID != null && _newModuleDefID > 0)
                        {
                            //Delete Module info from data base
                            install.ModulesRollBack(objModule.ModuleID, GetPortalID);
                        }
                    }
                }
                catch
                {
                    if (objModule.ModuleID > 0 && _newModuleDefID != null && _newModuleDefID > 0)
                    {
                        //Delete Module info from data base
                        install.ModulesRollBack(objModule.ModuleID, GetPortalID);
                    }
                }
            }
            return ExtensionMessage;
        }
        public void CreateSinglePagesModulePackage(ModuleSinglePageInfo pageObj)
        {
            ModuleController moduleCtr = new ModuleController();
            // PaymentGateWayModuleInfo module = new PaymentGateWayModuleInfo();
            ModuleInfo module = new ModuleInfo();
            SQLHandler sqlH = new SQLHandler();
            Int32? newModuleID = 0;
            Int32? newModuleDefID = 0;
            Int32? newPortalmoduleID = 0;

            if (!IsPageExists(pageObj.PageName))
            {
                try
                {
                    #region "Module Creation Logic"

                    // add into module table
                    ModuleInfo moduleObj = new ModuleInfo();
                    moduleObj.ModuleName = "AspxCommerce." + pageObj.FriendlyName;
                    moduleObj.Name = pageObj.FriendlyName;
                    moduleObj.PackageType = "Module";
                    moduleObj.Owner = "AspxCommerce";
                    moduleObj.Organization = "";
                    moduleObj.URL = "";
                    moduleObj.Email = "";
                    moduleObj.ReleaseNotes = "";
                    moduleObj.FriendlyName = pageObj.FriendlyName;
                    moduleObj.Description = pageObj.Description;
                    moduleObj.Version = pageObj.Version;
                    moduleObj.isPremium = true;
                    moduleObj.BusinessControllerClass = "";
                    moduleObj.FolderName = pageObj.FolderName;
                    moduleObj.supportedFeatures = 0;
                    moduleObj.CompatibleVersions = "";
                    moduleObj.dependencies = "";
                    moduleObj.permissions = "";
              

                        int[] outputValue;
                        outputValue = moduleCtr.AddModules(moduleObj, false, 0, true, DateTime.Now, GetPortalID, GetUsername);
                        moduleObj.ModuleID = outputValue[0];
                        moduleObj.ModuleDefID = outputValue[1];
                        newModuleID = moduleObj.ModuleID;
                        newModuleDefID = moduleObj.ModuleDefID;


                        //insert into ProtalModule table

                        newPortalmoduleID = moduleCtr.AddPortalModules(GetPortalID, newModuleID, true, DateTime.Now, GetUsername);
                    #endregion

                        //install permission for the installed module in ModuleDefPermission table with ModuleDefID and PermissionID
                        //int controlType = 0;
                        //controlType = checkControlType(pageObj.ControlType);
                        string IconFile = "";


                        foreach (var item in pageObj.PageControls)
                        {
                            int controlType = 0;
                            controlType = checkControlType(item.ControlType);
                            //add into module control table
                            moduleCtr.AddModuleCoontrols(newModuleDefID, pageObj.PageName + item.ControlType,
                                                               pageObj.PageTitle + item.ControlType, item.ControlSource,
                                                               IconFile, controlType, 0, pageObj.HelpURL,
                                                               pageObj.SupportPartialRendering, true,
                                                               DateTime.Now,
                                                               GetPortalID, GetUsername);
                        }
                   

                    //sp_ModuleDefPermissionAdd
                    string ModuleDefPermissionID;
                    List<KeyValuePair<string, object>> paramDef = new List<KeyValuePair<string, object>>();
                    paramDef.Add(new KeyValuePair<string, object>("@ModuleDefID", newModuleDefID));
                    paramDef.Add(new KeyValuePair<string, object>("@PortalModuleID", newPortalmoduleID));
                    paramDef.Add(new KeyValuePair<string, object>("@PermissionID", 1));
                    paramDef.Add(new KeyValuePair<string, object>("@IsActive", true));
                    paramDef.Add(new KeyValuePair<string, object>("@AddedOn", DateTime.Now));
                    paramDef.Add(new KeyValuePair<string, object>("@PortalID", GetPortalID));
                    paramDef.Add(new KeyValuePair<string, object>("@AddedBy", GetUsername));
                    ModuleDefPermissionID = sqlH.ExecuteNonQueryAsGivenType<string>("[dbo].[sp_ModuleDefPermissionAdd]", paramDef, "@ModuleDefPermissionID");

                    //ModuleDefPermissionID
                    List<KeyValuePair<string, object>> paramPage = new List<KeyValuePair<string, object>>();
                    paramPage.Add(new KeyValuePair<string, object>("@ModuleDefID", newModuleDefID));
                    paramPage.Add(new KeyValuePair<string, object>("@PageName", pageObj.PageName));
                    paramPage.Add(new KeyValuePair<string, object>("@PortalID", GetPortalID));
                    paramPage.Add(new KeyValuePair<string, object>("@ModuleDefPermissionID", int.Parse(ModuleDefPermissionID)));
                    sqlH.ExecuteNonQuery("[dbo].[usp_Aspx_CreatePageModulePackage]", paramPage);

                }
                catch (Exception ex)
                {

                    ProcessException(ex);
                }
            }
        }
        public void InstallPackage(PaymentGateWayModuleInfo module,int update)
        {
            ModuleController moduleCtr = new ModuleController();
            XmlDocument doc = new XmlDocument();
            ArrayList dllFiles = new ArrayList();
            string unistallScriptFile = string.Empty;
            doc.Load(module.TempFolderPath + '\\' + module.ManifestFile);
            XmlElement root = doc.DocumentElement;
            if (!String.IsNullOrEmpty(root.ToString()))
            {
                XmlNodeList xnList = doc.SelectNodes("sageframe/folders/folder");
                foreach (XmlNode xn in xnList)
                {
                    #region Module Exist check
                    try
                    {
                        System.Nullable<Int32> newModuleID = 0;
                        System.Nullable<Int32> newModuleDefID = 0;
                        System.Nullable<Int32> newPortalmoduleID = 0;
                        //System.Nullable<Int32> _newPortalmoduleID = 0;
                        //System.Nullable<Int32> _newModuleDefPermissionID = 0;
                        //System.Nullable<Int32> _newPortalModulePermissionID = 0;
                        #region "Module Creation Logic"
                        SQLHandler sqhl = new SQLHandler();
                        SqlConnection sqlConn = new SqlConnection(SystemSetting.SageFrameConnectionString);
                        SqlCommand sqlCmd = new SqlCommand();
                        int ReturnValue = -1;
                        sqlCmd.Connection = sqlConn;
                        sqlCmd.CommandText = "[dbo].[usp_Aspx_PaymentGatewayTypeAdd]";
                        sqlCmd.CommandType = CommandType.StoredProcedure;
                        sqlCmd.Parameters.Add(new SqlParameter("@PaymentGatewayTypeName", module.PaymentGatewayTypeName));
                        sqlCmd.Parameters.Add(new SqlParameter("@StoreID", module.StoreID));
                        sqlCmd.Parameters.Add(new SqlParameter("@PortalID", module.PortalID));
                        sqlCmd.Parameters.Add(new SqlParameter("@FolderName", module.FolderName));
                        sqlCmd.Parameters.Add(new SqlParameter("@FriendlyName", module.FriendlyName));
                        sqlCmd.Parameters.Add(new SqlParameter("@CultureName", module.CultureName));
                        sqlCmd.Parameters.Add(new SqlParameter("@Description", module.Description));
                        sqlCmd.Parameters.Add(new SqlParameter("@Version", module.Version));
                        sqlCmd.Parameters.Add(new SqlParameter("@AddedBy", GetUsername));
                        sqlCmd.Parameters.Add(new SqlParameter("@Update", update));
                        sqlCmd.Parameters.Add(new SqlParameter("@NewModuleId", SqlDbType.Int));
                        sqlCmd.Parameters["@NewModuleId"].Direction = ParameterDirection.Output;

                        sqlConn.Open();
                        sqlCmd.ExecuteNonQuery();
                        if (update==0)
                        {
                            ReturnValue = (int)sqlCmd.Parameters["@NewModuleId"].Value;
                            module.PaymentGatewayTypeID = ReturnValue;
                        }
                        sqlConn.Close();

                        XmlNodeList xnList5 = doc.SelectNodes("sageframe/folders/folder/modules/module/controls/control");
                        int displayOrder = 0;
                        foreach (XmlNode xn5 in xnList5)
                        {
                            displayOrder++;
                            string ctlKey = xn5["key"].InnerXml.ToString();
                            string ctlSource = xn5["src"].InnerXml.ToString();
                            string ctlTitle = xn5["title"].InnerXml.ToString();
                            string _ctlType = xn5["type"].InnerXml.ToString();
                            int ctlType = checkControlType(_ctlType);
                            string ctlHelpUrl = xn5["helpurl"].InnerXml.ToString();
                            string ctlSupportPr = xn5["supportspartialrendering"].InnerXml.ToString();


                            List<KeyValuePair<string, object>> paramCol = new List<KeyValuePair<string, object>>();
                            paramCol.Add(new KeyValuePair<string, object>("@PaymentGatewayTypeID", module.PaymentGatewayTypeID));
                            paramCol.Add(new KeyValuePair<string, object>("@ControlName", ctlKey));
                            paramCol.Add(new KeyValuePair<string, object>("@ControlType", ctlType));
                            paramCol.Add(new KeyValuePair<string, object>("@ControlSource", ctlSource));
                            paramCol.Add(new KeyValuePair<string, object>("@DisplayOrder", displayOrder));
                            paramCol.Add(new KeyValuePair<string, object>("@StoreID", module.StoreID));
                            paramCol.Add(new KeyValuePair<string, object>("@PortalID", module.PortalID));
                            paramCol.Add(new KeyValuePair<string, object>("@CultureName", module.CultureName));
                            paramCol.Add(new KeyValuePair<string, object>("@AddedBy", GetUsername));
                            paramCol.Add(new KeyValuePair<string, object>("@Update", update));
                            paramCol.Add(new KeyValuePair<string, object>("@HelpUrl", ctlHelpUrl));
                            paramCol.Add(new KeyValuePair<string, object>("@SupportsPartialRendering", bool.Parse(ctlSupportPr.ToString())));
                            if (xn5.Attributes["type"] == null)
                            {
                                sqlH.ExecuteNonQuery("[dbo].[usp_Aspx_PaymentGateWayControlAdd]", paramCol);
                            }
                            else
                            {
                                if (xn5.Attributes["type"] != null && xn5.Attributes["type"].Value.ToString().ToLower() == "page")
                                {

                                    if (!IsPageExists(ctlKey))
                                    {
                                        //if (update == 0)
                                        // {
                                        try
                                        {
                                            #region "Module Creation Logic"

                                            // add into module table
                                            ModuleInfo moduleObj = new ModuleInfo();
                                            moduleObj.ModuleName = "AspxCommerce." + module.FriendlyName;
                                            moduleObj.Name = module.Name;
                                            moduleObj.PackageType = "Module";
                                            moduleObj.Owner = "AspxCommerce";
                                            moduleObj.Organization = "";
                                            moduleObj.URL = "";
                                            moduleObj.Email = "";
                                            moduleObj.ReleaseNotes = "";
                                            moduleObj.FriendlyName = ctlKey;
                                            moduleObj.Description = ctlKey;
                                            moduleObj.Version = module.Version;
                                            moduleObj.isPremium = true;
                                            moduleObj.BusinessControllerClass = "";
                                            moduleObj.FolderName = module.FolderName;                                           
                                            moduleObj.supportedFeatures = 0;
                                            moduleObj.CompatibleVersions = "";
                                            moduleObj.dependencies = "";
                                            moduleObj.permissions = "";                                     

                                            int[] outputValue;
                                            outputValue = moduleCtr.AddModules(moduleObj, false, 0, true,
                                                                                      DateTime.Now, GetPortalID,
                                                                                      GetUsername);
                                            moduleObj.ModuleID = outputValue[0];
                                            moduleObj.ModuleDefID = outputValue[1];
                                            newModuleID = moduleObj.ModuleID;
                                            newModuleDefID = moduleObj.ModuleDefID;


                                            //insert into ProtalModule table

                                            newPortalmoduleID = moduleCtr.AddPortalModules(GetPortalID,
                                                                                                  newModuleID, true,
                                                                                                  DateTime.Now,
                                                                                                  GetUsername);
                                            #endregion

                                            //install permission for the installed module in ModuleDefPermission table with ModuleDefID and PermissionID
                                            int controlType = 0;
                                            controlType = ctlType;
                                            string IconFile = "";

                                            //add into module control table
                                            moduleCtr.AddModuleCoontrols(newModuleDefID, ctlKey + "View",
                                                                               ctlTitle + "View", ctlSource,
                                                                               IconFile, controlType, 0, ctlHelpUrl,
                                                                               bool.Parse(ctlSupportPr), true,
                                                                               DateTime.Now,
                                                                               GetPortalID, GetUsername);

                                            //sp_ModuleDefPermissionAdd
                                            string ModuleDefPermissionID;
                                            List<KeyValuePair<string, object>> paramDef =
                                                new List<KeyValuePair<string, object>>();
                                            paramDef.Add(new KeyValuePair<string, object>("@ModuleDefID",
                                                                                          newModuleDefID));
                                            paramDef.Add(new KeyValuePair<string, object>("@PortalModuleID",
                                                                                          newPortalmoduleID));
                                            paramDef.Add(new KeyValuePair<string, object>("@PermissionID", 1));
                                            paramDef.Add(new KeyValuePair<string, object>("@IsActive", true));
                                            paramDef.Add(new KeyValuePair<string, object>("@AddedOn", DateTime.Now));
                                            paramDef.Add(new KeyValuePair<string, object>("@PortalID", GetPortalID));
                                            paramDef.Add(new KeyValuePair<string, object>("@AddedBy", GetUsername));
                                            ModuleDefPermissionID =
                                                sqlH.ExecuteNonQueryAsGivenType<string>(
                                                    "[dbo].[sp_ModuleDefPermissionAdd]", paramDef,
                                                    "@ModuleDefPermissionID");

                                            //ModuleDefPermissionID
                                            List<KeyValuePair<string, object>> paramPage =
                                                new List<KeyValuePair<string, object>>();
                                            paramPage.Add(new KeyValuePair<string, object>("@ModuleDefID",
                                                                                           newModuleDefID));
                                            paramPage.Add(new KeyValuePair<string, object>("@PageName", ctlKey));
                                            paramPage.Add(new KeyValuePair<string, object>("@PortalID", GetPortalID));
                                            paramPage.Add(new KeyValuePair<string, object>(
                                                              "@ModuleDefPermissionID",
                                                              int.Parse(ModuleDefPermissionID)));
                                            ;
                                            sqlH.ExecuteNonQuery("[dbo].[usp_Aspx_CreatePaymentGatewayPage]",
                                                                 paramPage);

                                        }
                                        catch (Exception ex)
                                        {

                                            ProcessException(ex);
                                        }
                                        //   }
                                    }

                                }
                            }
                        }


                        XmlNodeList xnList2 = doc.SelectNodes("sageframe/folders/folder/settings/setting");
                        int onetime = 0;
                        foreach (XmlNode xn2 in xnList2)
                        {
                            onetime++;
                            string settingkey = xn2["key"].InnerXml.ToString();
                            string settingvalue = xn2["value"].InnerXml.ToString();
                            List<KeyValuePair<string, object>> paramCol = new List<KeyValuePair<string, object>>();
                            paramCol.Add(new KeyValuePair<string, object>("@PaymentGatewayTypeID", module.PaymentGatewayTypeID));
                            paramCol.Add(new KeyValuePair<string, object>("@StoreID", module.StoreID));
                            paramCol.Add(new KeyValuePair<string, object>("@PortalID", module.PortalID));
                            paramCol.Add(new KeyValuePair<string, object>("@SettingKey", settingkey));
                            paramCol.Add(new KeyValuePair<string, object>("@SettingValue", settingvalue));
                            paramCol.Add(new KeyValuePair<string, object>("@AddedBy", GetUsername));
                            paramCol.Add(new KeyValuePair<string, object>("@Update", update));
                            paramCol.Add(new KeyValuePair<string, object>("@onetime", onetime));
                            sqlH.ExecuteNonQuery("[dbo].[usp_Aspx_PaymentGateWaySettingByKeyAdd]", paramCol);
                        }

                        XmlNodeList xnList3 = doc.SelectNodes("sageframe/folders/folder/files/file");
                        if (xnList3.Count != 0)
                        {
                            foreach (XmlNode xn3 in xnList3)
                            {
                                string fileName = xn3["name"].InnerXml;
                                try
                                {
                                    #region CheckValidDataSqlProvider
                                    if (!String.IsNullOrEmpty(fileName) && fileName.Contains(module.Version + ".SqlDataProvider"))
                                    {
                                        _exceptions = ReadSQLFile(module.TempFolderPath, fileName);
                                    }
                                    #endregion

                                    #region CheckAlldllFiles
                                    if (!String.IsNullOrEmpty(fileName) && fileName.Contains(".dll"))
                                    {
                                        dllFiles.Add(fileName);
                                    }
                                    #endregion

                                    #region ReadUninstall SQL FileName
                                    if (!String.IsNullOrEmpty(fileName) && fileName.Contains("Uninstall.SqlDataProvider"))
                                    {
                                        unistallScriptFile = fileName;
                                    }
                                    #endregion
                                }
                                catch (Exception ex)
                                {
                                    _exceptions += ex.Message;
                                    break;
                                }
                            }
                        }

                        if (_exceptions != string.Empty)
                        {
                            if (module.PaymentGatewayTypeID.ToString() != null && module.PaymentGatewayTypeID > 0)
                            {
                                //Run unstallScript
                                if (unistallScriptFile != "")
                                {
                                    _exceptions = ReadSQLFile(module.TempFolderPath, unistallScriptFile);
                                }
                                //Delete Module info from data base
                                PaymentGatewayRollBack(module.PaymentGatewayTypeID, GetPortalID, module.StoreID);
                                module.PaymentGatewayTypeID = -1;
                            }
                        }
                        #endregion
                    }
                    catch
                    {
                        if (module.PaymentGatewayTypeID.ToString() != null && module.PaymentGatewayTypeID > 0)
                        {
                            //Run unstallScript
                            if (unistallScriptFile != "")
                            {
                                _exceptions = ReadSQLFile(module.TempFolderPath, unistallScriptFile);
                            }
                            //Delete Module info from data base
                            if (update == 0)
                            {
                               PaymentGatewayRollBack(module.PaymentGatewayTypeID, GetPortalID, module.StoreID);
                            }
                            module.PaymentGatewayTypeID = -1;
                        }
                    }
                    #endregion
                }
            }

            if (module.PaymentGatewayTypeID.ToString() != null && module.PaymentGatewayTypeID > 0 && _exceptions == string.Empty)
            {
                string path = HttpContext.Current.Server.MapPath("~/");
                string flPath = module.FolderName.ToString().Replace("/","\\"); 
                string targetPath = path + SageFrame.Common.RegisterModule.Common.ModuleFolder + '\\' + flPath;
                CopyDirectory(module.TempFolderPath, targetPath);
                for (int i = 0; i < dllFiles.Count; i++)
                {
                    string sourcedllFile = module.TempFolderPath + '\\' + dllFiles[i].ToString();
                    string targetdllPath = path + SageFrame.Common.RegisterModule.Common.DLLTargetPath + '\\' + dllFiles[i].ToString();
                    File.Copy(sourcedllFile, targetdllPath, true);
                    //File.Move();
                }
            }
            DeleteTempDirectory(module.TempFolderPath);
        }
    public void RegisterModule(string moduleName, string moduleFolderPath, string procedure)
    {
        ModuleInfo objModule = new ModuleInfo();
        int _newModuleID = 0;
        int _newModuleDefID = 0;
        int _newPortalmoduleID = 0;
        string Exceptions = string.Empty;
        string ExtensionMessage = string.Empty;
        try
        {
            //add module and package tables
            objModule.ModuleName = moduleName;
            objModule.Name = moduleName;
            objModule.FriendlyName = moduleName;
            objModule.Description = txtModuleDescription.Text;
            objModule.FolderName = moduleName;
            objModule.Version = "01.00.00";//ddlFirst.SelectedValue + "." + ddlSecond.SelectedValue + "." + ddlLast.SelectedValue;//"01.00.00"; //new Version(1, 0, 0);
            objModule.Owner = "";
            objModule.Organization = "";
            objModule.URL = "";
            objModule.Email = "";
            objModule.ReleaseNotes = "";
            objModule.License = "";
            objModule.PackageType = "Module";
            objModule.isPremium = true;
            objModule.supportedFeatures = 0;
            objModule.BusinessControllerClass = "";
            objModule.CompatibleVersions = "";
            objModule.dependencies = "";
            objModule.permissions = "";
            ModuleController objController = new ModuleController();

            int[] outputValue;
            outputValue = objController.AddModules(objModule, false, 0, true, DateTime.Now, GetPortalID, GetUsername);
            objModule.ModuleID = outputValue[0];
            objModule.ModuleDefID = outputValue[1];
            _newModuleID = objModule.ModuleID;
            _newModuleDefID = objModule.ModuleDefID;

            //insert into ProtalModule table
            _newPortalmoduleID = objController.AddPortalModules(GetPortalID, _newModuleID, true, DateTime.Now, GetUsername);

            //install permission for the installed module in ModuleDefPermission table with ModuleDefID and PermissionID

            // get the default module VIEW permissions
            int _permissionIDView = objController.GetPermissionByCodeAndKey("SYSTEM_VIEW", "VIEW");
            objController.AddModulePermission(_newModuleDefID, _permissionIDView, GetPortalID, _newPortalmoduleID, true, GetUsername, true, DateTime.Now, GetUsername);
            int _permissionIDEdit = objController.GetPermissionByCodeAndKey("SYSTEM_EDIT", "EDIT");
            objController.AddModulePermission(_newModuleDefID, _permissionIDEdit, GetPortalID, _newPortalmoduleID, true, GetUsername, true, DateTime.Now, GetUsername);

            RegisterControl(moduleName, moduleFolderPath + moduleName + "/" + moduleName + ".ascx", 1, _newModuleDefID);
            if (chkEdit.Checked)
            {
                RegisterControl(moduleName, moduleFolderPath + moduleName + "/" + moduleName + "Edit" + ".ascx", 2, _newModuleDefID);
            }
            if (chkSetting.Checked)
            {
                RegisterControl(moduleName, moduleFolderPath + moduleName + "/" + moduleName + "Setting" + ".ascx", 3, _newModuleDefID);
            }
            if (Exceptions != string.Empty)
            {
                if (objModule.ModuleID > 0 && _newModuleDefID > 0)
                {
                    Installers install = new Installers();
                    //Delete Module info from data base
                    install.ModulesRollBack(objModule.ModuleID, GetPortalID);
                }
            }
            else
            {
                SQLHandler sageSQLHandler = new SQLHandler();
                sageSQLHandler.ExecuteScript(procedure, true);
            }
        }
        catch (Exception ex)
        {
            ShowMessage("", ex.ToString(), "", SageMessageType.Error);
            ProcessException(ex);
        }
        Response.Redirect(Request.Url.AbsoluteUri);
    }