protected void btn_merchant_Click(object sender, EventArgs e)
        {
            BusinessEntitiesBS.merchantObj merchantValues = new BusinessEntitiesBS.merchantObj();
            merchantValues.mName = txt_mName.Text;
            merchantValues.mType = ddl_mType.SelectedItem.ToString();
            merchantValues.mAddress = txt_mAddress.InnerText.ToString();
            merchantValues.mPhno = txt_mPhno.Text;
            merchantValues.mLoginId = txt_mLoginId.Text;
            merchantValues.mPwd = CLASS.PasswordEncryption.EncryptIt(txt_mPwd.Text);
            merchantValues.mArea = areaAc.AreaId;
            merchantValues.mCatid = Int32.Parse(ddlCatagoryMer.SelectedValue);

            try
            {
                IAdmin insertMerchant = new AdminItems();
                int inserted = insertMerchant.insertMerchant(merchantValues);
                if (inserted != -1)
                {
                    lbl_merchantStatus.Text = "Merchant Added";
                    getMerchants();
                    ClearCache();
                }
                else
                {
                    lbl_merchantStatus.Text = "Merchant Not Added";
                }
            }
            catch (Exception ex)
            {
                lbl_merchantStatus.Text = HardCodedValues.BuddaResource.CatchBlockError + ex.Message;
            }
        }
        protected void btn_submit_Click(object sender, EventArgs e)
        {
            string aname = txt_username.Text;
            string pwd = CLASS.PasswordEncryption.EncryptIt(txt_password.Text);

            IAdmin checklogin = new AdminItems();
            int count = checklogin.checkLogin(aname, pwd);

            if (count != -1)
            {
                string roles = ConfigurationSettings.AppSettings["AdminPages"];

                CLASS.Authenticate authenticateMe = new budhashop.CLASS.Authenticate();
                authenticateMe.AuthenticateUser(aname, roles);

                // Get the requested page from the url
                string returnUrl = Request.QueryString["ReturnUrl"];

                // check if it exists, if not then redirect to default page
                if (returnUrl == null) returnUrl = "~/ADMIN/InsertPage.aspx";

                Response.Redirect(returnUrl);
            }
            else
            {
                lbl_submit.Text = HardCodedValues.BuddaResource.LoginFail;
            }
        }
        protected void CatagoryBtn_Click(object sender, EventArgs e)
        {
            string catName = CatagoryTxt.Text;
            string catDesc = catDescTxt.InnerText.ToString();
            bool catStatus = catStatusCb.Checked;

            BusinessEntitiesBS.Catagory_Entities.catagoryObj catObj = new BusinessEntitiesBS.Catagory_Entities.catagoryObj();

            catObj.catagoryName = catName;
            catObj.catagoryDesc = catDesc;
            catObj.catagoryStatus = catStatus;

            try
            {

                IAdmin catInsert = new AdminItems();

                int insertCatChk = catInsert.insertCatagory(catObj);
                if (insertCatChk != -1)
                {
                    string NewDir = Server.MapPath("~/ItemImages/" + insertCatChk);
                    try
                    {
                        // Check if directory exists
                        if (!Directory.Exists(NewDir))
                        {
                            // Create the directory.
                            Directory.CreateDirectory(NewDir);
                            catMsgLbl.Text = "Catagory inserted";

                        }
                    }
                    catch (IOException _ex)
                    {
                        catMsgLbl.Text = "Error: Floder" + _ex.Message;
                    }

                }
                else
                {
                    catMsgLbl.Text = "Catagory not inserted";
                    catMsgLbl.ForeColor = System.Drawing.Color.Red;
                }
            }
            catch (Exception exp)
            {
                //throw exp;
                catMsgLbl.Text = "Unable to connect" + exp.Message;
                catMsgLbl.ForeColor = System.Drawing.Color.Red;
            }
        }
 private void getFeedBackList()
 {
     try
     {
         IAdmin getFeedback = new AdminItems();
         DataTable feedbackDt = getFeedback.getFeedback();
         gv_feedback.DataSource = feedbackDt;
         gv_feedback.DataBind();
     }
     catch
     {
         gv_feedback.DataSource = null;
         gv_feedback.DataBind();
     }
 }
        protected void userGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int userid = Convert.ToInt32(userGrid.DataKeys[e.RowIndex].Value.ToString());
            string username = userGrid.DataKeys[e.RowIndex].Values["UserName"].ToString();
            string password = userGrid.DataKeys[e.RowIndex].Values["PWD"].ToString();
            TextBox newpassword = (TextBox)userGrid.Rows[e.RowIndex].FindControl("txt_editpwd");
            TextBox emailid = (TextBox)userGrid.Rows[e.RowIndex].FindControl("txt_editemailid");
            TextBox phno = (TextBox)userGrid.Rows[e.RowIndex].FindControl("txt_editphno");
            TextBox address = (TextBox)userGrid.Rows[e.RowIndex].FindControl("txt_editaddress");
            CheckBox userstatus = (CheckBox)userGrid.Rows[e.RowIndex].FindControl("cb_editactvsts");

            string encryptedpwd;
            if (password == newpassword.Text)
            {
                encryptedpwd = newpassword.Text;
            }
            else
            {
                encryptedpwd = CLASS.PasswordEncryption.EncryptIt(newpassword.Text);
            }

            BusinessEntitiesBS.UserEntities.userobj UpdateUserObj=new BusinessEntitiesBS.UserEntities.userobj();
            UpdateUserObj.uname=username;
            UpdateUserObj.pwd = encryptedpwd;
            UpdateUserObj.emailid=emailid.Text;
            UpdateUserObj.phno=phno.Text;
            UpdateUserObj.address=address.Text;
            UpdateUserObj.userstatus=userstatus.Checked;

            IAdmin UpdateUsers = new AdminItems();
            int updated = UpdateUsers.UpdateUsers(UpdateUserObj, userid);
            if (updated != -1)
            {
                lbl_status.Text = HardCodedValues.BuddaResource.UpdateSuccess;

                userGrid.EditIndex = -1;
                searchDT(txt_username.Text);
            }
            else
            {
                lbl_status.Text = HardCodedValues.BuddaResource.UpdateFail;
            }
        }
        private void getSubCatg()
        {
            try
            {
                IAdmin checkSubCatName = new AdminItems();
                DataTable dt = checkSubCatName.checkSubCatName(txt_SubCatName.Text, Int32.Parse(CatagoryDDL.SelectedValue));

                SubCatagoryDDL.DataSource = dt;
                SubCatagoryDDL.DataTextField = "SubCatName";
                SubCatagoryDDL.DataValueField = "SubCatId";
                SubCatagoryDDL.DataBind();
            }
            catch (Exception ex)
            {
                ItemMessageLbl.Text = HardCodedValues.BuddaResource.CatchBlockError + ex.Message;
            }
        }
 protected void btn_subcatagory_Click(object sender, EventArgs e)
 {
     if (lbl_SubCatName.Text == "Not Exist in DB")
     {
         int catid = Int32.Parse(ddl_Catagory.SelectedValue);
         string subCatName = txt_SubCatName.Text;
         try
         {
             IAdmin insertSubCatagory = new AdminItems();
             int inserted = insertSubCatagory.insertSubCatagory(catid, subCatName);
             if (inserted != -1)
             {
                 lbl_subCatStatus.Text = "Sub" + HardCodedValues.BuddaResource.CatogoryAdd;
                 txt_SubCatName.Text = "";
                 img_SubCatName.ImageUrl = "";
                 lbl_SubCatName.Text = "";
                 getSubCatg();
                 ClearCache();
             }
             else
             {
                 lbl_subCatStatus.Text = "Sub" + HardCodedValues.BuddaResource.CatogoryNotAdded;
             }
         }
         catch (Exception exp)
         {
             lbl_subCatStatus.Text = HardCodedValues.BuddaResource.CatchBlockError + exp.Message;
         }
     }
     else
     {
         txt_SubCatName.Focus();
         lbl_subCatStatus.Text = "Enter Valid Sub Catagory Name";
     }
 }
        protected DataTable getItems(int grpCatId)
        {
            try
            {

                IAdmin getItems = new AdminItems();
                DataTable itemDT = getItems.getItems(grpCatId);

                return itemDT;
            }
            catch (Exception iExp)
            {

                grpMsgLbl.Text = "Error Occured" + iExp.Message;
                return null;
            }
        }
        private void getMerchants()
        {
            try
            {
                IAdmin getmerchants = new AdminItems();
                DataTable dt = getmerchants.getMerchants();

                MerchantDDL.DataSource = dt;
                MerchantDDL.DataTextField = "MName";
                MerchantDDL.DataValueField = "MId";
                MerchantDDL.DataBind();
            }
            catch(Exception ex)
            {
                ItemMessageLbl.Text = HardCodedValues.BuddaResource.CatchBlockError + ex.Message;
            }
        }
 private DataTable getMerchants()
 {
     try
     {
         IAdmin getMerchantNames = new AdminItems();
         DataTable dt = getMerchantNames.getMerchants();
         return dt;
     }
     catch (Exception ex)
     {
         lbl_status.Text = HardCodedValues.BuddaResource.CatchBlockError + ex.Message;
         return null;
     }
 }
 private void searchDT(string itemname,int catid)
 {
     try
     {
         IAdmin searchitemname = new AdminItems();
         DataTable searchitemDT = searchitemname.SearchItems(itemname,catid);
         if (searchitemDT != null)
         {
             itemGrid.DataSource = searchitemDT;
             itemGrid.DataBind();
             lbl_status.Text = "";
         }
         else
         {
             lbl_status.Text = HardCodedValues.BuddaResource.NoItemError;
             itemGrid.DataSource = null;
             itemGrid.DataBind();
         }
     }
     catch (Exception iExp)
     {
         lbl_status.Text = HardCodedValues.BuddaResource.CatchBlockError  + iExp.Message;
     }
 }
        protected void grpSubmitBtn_Click(object sender, EventArgs e)
        {
            if (grpImageFU.FileName != string.Empty && grpImageFU.FileContent.Length <= 1024000)
            {
                //bool flagItem;
                float billedrate = 0, netrate = 0;

                DataTable grpItemsDt = new DataTable();
                DataColumn dc = new DataColumn("GrpItem", typeof(int));
                grpItemsDt.Columns.Add(dc);

                foreach (GridViewRow dRow in SelectedItemGrid.Rows)
                {
                    string nrate = dRow.Cells[4].Text.ToString();
                    string brate = dRow.Cells[3].Text.ToString();
                    billedrate += float.Parse(brate);
                    netrate += float.Parse(nrate);

                    int itemId = Convert.ToInt32(dRow.Cells[0].Text.ToString());

                    DataRow dr = grpItemsDt.NewRow();
                    dr[0] = itemId;

                    grpItemsDt.Rows.Add(dr);
                }

                string grpItemString = "";
                bool first = true;
                if (grpItemsDt.Rows.Count > 0)
                {
                    foreach (DataRow iRow in grpItemsDt.Rows)
                    {
                        if (first)
                        {
                            grpItemString += int.Parse(iRow["GrpItem"].ToString());
                            first = false;
                        }
                        else
                        {
                            grpItemString += "," + int.Parse(iRow["GrpItem"].ToString());
                        }

                    }

                    float discount = float.Parse(grpDiscountTxt.Text);
                    billedrate -= (billedrate * (discount / 100));
                    netrate = (netrate - (netrate * (discount / 100)));

                    BusinessEntitiesBS.GroupEntities.grpObj grpValus = new BusinessEntitiesBS.GroupEntities.grpObj();

                    grpValus.grpName = grpNameTxt.Text.ToString();
                    grpValus.grpDesc = grpDescTxt.Text.ToString();
                    grpValus.grpBR = billedrate;
                    grpValus.grpNR = netrate;
                    //grpValus.grpBR =  float.Parse(grpBrTxt.Text.ToString());
                    //grpValus.grpNR = float.Parse(grpNrTxt.Text.ToString());
                    grpValus.grpStatus = grpCb.Checked;
                    grpValus.fixedGrp = grpStatusCb.Checked;
                    grpValus.Quantity = Int32.Parse(grpQtyTxt.Text.ToString());
                    //item string
                    grpValus.itemIdStr = grpItemString;

                    IAdmin insertGroup = new AdminItems();
                    int grpId = insertGroup.insertGroup(grpValus);
                    if (grpId != -1)
                    {
                        //create folder for item images and save images. show result
                        string NewDir = Server.MapPath("~/GroupImages/" + "/" + grpId);
                        try
                        {
                            // Check if directory exists
                            if (!Directory.Exists(NewDir))
                            {
                                // Create the directory.
                                Directory.CreateDirectory(NewDir);
                            }
                        }
                        catch (IOException _ex)
                        {
                            grpMsgLbl.Text = HardCodedValues.BuddaResource.FloderError + _ex.Message;
                        }
                        string filename = grpId + "Photo.jpg";
                        grpImageFU.SaveAs(Server.MapPath("~/GroupImages/" + "/" + grpId + "/") + filename);

                        string filePath = Server.MapPath("~/GroupImages/" + "/" + grpId + "/") + filename;
                        string newfileMed = grpId + "Photomedium.jpg";
                        string newfileSmall = grpId + "small.jpg";
                        string resizedImageMed = Server.MapPath("~/GroupImages/" + "/" + grpId + "/") + newfileMed;
                        string resizedImageSmall = Server.MapPath("~/GroupImages/" + "/" + grpId + "/") + newfileSmall;
                        System.Drawing.Image img = System.Drawing.Image.FromFile(filePath);

                        System.Drawing.Bitmap bmpD = img as Bitmap;

                        Bitmap bmpDriverMed = new Bitmap(bmpD, 500, 500);
                        bmpDriverMed.Save(resizedImageMed, System.Drawing.Imaging.ImageFormat.Jpeg);

                        Bitmap bmpDriverSmall = new Bitmap(bmpD, 150, 150);
                        bmpDriverSmall.Save(resizedImageSmall, System.Drawing.Imaging.ImageFormat.Jpeg);

                        grpMsgLbl.Text =HardCodedValues.BuddaResource.GroupAdd;

                    }
                    else
                    {
                        grpMsgLbl.Text = HardCodedValues.BuddaResource.GroupNotAdded;
                    }
                }
                else
                {
                    grpMsgLbl.Text = HardCodedValues.BuddaResource.ItemSelect;
                }
            }
            else
            {
                grpMsgLbl.Text = HardCodedValues.BuddaResource.ImageSizeError;
            }
            ClearCache();
        }
        private void getcatgs()
        {
            try
            {
                IAdmin getCats = new AdminItems();
                DataTable catgDt = getCats.getCatagories();

                ddl_catagory.DataSource = catgDt;
                ddl_catagory.DataTextField = "CategoryName";
                ddl_catagory.DataValueField = "CategoryId";
                ddl_catagory.DataBind();
            }
            catch (Exception cExp)
            {
                throw cExp;
            }
        }
 protected void searchDT(string itemname)
 {
     try
     {
         IAdmin searchitemname = new AdminItems();
         DataTable searchitemDT = searchitemname.SearchItems(itemname);
         if (searchitemDT != null)
         {
             itemGrid.DataSource = searchitemDT;
             itemGrid.DataBind();
             lbl_status.Text = "";
         }
         else
         {
             lbl_status.Text = "No Items Found, Enter Existing Item Name";
             itemGrid.DataSource = null;
             itemGrid.DataBind();
         }
     }
     catch (Exception iExp)
     {
         lbl_status.Text = "Error Occured: " + iExp.Message;
     }
 }
        protected void CatagoryBtn_Click(object sender, EventArgs e)
        {
            string catName = CatagoryTxt.Text;
            string catDesc = catDescTxt.InnerText.ToString();
            bool catStatus = catStatusCb.Checked;

            BusinessEntitiesBS.Catagory_Entities.catagoryObj catObj = new BusinessEntitiesBS.Catagory_Entities.catagoryObj();

            catObj.catagoryName = catName;
            catObj.catagoryDesc = catDesc;
            catObj.catagoryStatus = catStatus;

            try
            {

                IAdmin catInsert = new AdminItems();

                int insertCatChk = catInsert.insertCatagory(catObj);

                if (insertCatChk != -1)
                {
                    string NewDir = Server.MapPath("~/ItemImages/" + insertCatChk);
                    try
                    {
                        // Check if directory exists
                        if (!Directory.Exists(NewDir))
                        {
                            // Create the directory.
                            Directory.CreateDirectory(NewDir);
                            catMsgLbl.Text = HardCodedValues.BuddaResource.CatogoryAdd;
                            getcatgs();

                        }
                    }
                    catch (IOException _ex)
                    {
                        catMsgLbl.Text = HardCodedValues.BuddaResource.FloderError + _ex.Message;
                    }

                }
                else
                {
                    catMsgLbl.Text = HardCodedValues.BuddaResource.CatogoryNotAdded;
                    catMsgLbl.ForeColor = System.Drawing.Color.Red;
                }
                ClearCache();
            }
            catch (Exception exp)
            {
                //throw exp;
                catMsgLbl.Text = HardCodedValues.BuddaResource.ConnectionError + exp.Message;
                catMsgLbl.ForeColor = System.Drawing.Color.Red;
            }
        }
        protected void itemGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int itemid = Convert.ToInt32(itemGrid.DataKeys[e.RowIndex].Value.ToString());
            TextBox itemname=(TextBox)itemGrid.Rows[e.RowIndex].FindControl("txt_iname");
            TextBox description=(TextBox)itemGrid.Rows[e.RowIndex].FindControl("txt_editidescr");
            FileUpload fu_itemimage = (FileUpload)itemGrid.Rows[e.RowIndex].FindControl("fu_iimage");
            TextBox catagoryid=(TextBox)itemGrid.Rows[e.RowIndex].FindControl("txt_cid");
            TextBox billedrate=(TextBox)itemGrid.Rows[e.RowIndex].FindControl("txt_billedrate");
            TextBox quantity = (TextBox)itemGrid.Rows[e.RowIndex].FindControl("txt_qty");
            TextBox netrate = (TextBox)itemGrid.Rows[e.RowIndex].FindControl("txt_netrate");

            //check whether the image is valid or not
            bool isImageValid = checkPhoto(fu_itemimage,Int32.Parse(catagoryid.Text),itemid);
            if (isImageValid)
            {
                //save updated values in database
                BusinessEntitiesBS.ItemEntities.ItemObj UpdateItemObj = new BusinessEntitiesBS.ItemEntities.ItemObj();
                UpdateItemObj.itemName = itemname.Text;
                UpdateItemObj.itemDesc = description.Text;
                UpdateItemObj.itemCatagory = Int32.Parse(catagoryid.Text);
                UpdateItemObj.itemBR = float.Parse(billedrate.Text);
                UpdateItemObj.itemQty = Int32.Parse(quantity.Text);
                UpdateItemObj.itemNR = float.Parse(netrate.Text);

                IAdmin UpdateItems = new AdminItems();
                int updated = UpdateItems.UpdateItems(UpdateItemObj, itemid);
                if (updated != -1)
                {
                    lbl_status.Text = "Updated Successfully";
                    itemGrid.EditIndex = -1;
                    if (txt_itemname.Text == "Enter Item Name/Id")
                    {
                        int grpCatId = Int32.Parse(ddl_catagory.SelectedValue.ToString());
                        getItems(grpCatId);
                    }
                    else
                    {
                        searchDT(txt_itemname.Text);
                    }
                }
                else
                {
                    lbl_status.Text = "Error Occured.. Row Not Updated";
                }
            }
            else
            {
                lbl_status.Text = "Selected file is not an image or it is greater than 1mb";
            }
        }
 protected void itemGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     int itemid = Convert.ToInt32(itemGrid.DataKeys[e.RowIndex].Value.ToString());
     IAdmin RemoveItem = new AdminItems();
     int removed = RemoveItem.removeItems(itemid);
     if (removed == -1)
     {
         lbl_status.Text = "Item Removed";
         if (txt_itemname.Text == "Enter Item Name/Id")
         {
             int grpCatId = Int32.Parse(ddl_catagory.SelectedValue.ToString());
             getItems(grpCatId);
         }
         else
         {
             searchDT(txt_itemname.Text);
         }
     }
     else
     {
         lbl_status.Text = "Error Occured while Removing the Item, Try again";
     }
 }
 protected void getItems(int grpCatId)
 {
     try
     {
         IAdmin getItems = new AdminItems();
         DataTable itemDT = getItems.getItems(grpCatId);
         if (itemDT != null)
         {
             itemGrid.DataSource = itemDT;
             itemGrid.DataBind();
         }
         else
         {
             lbl_status.Text = "No Data for items! change the catagory";
             itemGrid.DataSource = null;
             itemGrid.DataBind();
         }
     }
     catch (Exception iExp)
     {
         lbl_status.Text = "Error Occured: " + iExp.Message;
     }
 }
 protected void itemGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     int itemid = Convert.ToInt32(itemGrid.DataKeys[e.RowIndex].Value.ToString());
     IAdmin RemoveItem = new AdminItems();
     int removed = RemoveItem.removeItems(itemid);
     if (removed == -1)
     {
         lbl_status.Text = HardCodedValues.BuddaResource.ItemDeleted;
         ClearCache();
         int grpCatId = Int32.Parse(ddl_catagory.SelectedValue.ToString());
         if (txt_itemname.Text == "")
         {
             getItems(grpCatId);
         }
         else
         {
             searchDT(txt_itemname.Text, grpCatId);
         }
     }
     else
     {
         lbl_status.Text = HardCodedValues.BuddaResource.ItemRemovalError;
     }
 }
        protected void ItemBtn_Click(object sender, EventArgs e)
        {
            bool resFU = checkPhoto(itemImageFU);
            if (resFU)
            {
                try
                {

                    BusinessEntitiesBS.ItemEntities.ItemObj itemValues = new BusinessEntitiesBS.ItemEntities.ItemObj();

                    itemValues.itemName = ItemTxt.Text;
                    itemValues.itemDesc = descTxt.InnerText.ToString();
                    itemValues.itemCatagory = Int32.Parse(CatagoryDDL.SelectedValue);

                    itemValues.itemImagePath = itemImageFU.FileName.ToString();

                    itemValues.itemQty = Int32.Parse(qtyTxt.Text);
                    itemValues.itemBR = float.Parse(brateTxt.Text);
                    itemValues.itemNR = float.Parse(netRateTxt.Text);
                    itemValues.itemStatus = CheckBoxSts.Checked;
                    itemValues.itemType = typeTxt.Text;
                    itemValues.itemSubCatId = Int32.Parse(SubCatagoryDDL.SelectedValue);
                    itemValues.merchantId = Int32.Parse(MerchantDDL.SelectedValue);

                    IAdmin insertItem = new AdminItems();
                    int itemId = insertItem.insertItems(itemValues);
                    if (itemId != -1)
                    {
                        //create folder for item images and save images. show result
                        string NewDir = Server.MapPath("~/ItemImages/" + Int32.Parse(CatagoryDDL.SelectedValue) + "/" + itemId);
                        try
                        {
                            // Check if directory exists
                            if (!Directory.Exists(NewDir))
                            {
                                // Create the directory.
                                Directory.CreateDirectory(NewDir);

                            }
                        }
                        catch (IOException _ex)
                        {
                            ItemMessageLbl.Text = HardCodedValues.BuddaResource.CatchBlockError + _ex.Message;
                        }

                        //string filename = Path.GetFileName(PhotoFU.FileName);
                        string filename = itemId + "Photo.jpg";
                        itemImageFU.SaveAs(Server.MapPath("~/ItemImages/" + Int32.Parse(CatagoryDDL.SelectedValue) + "/" + itemId + "/") + filename);

                        string filePath = Server.MapPath("~/ItemImages/" + Int32.Parse(CatagoryDDL.SelectedValue) + "/" + itemId + "/") + filename;
                        string newfileMed = itemId + "Photomedium.jpg";
                        string newfileSmall = itemId + "small.jpg";
                        string resizedImageMed = Server.MapPath("~/ItemImages/" + Int32.Parse(CatagoryDDL.SelectedValue) + "/" + itemId + "/") + newfileMed;
                        string resizedImageSmall = Server.MapPath("~/ItemImages/" + Int32.Parse(CatagoryDDL.SelectedValue) + "/" + itemId + "/") + newfileSmall;
                        System.Drawing.Image img = System.Drawing.Image.FromFile(filePath);

                        System.Drawing.Bitmap bmpD = img as Bitmap;

                        Bitmap bmpDriverMed = new Bitmap(bmpD, 500, 500);
                        bmpDriverMed.Save(resizedImageMed, System.Drawing.Imaging.ImageFormat.Jpeg);

                        Bitmap bmpDriverSmall = new Bitmap(bmpD, 150, 150);
                        bmpDriverSmall.Save(resizedImageSmall, System.Drawing.Imaging.ImageFormat.Jpeg);

                        ItemMessageLbl.Text = HardCodedValues.BuddaResource.ItemAdd;

                    }
                    else
                    {
                        ItemMessageLbl.Text = HardCodedValues.BuddaResource.AddItemFail;
                    }
                    ClearCache();

                }
                catch (Exception iExp)
                {
                    ItemMessageLbl.Text = HardCodedValues.BuddaResource.CatchBlockError + iExp.Message;
                }

            }
        }
        protected void itemGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int itemid = Convert.ToInt32(itemGrid.DataKeys[e.RowIndex].Value.ToString());
            TextBox itemname=(TextBox)itemGrid.Rows[e.RowIndex].FindControl("txt_iname");
            TextBox description=(TextBox)itemGrid.Rows[e.RowIndex].FindControl("txt_editidescr");
            FileUpload fu_itemimage = (FileUpload)itemGrid.Rows[e.RowIndex].FindControl("fu_iimage");
            TextBox catagoryid=(TextBox)itemGrid.Rows[e.RowIndex].FindControl("txt_cid");
            TextBox billedrate=(TextBox)itemGrid.Rows[e.RowIndex].FindControl("txt_billedrate");
            TextBox quantity = (TextBox)itemGrid.Rows[e.RowIndex].FindControl("txt_qty");
            TextBox netrate = (TextBox)itemGrid.Rows[e.RowIndex].FindControl("txt_netrate");
            CheckBox cb_actvsts = (CheckBox)itemGrid.Rows[e.RowIndex].FindControl("cb_actvstsedit");
            CheckBox cb_featuredflag = (CheckBox)itemGrid.Rows[e.RowIndex].FindControl("cb_fflagedit");
            TextBox txt_itemtype = (TextBox)itemGrid.Rows[e.RowIndex].FindControl("txt_type");
            DropDownList ddl_SubCatId = (DropDownList)itemGrid.Rows[e.RowIndex].FindControl("ddl_subcatid");
            DropDownList ddl_merchantId = (DropDownList)itemGrid.Rows[e.RowIndex].FindControl("ddl_merchantId");

            //check whether the image is valid or not
            bool isImageValid = checkPhoto(fu_itemimage,Int32.Parse(catagoryid.Text),itemid);
            if (isImageValid)
            {
                //save updated values in database
                BusinessEntitiesBS.ItemEntities.ItemObj UpdateItemObj = new BusinessEntitiesBS.ItemEntities.ItemObj();
                UpdateItemObj.itemName = itemname.Text;
                UpdateItemObj.itemDesc = description.Text;
                UpdateItemObj.itemCatagory = Int32.Parse(catagoryid.Text);
                UpdateItemObj.itemBR = float.Parse(billedrate.Text);
                UpdateItemObj.itemQty = Int32.Parse(quantity.Text);
                UpdateItemObj.itemNR = float.Parse(netrate.Text);
                UpdateItemObj.itemStatus = cb_actvsts.Checked;
                UpdateItemObj.featuredFlag = cb_featuredflag.Checked;
                UpdateItemObj.itemType = txt_itemtype.Text;
                UpdateItemObj.itemSubCatId = Int32.Parse(ddl_SubCatId.SelectedValue);
                UpdateItemObj.merchantId = Int32.Parse(ddl_merchantId.SelectedValue);

                IAdmin UpdateItems = new AdminItems();
                int updated = UpdateItems.UpdateItems(UpdateItemObj, itemid);
                if (updated != -1)
                {
                    lbl_status.Text = HardCodedValues.BuddaResource.UpdateSuccess;
                    ClearCache();
                    itemGrid.EditIndex = -1;
                    int grpCatId = Int32.Parse(ddl_catagory.SelectedValue.ToString());
                    if (txt_itemname.Text == "")
                    {
                        getItems(grpCatId);
                    }
                    else
                    {
                        searchDT(txt_itemname.Text, grpCatId);
                    }
                }
                else
                {
                    lbl_status.Text = HardCodedValues.BuddaResource.UpdateFail;
                }
            }
            else
            {
                lbl_status.Text = HardCodedValues.BuddaResource.ImageError;
            }
        }
 private void searchDT(string uname)
 {
     try
     {
         IAdmin searchusername = new AdminItems();
         DataTable searchuserDT = searchusername.SearchUsers(uname);
         if (searchuserDT != null)
         {
             userGrid.DataSource = searchuserDT;
             userGrid.DataBind();
             lbl_status.Text = "";
         }
         else
         {
             lbl_status.Text = HardCodedValues.BuddaResource.UserNull;
             userGrid.DataSource = null;
             userGrid.DataBind();
         }
     }
     catch (Exception iExp)
     {
         lbl_status.Text = HardCodedValues.BuddaResource.CatchBlockError+ iExp.Message;
     }
 }
 private void getItems(int grpCatId)
 {
     try
     {
         IAdmin getItems = new AdminItems();
         DataTable itemDT = getItems.getItems(grpCatId);
         if (itemDT != null)
         {
             itemGrid.DataSource = itemDT;
             itemGrid.DataBind();
         }
         else
         {
             lbl_status.Text = HardCodedValues.BuddaResource.ItemsNull;
             itemGrid.DataSource = null;
             itemGrid.DataBind();
         }
     }
     catch (Exception iExp)
     {
         lbl_status.Text = HardCodedValues.BuddaResource.CatchBlockError + iExp.Message;
     }
 }
        protected void getcatgs()
        {
            try
            {
                IAdmin getCats = new AdminItems();
                DataTable catgDt = getCats.getCatagories();

                CatagoryDDL.DataSource = catgDt;
                CatagoryDDL.DataTextField = "CategoryName";
                CatagoryDDL.DataValueField = "CategoryId";
                CatagoryDDL.DataBind();

                grpCatDDL.DataSource = catgDt;
                grpCatDDL.DataTextField = "CategoryName";
                grpCatDDL.DataValueField = "CategoryId";
                grpCatDDL.DataBind();

            }
            catch (Exception cExp)
            {
                ItemMessageLbl.Text = "Error occured" + cExp.Message;
            }
        }
 private DataTable getSubCatg()
 {
     try
     {
         IAdmin checkSubCatName = new AdminItems();
         DataTable dt = checkSubCatName.checkSubCatName(string.Empty, Int32.Parse(ddl_catagory.SelectedValue));
         return dt;
     }
     catch (Exception ex)
     {
         lbl_status.Text = HardCodedValues.BuddaResource.CatchBlockError + ex.Message;
         return null;
     }
 }
        private void getcatgs()
        {
            try
            {
                IAdmin getCats = new AdminItems();
                DataTable catgDt = getCats.getCatagories();

                CatagoryDDL.DataSource = catgDt;
                CatagoryDDL.DataTextField = "CategoryName";
                CatagoryDDL.DataValueField = "CategoryId";
                CatagoryDDL.DataBind();

                grpCatDDL.DataSource = catgDt;
                grpCatDDL.DataTextField = "CategoryName";
                grpCatDDL.DataValueField = "CategoryId";
                grpCatDDL.DataBind();

                ddl_Catagory.DataSource = catgDt;
                ddl_Catagory.DataTextField = "CategoryName";
                ddl_Catagory.DataValueField = "CategoryId";
                ddl_Catagory.DataBind();

                ddlCatagoryMer.DataSource = catgDt;
                ddlCatagoryMer.DataTextField = "CategoryName";
                ddlCatagoryMer.DataValueField = "CategoryId";
                ddlCatagoryMer.DataBind();
            }
            catch (Exception cExp)
            {
                ItemMessageLbl.Text = HardCodedValues.BuddaResource.CatchBlockError + cExp.Message;
            }
        }
 protected void txt_SubCatName_TextChanged(object sender, EventArgs e)
 {
     try
     {
         IAdmin checkSubCatName = new AdminItems();
         DataTable dt = checkSubCatName.checkSubCatName(txt_SubCatName.Text, Int32.Parse(ddl_Catagory.SelectedValue));
         if (dt != null)
         {
             img_SubCatName.ImageUrl = "~/images/unavailable.png";
             img_SubCatName.Visible = true;
             lbl_SubCatName.Text = "Name already Exist";
             lbl_SubCatName.ForeColor = System.Drawing.Color.Red;
             txt_SubCatName.Focus();
         }
         else
         {
             img_SubCatName.ImageUrl = "~/images/tick.png";
             img_SubCatName.Visible = true;
             lbl_SubCatName.Text = "Not Exist in DB";
             lbl_SubCatName.ForeColor = System.Drawing.Color.Green;
         }
     }
     catch (Exception ex)
     {
         lbl_SubCatName.Text = HardCodedValues.BuddaResource.CatchBlockError + ex.Message;
     }
 }
        protected void grpSubmitBtn_Click(object sender, EventArgs e)
        {
            bool flagItem;

            DataTable grpItemsDt = new DataTable();
            DataColumn dc = new DataColumn("GrpItem", typeof(int));
            grpItemsDt.Columns.Add(dc);

            foreach (GridViewRow dRow in itemGrid.Rows)
            {

             flagItem = (dRow.FindControl("itemChkBox") as CheckBox).Checked;

                if (flagItem)
                 {
                     int itemId = Convert.ToInt32(itemGrid.DataKeys[dRow.RowIndex].Value);

                     DataRow dr = grpItemsDt.NewRow();
                     dr[0] = itemId;

                     grpItemsDt.Rows.Add(dr);

                 }

            }

            string grpItemString = "";
            bool first = true;
            if (grpItemsDt.Rows.Count > 0)
            {
                foreach (DataRow iRow in grpItemsDt.Rows)
                {
                    if (first)
                    {
                        grpItemString += int.Parse(iRow["GrpItem"].ToString());
                        first = false;
                    }
                    else
                    {
                        grpItemString += "," + int.Parse(iRow["GrpItem"].ToString());
                    }

                }

                BusinessEntitiesBS.GroupEntities.grpObj grpValus = new BusinessEntitiesBS.GroupEntities.grpObj();

                grpValus.grpName = grpNameTxt.Text.ToString();
                grpValus.grpDesc = grpDescTxt.Text.ToString();
                grpValus.grpBR =  float.Parse(grpBrTxt.Text.ToString());
                grpValus.grpNR = float.Parse(grpNrTxt.Text.ToString());
                grpValus.grpStatus = grpCb.Checked;
                grpValus.fixedGrp = grpStatusCb.Checked;
                grpValus.Quantity = Int32.Parse(grpQtyTxt.Text.ToString());
                //item string
                grpValus.itemIdStr = grpItemString;

                IAdmin insertGroup = new AdminItems();
                int grpId = insertGroup.insertGroup(grpValus);
                if (grpId != -1)
                {
                    grpMsgLbl.Text = "Group Inserted";
                }
                else
                {
                    grpMsgLbl.Text = "Error Occured! Group not inserted";
                }
            }
            else
            {
                grpMsgLbl.Text = "Select items for the group";
            }
        }