private void RefreshBatchList()
 {
     try
     {
         _batchcollection = new AutoCompleteStringCollection();
         if (m_LocationID > 0 && m_ItemID > 0)
         {
             string               errorMessage = string.Empty;
             CIBatchDetail        batch        = new CIBatchDetail();
             List <CIBatchDetail> Lists        = batch.GetBatchDetail(string.Empty, m_ItemID, m_LocationID, ref errorMessage);
             if (Lists != null)
             {
                 for (int j = 0; j < Lists.Count; j++)
                 {
                     _batchcollection.Add(Lists[j].BatchNo);
                 }
             }
         }
         txtBatchNo.AutoCompleteMode         = AutoCompleteMode.SuggestAppend;
         txtBatchNo.AutoCompleteSource       = AutoCompleteSource.CustomSource;
         txtBatchNo.AutoCompleteCustomSource = _batchcollection;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 private void ResetForm()
 {
     try
     {
         m_Order = new CO();
         m_Order.GetCOAllDetails(OrderNo, (int)Common.OrderStatus.Confirmed);
         if (m_Order != null && !string.IsNullOrEmpty(m_Order.CustomerOrderNo))
         {
             CODetailList = m_Order.CODetailList;
             dgvCOItemDetails.DataSource = CODetailList;
             SetHeaderValue();
             //RefreshItemList();
             // Get Grid View data
             string errorMessage = string.Empty;
             ListBatch = CIBatchDetail.GetDefaultBatch(OrderNo, m_LocationID, ref errorMessage);
             SetGridView();
             dgvCOItemDetails.ClearSelection();
             dgvInvoiceDetail.ClearSelection();
         }
         else
         {
             // Co Detail not Found
             ErrorCode = "40009";
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 private void AddBatch()
 {
     try
     {
         bool toadd = true;
         var  q1    = from q in ListBatch where q.ItemId == m_CurrentBatch.ItemId && q.RecordNo == m_CurrentBatch.RecordNo && q.BatchNo == txtBatchNo.Text.Trim() select q;
         if (q1 != null && q1.ToList().Count > 0)
         {
             m_CurrentBatch = (CIBatchDetail)q1.ToList()[0];
             toadd          = false;
         }
         m_CurrentBatch.CreatedBy = m_UserID;
         m_CurrentBatch.Quantity  = Convert.ToDecimal(txtInvoiceQty.Text.Trim());
         if (toadd)
         {
             ListBatch.Add(m_CurrentBatch);
         }
         SetGridView();
         ClearDetails();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 private decimal GetAvailableQty(CIBatchDetail batch)
 {
     if (batch.AvailableQty > 0)
     {
         decimal usedQty = 0;
         var     query   = from q in ListBatch where q.ItemId == m_CurrentBatch.ItemId && q.RecordNo != m_CurrentBatch.RecordNo select q.Quantity;
         if (query != null && query.ToList().Count > 0)
         {
             usedQty = query.Sum();
         }
         batch.AvailableQty = batch.AvailableQty; //- usedQty;
     }
     return(batch.AvailableQty);
 }
 private CIBatchDetail CreateBatchObject(CODetail ODetail)
 {
     try
     {
         CIBatchDetail batch = new CIBatchDetail();
         batch.ItemCode      = ODetail.ItemCode;
         batch.ItemId        = ODetail.ItemId;
         batch.TotalQuantity = ODetail.Qty;
         return(batch);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        private void txtBatchNo_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                // m_ItemID = m_CurrentBatch.ItemId;
                m_CurrentBatch = new CIBatchDetail();

                string errorMessage = string.Empty;
                if (txtBatchNo.Text.Trim().Equals(string.Empty))
                {
                    return;
                }
                List <CIBatchDetail> List = m_CurrentBatch.GetBatchDetail(txtBatchNo.Text.Trim(), m_ItemID, m_LocationID, ref errorMessage);
                if (List != null && List.Count > 0 && errorMessage.Trim().Equals(string.Empty))
                {
                    m_CurrentBatch               = List[0];
                    m_CurrentBatch.ItemId        = m_ItemID;
                    m_CurrentBatch.ItemCode      = m_itemCode;
                    m_CurrentBatch.RecordNo      = m_Recordno;
                    m_CurrentBatch.TotalQuantity = m_TotalQty;
                    m_CurrentBatch.AvailableQty  = GetAvailableQty(m_CurrentBatch);
                }
                else
                {
                    m_CurrentBatch.BatchNo = txtBatchNo.Text.Trim();
                }

                // m_CurrentBatch.ItemCode = txtItemCode.Text.Trim();
                m_CurrentBatch.Quantity = txtInvoiceQty.Text.Trim() == string.Empty?0:Convert.ToDecimal(txtInvoiceQty.Text.Trim());
                SetBatchDetails();
            }
            catch (Exception ex)
            {
                MessageBox.Show(Common.GetMessage("10002"), Common.GetMessage("30007"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                Common.LogException(ex);
            }
        }