private void InitailizeControls()
        {
            try
            {
                // Create GridView
                dgvBatchDetails.AutoGenerateColumns = false;
                dgvBatchDetails.DataSource          = null;
                DataGridView dgvItemsNew = Common.GetDataGridViewColumns(dgvBatchDetails, GRIDVIEW_XML_PATH);

                dgvBatchDetails.AutoGenerateColumns = false;

                dgvBatchDetails.DataSource = null;


                CoreComponent.MasterData.BusinessObjects.ItemDetails itemDetail = new CoreComponent.MasterData.BusinessObjects.ItemDetails();
                ItemDetails objnew = new ItemDetails();
                //itemDetail.ItemId = objnew.ToItemId;
                itemDetail.ItemCode = Itemcode.ToUpper();
                List <CoreComponent.MasterData.BusinessObjects.ItemDetails> items = itemDetail.Search();
                List <CoreComponent.MasterData.BusinessObjects.ItemDetails> lstItem;
                if (items != null && items.Count > 0)
                {
                    var query = from a in items where a.ItemCode.ToUpper() == Itemcode.ToUpper() select a;
                    lstItem = (List <CoreComponent.MasterData.BusinessObjects.ItemDetails>)query.ToList();
                    if (lstItem.Count > 0)
                    {
                        m_expiryMonth = lstItem[0].ExpiryDuration;
                    }
                }

                dtpExpiryDate.Value = DateTime.Today.AddMonths(m_expiryMonth);
                if (ItemInventory.BatchDetailList != null && ItemInventory.BatchDetailList.Count > 0)
                {
                    var query = (from p in ItemInventory.BatchDetailList select p.SerialNo).Max();
                    m_SerialNo = Convert.ToInt32(query) + 1;
                }
                else
                {
                    m_SerialNo++;
                }



                if (ItemInventory.BatchDetailList == null || ItemInventory.BatchDetailList.Count == 0)
                {
                    dgvBatchDetails.AutoGenerateColumns = false;
                    dgvBatchDetails.DataSource          = null;
                    dgvBatchDetails.DataSource          = new List <ItemBatchDetails>();
                }
                ResetGrid();

                btnAdd.Enabled          = EnableControl;
                txtManuBatchNo.ReadOnly = !EnableControl;
                dtpExpiryDate.Enabled   = EnableControl;
                dtpMfgDate.Enabled      = EnableControl;
                dgvBatchDetails.Columns[CON_GRID_Remove].Visible = EnableControl;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void dgvBatchDetails_SelectionChanged(object sender, EventArgs e)
        {
            try
            {
                if (dgvBatchDetails.SelectedRows.Count > 0)
                {
                    errorAdd.Clear();
                    if (ItemInventory.BatchDetailList != null && ItemInventory.BatchDetailList.Count > 0)
                    {
                        var query = from a in ItemInventory.BatchDetailList where a.ToItemCode.ToUpper() == Itemcode.ToUpper() select a;
                        List <CoreComponent.MasterData.BusinessObjects.ItemBatchDetails> lstItem;
                        lstItem = (List <CoreComponent.MasterData.BusinessObjects.ItemBatchDetails>)query.ToList();

                        foreach (ItemBatchDetails cn in lstItem)
                        {
                            CurrentSerialno = cn.SerialNo;
                            int s = cn.SerialNo;

                            m_CurrentBatch = ItemInventory.BatchDetailList[0];
                        }
                        ItemBatchDetails batch = CopyObject(m_CurrentBatch);

                        ResetValues(batch);
                        //m_returnObject = dgvBatchDetails.SelectedRows[0].DataBoundItem;
                        //DialogResult = DialogResult.OK;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Common.GetMessage("10002"), Common.GetMessage("30007"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                Common.LogException(ex);
            }
        }
        private void EditItem()
        {
            try
            {
                ValidateEdit();
                StringBuilder sbError;
                sbError = GenerateAddError();
                if (sbError.ToString().Trim().Equals(string.Empty))
                {
                    DialogResult saveResult = MessageBox.Show(Common.GetMessage("5010", "Edit"), Common.GetMessage("10001"), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (saveResult == DialogResult.Yes)
                    {
                        if (ItemInventory.BatchDetailList != null && ItemInventory.BatchDetailList.Count > 0)
                        {
                            var query = from a in ItemInventory.BatchDetailList where a.ToItemCode.ToUpper() == Itemcode.ToUpper() select a;
                            List <CoreComponent.MasterData.BusinessObjects.ItemBatchDetails> lstItem;
                            lstItem = (List <CoreComponent.MasterData.BusinessObjects.ItemBatchDetails>)query.ToList();
                            //int s = 0;
                            foreach (ItemBatchDetails cn in lstItem)
                            {
                                CurrentSerialno = cn.SerialNo;
                                int s = cn.SerialNo;

                                ItemInventory.BatchDetailList[s].ItemCode           = Itemcode.Trim().ToString();
                                ItemInventory.BatchDetailList[s].ExpDate            = dtpExpiryDate.Value.ToShortDateString();
                                ItemInventory.BatchDetailList[s].MfgDate            = dtpMfgDate.Value.ToShortDateString();
                                ItemInventory.BatchDetailList[s].ManufactureBatchNo = txtManuBatchNo.Text.Trim();
                                ItemInventory.BatchDetailList[s].DisplayExpDate     = dtpExpiryDate.Value.ToString(Common.DTP_DATE_FORMAT);

                                ItemInventory.BatchDetailList[s].DisplayMfgDate = dtpMfgDate.Value.ToString(Common.DTP_DATE_FORMAT);
                            }
                            ResetGrid();
                            //m_ParentGridView.Refresh();
                            ClearItem();
                            MessageBox.Show(Common.GetMessage("INF0055", "Batch", "Updated"), Common.GetMessage("10001"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else
                {
                    MessageBox.Show(sbError.ToString(), Common.GetMessage("30007"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void AddItem()
        {
            try
            {
                ValidateAdd();
                StringBuilder sbError;
                sbError = GenerateAddError();
                if (sbError.ToString().Trim().Equals(string.Empty))
                {
                    DialogResult saveResult = MessageBox.Show(Common.GetMessage("5010", "Add"), Common.GetMessage("10001"), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (saveResult == DialogResult.Yes)
                    {
                        if (ItemInventory.BatchDetailList != null && ItemInventory.BatchDetailList.Count > 0)
                        {
                            var query = from a in ItemInventory.BatchDetailList where a.ToItemCode.ToUpper() == Itemcode.ToUpper() select a;
                            if (query.Count(c => c.ToItemCode == Itemcode) > 0)
                            {
                                MessageBox.Show(Common.GetMessage("INF0227"), Common.GetMessage("10001"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else if (query.Count(c => c.ToItemCode == Itemcode) == 0)
                            {
                                ItemBatchDetails batch = new ItemBatchDetails();
                                batch.ToItemCode         = Itemcode.Trim().ToString();
                                batch.ManufactureBatchNo = txtManuBatchNo.Text.Trim();
                                batch.Expiry             = dtpExpiryDate.Value.ToShortDateString();
                                batch.Manufacure         = dtpMfgDate.Value.ToShortDateString();
                                //batch.DisplayMfgDate = dtpMfgDate.Value.ToString(Common.DTP_DATE_FORMAT);
                                batch.SerialNo = m_SerialNo++;

                                if (ItemInventory.BatchDetailList == null)
                                {
                                    ItemInventory.BatchDetailList = new List <ItemBatchDetails>();
                                }

                                ItemInventory.BatchDetailList.Add(batch);


                                ResetGrid();
                                //m_ParentGridView.Refresh();
                                ClearItem();
                                MessageBox.Show(Common.GetMessage("INF0055", "Batch", "Added"), Common.GetMessage("10001"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }

                        else
                        {
                            ItemBatchDetails batch = new ItemBatchDetails();
                            batch.ToItemCode         = Itemcode.Trim().ToString();
                            batch.ManufactureBatchNo = txtManuBatchNo.Text.Trim();
                            batch.Expiry             = dtpExpiryDate.Value.ToShortDateString();
                            //batch.DisplayExpDate = dtpExpiryDate.Value.ToString(Common.DTP_DATE_FORMAT);
                            //batch.ItemId = m_CurrentGRNDetail.ItemId;
                            batch.Manufacure = dtpMfgDate.Value.ToShortDateString();
                            //batch.DisplayMfgDate = dtpMfgDate.Value.ToString(Common.DTP_DATE_FORMAT);
                            batch.SerialNo = m_SerialNo++;

                            if (ItemInventory.BatchDetailList == null)
                            {
                                ItemInventory.BatchDetailList = new List <ItemBatchDetails>();
                            }

                            ItemInventory.BatchDetailList.Add(batch);


                            ResetGrid();
                            //m_ParentGridView.Refresh();
                            ClearItem();
                            MessageBox.Show(Common.GetMessage("INF0055", "Batch", "Added"), Common.GetMessage("10001"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else
                {
                    MessageBox.Show(sbError.ToString(), Common.GetMessage("30007"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void ResetGrid()
        {
            try
            {
                dgvBatchDetails.DataSource = null;
                //dgvBatchDetails.DataSource = new List<ItemBatchDetails>();
                if (ItemInventory.BatchDetailList != null && ItemInventory.BatchDetailList.Count > 0)
                {
                    var query = from a in ItemInventory.BatchDetailList where a.ToItemCode.ToUpper() == Itemcode.ToUpper() select a;
                    if (query.Count(c => c.ToItemCode == Itemcode) > 0)
                    {
                        List <CoreComponent.MasterData.BusinessObjects.ItemBatchDetails> lstItem;
                        lstItem = (List <CoreComponent.MasterData.BusinessObjects.ItemBatchDetails>)query.ToList();


                        //int s = 0;
                        foreach (ItemBatchDetails cn in lstItem)
                        {
                            CurrentSerialno = cn.SerialNo;
                            if (dgvBatchDetails.Rows.Count == 0)
                            {
                                dgvBatchDetails.Rows.Add();
                            }
                            //int s = cn.SerialNo;
                            //dgvBatchDetails.Rows[0].Cells[0].Value = " X ";
                            dgvBatchDetails.Rows[0].Cells[1].Value = lstItem[0].ManufactureBatchNo;
                            dgvBatchDetails.Rows[0].Cells[2].Value = lstItem[0].DisplayManufacure;
                            dgvBatchDetails.Rows[0].Cells[3].Value = lstItem[0].DisplayExpiry;
                            //s++;
                        }
                    }
                    //else if()
                    //{
                    //foreach (ItemBatchDetails cn in ItemDetail.GRNBatchDetailList)
                    //{
                    //    int s = cn.SerialNo - 1;
                    //    dgvBatchDetails.Rows[s].Cells[1].Value = ItemDetail.GRNBatchDetailList[0].ManufactureBatchNo;
                    //    dgvBatchDetails.Rows[s].Cells[2].Value = ItemDetail.GRNBatchDetailList[0].DisplayMfgDate;
                    //    dgvBatchDetails.Rows[s].Cells[3].Value = ItemDetail.GRNBatchDetailList[0].DisplayExpDate;
                    //}
                    dgvBatchDetails.ClearSelection();
                    m_bindingMgr = (CurrencyManager)this.BindingContext[ItemInventory.BatchDetailList];
                    m_bindingMgr.Refresh();
                }
                dgvBatchDetails.ClearSelection();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }