protected void btnSave_Click(object sender, EventArgs e)
    {
        string strResult   = "";
        int    intSchoolID = 0;

        string[] strArray = this.hidFlag.Value.Split('^');
        try
        {
            List <string> lstArray  = new List <string>();
            byte[]        fileData  = null;
            byte[]        imageData = null;

            long lnLength = 0;

            fUploadEmblem.Attributes["filename"] = hdnSImagePath.Value;
            if (fUploadEmblem.PostedFile.FileName != "")
            {
                if (fUploadEmblem.HasFile)
                {
                    try
                    {
                        Stream myStream = fUploadEmblem.PostedFile.InputStream;
                        lnLength = myStream.Length;
                        fileData = new byte[(int)myStream.Length];
                        myStream.Read(fileData, 0, (int)lnLength);
                        myStream.Close();
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            string strEmblemStatus;
            if (rbtnYes.Checked == true)
            {
                strEmblemStatus = "Y";
            }
            else
            {
                strEmblemStatus = "N";
            }
            //if (strArray[0] == "N" || strArray[0]=="E" && strArray[3].Trim().ToUpper() != txtAddress.Text.Trim().ToUpper())
            //{
            //    if (objCCWeb.ReturnNumericValue("SELECT COUNT(SchoolID) FROM MTClientCompany WHERE Address='" + txtAddress.Text.Trim().Replace("'", "''") + "'") > 0)
            //    {
            //        strResult = objCCWeb.pDisplayMessage("" + Session["Type"].ToString() + "", "5", lblAddress.Text);
            //        ClientScript.RegisterStartupScript(this.GetType(), "", "<script>" + strHideID + "alert('" + strResult + "')</script>");
            //        //ClientScript.RegisterStartupScript(this.GetType(), "", "<script>" + strHideID + "alert('Address Already Exist')</script>");
            //        hidFlag.Value = "S";
            //        return;
            //    }
            //}
            if (strArray[0] == "E")
            {
                lstArray.Add("UPDATE MTClientCompany SET SchoolName1=" + objCCWeb.fReplaceChar(txtInstitution1) + ",SchoolName2='" + txtInstitution2.Text.Trim().Replace("'", "''") + "',Address=" + objCCWeb.fReplaceChar(txtAddress) + ",ReportHeader=" + objCCWeb.fReplaceChar(txtReportHeader) +
                             ",City=" + objCCWeb.fReplaceChar(txtCity) + ",State=" + objCCWeb.fReplaceChar(txtState) + ",Pincode=" + objCCWeb.fReplaceChar(txtPincode) + ",Telephone=" + objCCWeb.fReplaceChar(txtTelephone) + "," +
                             "Fax=" + objCCWeb.fReplaceChar(txtFax) + ",Email=" + objCCWeb.fReplaceChar(txtEmail) + ",DirectorName=" + objCCWeb.fReplaceChar(txtDirector) + ",DirectorTelephone=" + objCCWeb.fReplaceChar(txtDirPhone) +
                             ",PrincipalName=" + objCCWeb.fReplaceChar(txtPrincipal) + ",PrincipalPhone=" + objCCWeb.fReplaceChar(txtPriPhone) + ",VicePrincipalName=" + objCCWeb.fReplaceChar(txtVicePrincipal) + "," +
                             "VicePrincipalPhone=" + objCCWeb.fReplaceChar(txtVicePriPhone) + ",AdministratorName=" + objCCWeb.fReplaceChar(txtAdministrator) + ",AdministratorPhone=" + objCCWeb.fReplaceChar(txtAdmPhone) + ",Affiliation=" + objCCWeb.fReplaceChar(txtAffiliation) +
                             ",Medium=" + objCCWeb.fReplaceChar(txtMedium) + ",Motto=" + objCCWeb.fReplaceChar(txtMotto) + ",EstablishedOn=" + objCCWeb.fReplaceChar(txtEstablishedOn) + ",EstablishmentCode=" + objCCWeb.fReplaceChar(txtEstablishmentCode) + "," +
                             "BankAccountNo=" + objCCWeb.fReplaceChar(txtBankACNo) + ",EmblemStatus='" + strEmblemStatus + "',UpdateUserID=" + Session["UID"].ToString() + ",UpdateDate=GETDATE(),PLPackDate=" + objCCWeb.ReturnDateorNull(txtPLPackDate.Text.Trim()) + ",PLPackdateStaff=" + objCCWeb.ReturnDateorNull(txtPLPackDateStaff.Text.Trim()) + " WHERE SchoolID=" + strArray[1] + "");

                lstArray.Add("INSERT INTO UserUpdateDetails(UID,SessionID,UpdateDate,FormName,Details) VALUES(" + Session["UID"] + ",'" + Session.SessionID + "',GETDATE(),'mnuInstitutionMaster','School " + (txtInstitution1.Text.Trim().Replace("'", "''") != "" ? txtInstitution1.Text.Trim().Replace("'", "''") : txtInstitution2.Text.Trim().Replace("'", "''")) + " Information ,Is Modified')");
            }
            else
            {
                intSchoolID = objCCWeb.ReturnNumericValue("SELECT ISNULL(MAX(SchoolID),0)+1 FROM MTClientCompany");

                lstArray.Add("INSERT INTO MTClientCompany(SchoolID,SchoolName1,SchoolName2,Address,ReportHeader,City,State,Pincode,Telephone,Fax,Email,DirectorName,DirectorTelephone,PrincipalName,PrincipalPhone,VicePrincipalName,VicePrincipalPhone,AdministratorName,AdministratorPhone," +
                             "Affiliation,Medium,Motto,EstablishedOn,EstablishmentCode,BankAccountNo,EmblemStatus,EntryUserID,EntryDate) SELECT ISNULL(MAX(SchoolID),0)+1, '" + txtInstitution1.Text.Trim().Replace("'", "''") + "','" + txtInstitution2.Text.Trim().Replace("'", "''") + "','" + txtAddress.Text.Trim().Replace("'", "''") + "','" + txtReportHeader.Text.Trim().Replace("'", "''") +
                             "','" + txtCity.Text.Trim().Replace("'", "''") + "','" + txtState.Text.Trim().Replace("'", "''") + "','" + txtPincode.Text.Trim().Replace("'", "''") + "','" + txtTelephone.Text.Trim().Replace("'", "''") + "'," +
                             "'" + txtFax.Text.Trim().Replace("'", "''") + "','" + txtEmail.Text.Trim().Replace("'", "''") + "','" + txtDirector.Text.Trim().Replace("'", "''") + "','" + txtDirPhone.Text.Trim().Replace("'", "''") +
                             "','" + txtPrincipal.Text.Trim().Replace("'", "''") + "','" + txtPriPhone.Text.Trim().Replace("'", "''") + "','" + txtVicePrincipal.Text.Trim().Replace("'", "''") + "'," +
                             "'" + txtVicePriPhone.Text.Trim().Replace("'", "''") + "','" + txtAdministrator.Text.Trim().Replace("'", "''") + "','" + txtAdmPhone.Text.Trim().Replace("'", "''") + "','" + txtAffiliation.Text.Trim().Replace("'", "''") +
                             "','" + txtMedium.Text.Trim().Replace("'", "''") + "','" + txtMotto.Text.Trim().Replace("'", "''") + "','" + txtEstablishedOn.Text.Trim().Replace("'", "''") + "','" + txtEstablishmentCode.Text.Trim().Replace("'", "''") + "'," +
                             "'" + txtBankACNo.Text.Trim().Replace("'", "''") + "','" + strEmblemStatus + "'," + Session["UID"].ToString() + ",GETDATE() FROM MTClientCompany");
            }
            strResult = objCCWeb.ExecuteQueryList(lstArray);
            if (strArray[0] == "E")
            {
                intSchoolID = Convert.ToInt32(strArray[1]);
            }

            if (hidFlag.Value == "N^")
            {
                hidFlag.Value = "N^";
            }
            else
            {
                hidFlag.Value = "E^";
            }
            if (strResult == "")
            {
                if (lnLength > 0)
                {
                    //SqlConnection conSImage = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings.Get("ConnectionString"));
                    SqlConnection conSImage = new SqlConnection(objCCWeb.ReturnConnectionString());
                    conSImage.Open();
                    SqlCommand cmdSImage = new SqlCommand("UPDATE MTClientCompany SET Emblem=@img,EmblemLength=" + lnLength.ToString() + " where SchoolID=" + intSchoolID + "", conSImage);
                    cmdSImage.CommandType = CommandType.Text;
                    cmdSImage.Parameters.Add(new SqlParameter("@img", SqlDbType.Image));
                    cmdSImage.Parameters["@img"].Value = fileData;
                    cmdSImage.ExecuteNonQuery();
                    conSImage.Close();
                    conSImage.Dispose();
                }
                if (lnLength == 0)
                {
                    if (strArray[0] == "E")
                    {
                        SqlDataReader rdrImage = objCCWeb.BindReader("SELECT ISNULL(Emblem,'') AS Emblem,CAST(ISNULL(EmblemLength,0) AS INT) AS EmblemLength FROM MTClientCompany WHERE SchoolID=" + intSchoolID + "");
                        if (rdrImage.Read())
                        {
                            int intLength = (int)rdrImage["EmblemLength"];
                            imageData = new byte[intLength];
                            imageData = (byte[])rdrImage["Emblem"];
                            if (intLength != 0)
                            {
                                lnLength = intLength;
                            }
                        }
                        rdrImage.Close();
                        rdrImage.Dispose();
                    }
                }
                if (strArray[0] == "N")
                {
                    strResult = objCCWeb.pDisplayMessage("" + Session["Type"].ToString() + "", "1", "");
                }
                else
                {
                    strResult = objCCWeb.pDisplayMessage("" + Session["Type"].ToString() + "", "2", "");
                }
                ClientScript.RegisterStartupScript(this.GetType(), "displayScriptMsg", "<script>" + strHideID + "alert('" + strResult + "')</script>");
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "displayE", "<script language=javascript>" + strHideID + "alert('" + strResult + "')</script>");
            }
            if (fUploadEmblem.PostedFile.FileName == "")
            {
                fileData = imageData;
            }
            btnCancel_Click(sender, e);
        }
        catch (Exception ex)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "displayScript", "<script language=javascript>" + strHideID + "alert('" + ex.Message + "')</script>");
        }
        BindDDL();
        btnCancel_Click(sender, e);
    }