Monday, 1 February 2016

Change the source url of kendo ui pop up window .


Change the source url of kendo ui pop up window .
   var jq=   jQuery.noConflict();
        var direction = '@Url.Action("EditEquipmentPopUp", "Service")';
     
        var wnd = jq("#windowEquipment").data("kendoWindow");
        if (typeof wnd != 'undefined')
        {
            wnd.refresh({
                url: direction,
                data: { verno: verno, ServiceCode:serviceid}
            });
            wnd.center();
            wnd.open();
        }

Reassign the kendo Ui pop up window in javascript

Reinitialize the kendo Ui pop up window in javascript

 jq("#windowEquipment").kendoWindow({
                title: "Edit Equipment",
                width:"800px",
                height: "500px",

                content: {
                    url: direction,
                    data: { verno: verno, ServiceCode:serviceid}
                }
               
            });
            var dialog = jq("#windowEquipment").data("kendoWindow");
           
            dialog.center();
            dialog.open();

Encryption and Decryption of query string that will pass by URL

Encryption 
  public static string Encrypt(string strToEncrypt, string strKey)
        {
            try
            {
                TripleDESCryptoServiceProvider objDESCrypto = new TripleDESCryptoServiceProvider();
                MD5CryptoServiceProvider objHashMD5 = new MD5CryptoServiceProvider();

                byte[] byteHash, byteBuff;
                string strTempKey = strKey;

                byteHash = objHashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strTempKey));
                objHashMD5 = null;
                objDESCrypto.Key = byteHash;
                objDESCrypto.Mode = CipherMode.ECB;

                objDESCrypto.Padding = PaddingMode.PKCS7;

                byteBuff = ASCIIEncoding.ASCII.GetBytes(strToEncrypt);
                strToEncrypt = Convert.ToBase64String(objDESCrypto.CreateEncryptor().TransformFinalBlock(byteBuff, 0, byteBuff.Length));
                strToEncrypt = strToEncrypt.Replace("+", "AeIoU").Replace("/", "AEIou").Replace("=", "aeIOU");

                return strToEncrypt;


            }
            catch (Exception ex)
            {
                return "Wrong Input. " + ex.Message;
            }
        }
====================================================
Decryption  


    public static string Decrypt(string strEncrypted, string strKey)
        {
            try
            {
                strEncrypted = strEncrypted.Replace("AeIoU", "+").Replace("AEIou", "/").Replace("aeIOU", "=");
                TripleDESCryptoServiceProvider objDESCrypto = new TripleDESCryptoServiceProvider();
                MD5CryptoServiceProvider objHashMD5 = new MD5CryptoServiceProvider();

                byte[] byteHash, byteBuff;
                string strTempKey = strKey;

                byteHash = objHashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strTempKey));
                objHashMD5 = null;
                objDESCrypto.Key = byteHash;
                objDESCrypto.Mode = CipherMode.ECB; //CBC, CFB
                objDESCrypto.Padding = PaddingMode.PKCS7;

                byteBuff = Convert.FromBase64String(strEncrypted);
                string strDecrypted = ASCIIEncoding.ASCII.GetString(objDESCrypto.CreateDecryptor().TransformFinalBlock(byteBuff, 0, byteBuff.Length));
                objDESCrypto = null;

                return strDecrypted;

               
            }
            catch (Exception ex)
            {
                return "Wrong Input. " + ex.Message;
            }
        }

Api call in asp.net desktop application


Api call in asp.net desktop application 

var ApiUrl = ConfigurationManager.AppSettings["ApiUrl"].ToString();//ex http://www.abc.com/
                client.BaseAddress = new Uri(ApiUrl);
                string Email = DataEncryption.Encrypt(txtEmail.Text);
                string Password = DataEncryption.Encrypt(txtPassword.Text);
                string apiKey = "api/UserApi/CheckUserLicense/" + Email + "/" + Password;
                var response = client.GetAsync(apiKey).Result;
                if (response.IsSuccessStatusCode)
                {
                    var responseString = response.Content.ReadAsStringAsync().Result;
                    UserModel model = JsonConvert.DeserializeObject<UserModel>(responseString);
              }

Execute a script in c#

you have to take reference of  these


url of that file will be
C:\Program Files\Microsoft SQL Server\120\SDK\Assemblies
these will come after install the sql server 
private bool ExecuteScript(SqlConnection conn)
        {
            try
            {
                string strSqlFilePath = Properties.Settings.Default.sqlScriptPath;
                string strFilePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + strSqlFilePath;
                string script = File.ReadAllText(@strFilePath);
                ServerConnection servCon = new ServerConnection(conn);
                servCon.StatementTimeout = 240;
                Server server = new Server(servCon);
                conn.Open();
                server.ConnectionContext.ExecuteNonQuery(script);
            }
            catch (System.Exception ex)
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                MessageBox.Show("Please Check Server and database name. Incorrect Server and database name.", "Database", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return true;
        }

Update AppSettings of config file in runtiome in asp.net Desktop Application


Update AppSettings of config file in runtime in asp.net Desktop Application 


 public static void SaveConfig(string ConSource)
        {
            string appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string configFile = System.IO.Path.Combine(appPath, "b02C_core.exe.config");
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            config.AppSettings.Settings["connectb02C_coreDB"].Value = ConSource;
            config.Save();
            ConfigurationManager.RefreshSection("connectionStrings");
        }

Update web config file in runtime in asp.net desktop application


Update web config file in runtime in asp.net desktop application .


 public static void updateConfigFile(string con)
        {
            try
            {
                var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                var connectionStringsSection = (ConnectionStringsSection)config.GetSection("connectionStrings");
                connectionStringsSection.ConnectionStrings["b02C_coreConnectionStrings"].ConnectionString = con;
                config.Save();
                ConfigurationManager.RefreshSection("connectionStrings");
            }
            catch (Exception E)
            {
                MessageBox.Show(E.ToString());
            }
        }

Create a directory permition of installation folder in asp.net desktop application


Create a directory permition of installation folder in asp.net desktop application

You can us only the color block of code .

 [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var connectionstring = ConfigurationManager.AppSettings["connectb02C_coreDB"].ToString().Trim();
            b02C_core.DataAccess.DataAccess obj = new DataAccess.DataAccess();
            if (string.IsNullOrWhiteSpace(connectionstring) && connectionstring == "")
            {
                string sFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                try
                {
                    DirectoryInfo info = new DirectoryInfo(sFolder);
                    WindowsIdentity self = System.Security.Principal.WindowsIdentity.GetCurrent();
                    DirectorySecurity ds = info.GetAccessControl();
                    ds.AddAccessRule(new FileSystemAccessRule(self.Name,
                    FileSystemRights.FullControl,
                    InheritanceFlags.ObjectInherit |
                    InheritanceFlags.ContainerInherit,
                    PropagationFlags.None,
                    AccessControlType.Allow));
                    info.SetAccessControl(ds);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Oops! Error in setup. ","Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Application.Run(new SqlSetUpForm());
            }

Check the connection string into Desktop App in case of fist install to setup the Database



Check the connection string into Desktop App in case of fist install to setup the Database

static void Main()
        {
            Application.EnableVisualStyles(); 
            Application.SetCompatibleTextRenderingDefault(false);
            var connectionstring = ConfigurationManager.AppSettings["connectb02C_coreDB"].ToString().Trim();
            b02C_core.DataAccess.DataAccess obj = new DataAccess.DataAccess();
            if (string.IsNullOrWhiteSpace(connectionstring) && connectionstring == "")
            {
                
                Application.Run(new SqlSetUpForm());
            }
            else
            {
                Application.Run(new LoginForm());
            }
        }