protected void gvProductCategory_RowEditing(object sender, GridViewEditEventArgs e)
        {
            try
            {
                int productCategoryID = (int)gvProductCategory.DataKeys[e.NewEditIndex].Value;

                FBFoodInventoryController controller = new FBFoodInventoryController();
                FBFoodInventoryInfo       item       = controller.FBProductCategory_GetByID(this.ModuleId, productCategoryID);

                if (item != null)
                {
                    panelGrid.Visible = false;
                    panelEdit.Visible = true;

                    txtProductCategory.Text    = item.ProductCategory.ToString();
                    txtProductCategoryID.Value = item.ProductCategoryID.ToString();
                    rblIsActive.SelectedValue  = item.IsActive.ToString();
                }
                else
                {
                    txtProductCategoryID.Value = "";
                }


                e.Cancel = true;
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        protected void cmdUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                FBFoodInventoryController controller = new FBFoodInventoryController();
                FBFoodInventoryInfo       item       = new FBFoodInventoryInfo();

                item.SupplierName    = txtContent.Text;
                item.SupplierID      = itemId;
                item.ModuleId        = this.ModuleId;
                item.CreatedByUserID = this.UserId;

                //determine if we are adding or updating
                if (Null.IsNull(item.SupplierID))
                {
                    controller.FBSuppliers_Insert(item);
                }
                else
                {
                    controller.FBSuppliers_Update(item);
                }

                Response.Redirect(Globals.NavigateURL(), true);
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        protected void AddNewLineItem(object sender, EventArgs e)
        {
            try
            {
                lblFormMessage.Visible = false;

                FBFoodInventoryController controller = new FBFoodInventoryController();
                FBFoodInventoryInfo       item       = new FBFoodInventoryInfo();

                item.ModuleId = this.ModuleId;
                item.PortalId = this.PortalId;

                item.InvoiceID = Int32.Parse(txtInvoiceID.Value.ToString());

                item.ProductID = Int32.Parse(ddlProducts.SelectedValue.ToString());

                item.Cases                = Int32.Parse(txtCasesAddNewEdit.Text.ToString());
                item.CountPerCase         = Int32.Parse(txtCountPerCaseAddNewEdit.Text.ToString());
                item.WeightPerCase        = double.Parse(txtWeightPerCaseAddNewEdit.Text.ToString());
                item.PricePerCase         = Convert.ToDouble(txtPricePerCaseAddNewEdit.Text.ToString());
                item.ReportType           = ddlReportType.SelectedValue.ToString();
                item.LastModifiedByUserID = this.UserId;

                if (txtLineItemID_Edit.Value.Length > 0)
                {
                    item.LineItemID = Int32.Parse(txtLineItemID_Edit.Value.ToString());
                    controller.FBLineItems_Update(item);
                }
                else
                {
                    controller.FBLineItems_Insert(item);
                }
                GroupIt();
                GetLineItems(Int32.Parse(txtInvoiceID.Value.ToString()));

                btnAdd.Text                     = "Add New Item";
                txtCasesAddNewEdit.Text         = "";
                txtCountPerCaseAddNewEdit.Text  = "";
                txtPricePerCaseAddNewEdit.Text  = "";
                ddlProducts.SelectedValue       = "0";
                txtWeightPerCaseAddNewEdit.Text = "";
                ddlReportType.SelectedValue     = "";

                txtLineItemID_Edit.Value        = "";
                ddlFilterCategory.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                FBFoodInventoryController controller = new FBFoodInventoryController();
                FBFoodInventoryInfo       item       = new FBFoodInventoryInfo();


                item.ModuleId = this.ModuleId;
                item.PortalId = this.PortalId;

                item.InvoiceNumber = txtInvoiceNumber.Text.ToString();

                item.SupplierID = Int32.Parse(ddlSupplier.SelectedValue.ToString());

                item.InvoiceDate = Convert.ToDateTime(txtInvoiceDate.Text.ToString());

                item.Organization = ddlOrganization.SelectedValue.ToString();

                item.LastModifiedByUserID = this.UserId;



                if (txtInvoiceID.Value.Length > 0)
                {
                    item.InvoiceID = Int32.Parse(txtInvoiceID.Value.ToString());
                    controller.FBInvoice_Update(item);

                    lblFormMessage.Text    = Localization.GetString("InvoiceUpdateSuccessful", this.LocalResourceFile);
                    lblFormMessage.Visible = true;
                }
                else
                {
                    item.CreatedByUserID = this.UserId;


                    int MyNewID = Null.NullInteger;
                    MyNewID            = controller.FBInvoice_Insert(item);
                    txtInvoiceID.Value = Convert.ToString(MyNewID);

                    lblFormMessage.Text    = Localization.GetString("InvoiceInsertSuccessful", this.LocalResourceFile);
                    lblFormMessage.Visible = true;
                }

                panelAddLineItems.Visible = true;
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                // get the ID of the clicked row

                int ID = Convert.ToInt32(e.CommandArgument);
                // Delete the record

                FBFoodInventoryController controller = new FBFoodInventoryController();
                controller.FBLineItems_Delete(ID);
                //  DeleteRecordByID(ID);
                // Implement this on your own :)
            }


            if (e.CommandName == "Edit")
            {
                int ID = Convert.ToInt32(e.CommandArgument);

                FBFoodInventoryController controller = new FBFoodInventoryController();
                FBFoodInventoryInfo       item       = controller.FBLineItems_GetByID(ID);

                if (item != null)
                {
                    txtLineItemID_Edit.Value        = item.LineItemID.ToString();
                    txtCasesAddNewEdit.Text         = item.Cases.ToString();
                    txtCountPerCaseAddNewEdit.Text  = item.CountPerCase.ToString();
                    txtWeightPerCaseAddNewEdit.Text = item.WeightPerCase.ToString();
                    txtPricePerCaseAddNewEdit.Text  = item.PricePerCase.ToString();
                    ddlProducts.SelectedValue       = item.ProductID.ToString();
                    if (item.ReportType != null)
                    {
                        ddlReportType.SelectedValue = item.ReportType.ToString();
                    }


                    btnAdd.Text = "Update Item";
                }
                else
                {
                    txtLineItemID_Edit.Value = "0";
                }
            }


            GroupIt();
            GetLineItems(Int32.Parse(txtInvoiceID.Value.ToString()));
        }
        protected void gvProducts_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName == "Delete")
                {
                    // get the ID of the clicked row
                    int ID = Convert.ToInt32(e.CommandArgument);

                    FBFoodInventoryController controller = new FBFoodInventoryController();
                    // Delete the record
                    controller.FBProducts_Delete(ID);

                    FillProductsGrid();
                }


                if (e.CommandName == "Edit")
                {
                    int ID = Convert.ToInt32(e.CommandArgument);


                    FBFoodInventoryController controller = new FBFoodInventoryController();
                    FBFoodInventoryInfo       item       = controller.FBProducts_GetByID(this.ModuleId, ID);

                    if (item != null)
                    {
                        panelGrid.Visible   = false;
                        panelEdit.Visible   = true;
                        txtProductName.Text = item.ProductName.ToString();
                        txtCasePrice.Text   = string.Format("{0:0.00}", item.CasePrice.ToString());
                        //txtCasePrice.Text = item.CasePrice.ToString();
                        txtCaseCount.Text = item.CaseCount.ToString();
                        ddlProductCategory.SelectedValue = item.ProductCategoryID.ToString();
                        txtCaseWeight.Text        = item.CaseWeight.ToString();
                        rblIsActive.SelectedValue = item.IsActive.ToString();
                        txtProductID.Value        = item.ProductID.ToString();
                    }
                    else
                    {
                        txtProductID.Value = "";
                    }
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Request.QueryString["ItemId"] != null)
                {
                    itemId = Int32.Parse(Request.QueryString["ItemId"]);
                }

                if (!IsPostBack)
                {
                    //load the data into the control the first time
                    //we hit this page


                    cmdDelete.Attributes.Add("onClick", "javascript:return confirm('" + Localization.GetString("DeleteItem") + "');");

                    //check we have an item to lookup
                    if (!Null.IsNull(itemId))
                    {
                        //load the item
                        FBFoodInventoryController controller = new FBFoodInventoryController();
                        FBFoodInventoryInfo       item       = controller.FBSuppliers_GetByID(this.ModuleId, itemId);

                        if (item != null)
                        {
                            txtContent.Text        = item.SupplierName;
                            ctlAudit.CreatedByUser = item.CreatedByUserName;
                            ctlAudit.CreatedDate   = item.CreatedOnDate.ToLongDateString();
                        }
                        else
                        {
                            Response.Redirect(Globals.NavigateURL(), true);
                        }
                    }
                    else
                    {
                        cmdDelete.Visible = false;
                        ctlAudit.Visible  = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                FBFoodInventoryController controller = new FBFoodInventoryController();
                FBFoodInventoryInfo       item       = new FBFoodInventoryInfo();


                item.ModuleId = this.ModuleId;
                item.PortalId = this.PortalId;

                item.ProductName = txtProductName.Text.ToString();

                item.CaseWeight        = double.Parse(txtCaseWeight.Text.ToString());
                item.CasePrice         = double.Parse(txtCasePrice.Text.ToString());
                item.CaseCount         = Int32.Parse(txtCaseCount.Text.ToString());
                item.ProductCategoryID = Int32.Parse(ddlProductCategory.SelectedValue.ToString());

                item.LastModifiedByUserID = this.UserId;
                item.IsActive             = bool.Parse(rblIsActive.SelectedValue.ToString());


                if (txtProductID.Value.Length > 0)
                {
                    item.ProductID = Int32.Parse(txtProductID.Value.ToString());
                    controller.FBProducts_Update(item);
                }
                else
                {
                    item.CreatedByUserID = this.UserId;
                    controller.FBProducts_Insert(item);
                }


                //Response.Redirect(EditUrl("Products"));
                ResetForm();
                FillProductsGrid();
                panelGrid.Visible = true;
                panelEdit.Visible = false;
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                FBFoodInventoryController controller = new FBFoodInventoryController();
                FBFoodInventoryInfo       item       = new FBFoodInventoryInfo();


                item.ModuleId = this.ModuleId;
                item.PortalId = this.PortalId;

                item.SupplierName = txtSupplierName.Text.ToString();
                //     item.GBFB = Convert.ToBoolean(cbxGBFB.Checked);
                item.Address              = txtAddress.Text.ToString();
                item.City                 = txtCity.Text.ToString();
                item.State                = ddlState.SelectedValue.ToString();
                item.Zip                  = txtZip.Text.ToString();
                item.SupplierPhone        = txtSupplierPhone.Text.ToString();
                item.Salesman             = txtSalesman.Text.ToString();
                item.SalesmanPhone        = txtSalesmanPhone.Text.ToString();
                item.LastModifiedByUserID = this.UserId;

                item.IsActive = Convert.ToBoolean(rblIsActive.SelectedValue.ToString());

                if (txtSupplierID.Value.Length > 0)
                {
                    item.SupplierID = Int32.Parse(txtSupplierID.Value.ToString());
                    controller.FBSuppliers_Update(item);
                }
                else
                {
                    item.CreatedByUserID = this.UserId;
                    controller.FBSuppliers_Insert(item);
                }


                Response.Redirect(EditUrl("Suppliers"));
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        protected void ddlProducts_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                int productID = Int32.Parse(ddlProducts.SelectedValue.ToString());

                FBFoodInventoryController controller = new FBFoodInventoryController();
                FBFoodInventoryInfo       item       = controller.FBProducts_GetByID(this.ModuleId, productID);

                if (item != null)
                {
                    txtPricePerCaseAddNewEdit.Text  = item.CasePrice.ToString();
                    txtCountPerCaseAddNewEdit.Text  = item.CaseCount.ToString();
                    txtWeightPerCaseAddNewEdit.Text = item.CaseWeight.ToString();
                }
                txtCasesAddNewEdit.Focus();
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        protected void gvSuppliers_RowEditing(object sender, GridViewEditEventArgs e)
        {
            try
            {
                //   cmdDeleteDonation.Attributes.Add("onClick", "javascript:return confirm('" + Localization.GetString("DeleteDonationItemMessage.Confirm", this.LocalResourceFile) + "');");

                panelEdit.Visible = true;
                panelGrid.Visible = false;

                int supplierID = (int)gvSuppliers.DataKeys[e.NewEditIndex].Value;

                FBFoodInventoryController controller = new FBFoodInventoryController();
                FBFoodInventoryInfo       item       = controller.FBSuppliers_GetByID(this.ModuleId, supplierID);

                if (item != null)
                {
                    txtSupplierName.Text = item.SupplierName.ToString();
                    //   cbxGBFB.Checked = item.GBFB;
                    txtAddress.Text           = item.Address.ToString();
                    txtCity.Text              = item.City.ToString();
                    ddlState.SelectedValue    = item.State.ToString();
                    txtZip.Text               = item.Zip.ToString();
                    txtSupplierPhone.Text     = item.SupplierPhone.ToString();
                    txtSalesman.Text          = item.Salesman.ToString();
                    txtSalesmanPhone.Text     = item.SalesmanPhone.ToString();
                    rblIsActive.SelectedValue = item.IsActive.ToString();
                    txtSupplierID.Value       = item.SupplierID.ToString();
                }
                else
                {
                    txtSupplierID.Value = "";
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        public void AddInActiveSupplier(int SupplierID)
        {
            try
            {
                FBFoodInventoryController controller = new FBFoodInventoryController();
                FBFoodInventoryInfo       item       = controller.FBSuppliers_GetByID(this.ModuleId, SupplierID);

                if (item != null)
                {
                    ListItem lst = new ListItem(item.SupplierName.ToString(), SupplierID.ToString());

                    ddlSupplier.Items.Add(lst);
                    ddlSupplier.SelectedValue = SupplierID.ToString();
                }
                else
                {
                    //  txtSupplierID.Value = "";
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        protected void gvInvoices_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName == "Delete")
                {
                    // get the ID of the clicked row

                    int ID = Convert.ToInt32(e.CommandArgument);
                    // Delete the record

                    FBFoodInventoryController controller = new FBFoodInventoryController();
                    controller.FBInvoice_Delete(ID);
                    //  DeleteRecordByID(ID);
                    // Implement this on your own :)

                    txtInvoiceID.Value = "0";

                    FillInvoiceGrid();
                }


                if (e.CommandName == "Edit")
                {
                    int ID = Convert.ToInt32(e.CommandArgument);

                    //  int invoiceID = (int)gvInvoices.DataKeys[e.NewEditIndex].Value;

                    FBFoodInventoryController controller = new FBFoodInventoryController();
                    FBFoodInventoryInfo       item       = controller.FBInvoice_GetByID(this.ModuleId, ID);

                    if (item != null)
                    {
                        panelAddLineItems.Visible = true;
                        FillSupplierDropDown();
                        FillReportTypeDropDown();
                        btnSave.Text                  = "Update Record";
                        panelGrid.Visible             = false;
                        panelEdit.Visible             = true;
                        txtInvoiceNumber.Text         = item.InvoiceNumber.ToString();
                        txtInvoiceDate.Text           = item.InvoiceDate.ToShortDateString();
                        ddlOrganization.SelectedValue = item.Organization.ToString();
                        ListItem lstitem = ddlSupplier.Items.FindByValue(item.SupplierID.ToString());
                        if (lstitem != null)
                        {
                            ddlSupplier.SelectedValue = item.SupplierID.ToString();
                        }
                        else
                        {
                            AddInActiveSupplier(item.SupplierID);
                        }


                        txtInvoiceID.Value = item.InvoiceID.ToString();
                        //GroupIt();
                        //GetLineItems(item.InvoiceID);
                        GroupIt();
                        GetLineItems(Int32.Parse(txtInvoiceID.Value.ToString()));
                    }
                    else
                    {
                        txtInvoiceID.Value = "0";
                    }
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }