示例#1
0
 //Jamshi
 //public void SaveFunction()
 //{
 //    try
 //    {
 //        BatchSP spBatch = new BatchSP();
 //        BatchInfo infoBatch = new BatchInfo();
 //        infoBatch.BatchNo = txtBatchName.Text.Trim();
 //        infoBatch.ProductId = Convert.ToDecimal(cmbProduct.SelectedValue.ToString());
 //        infoBatch.ManufacturingDate = Convert.ToDateTime(txtMfgDate.Text);
 //        infoBatch.ExpiryDate = Convert.ToDateTime(txtExpiryDate.Text);
 //        infoBatch.narration = txtNarration.Text.Trim();
 //        infoBatch.Extra1 = string.Empty;
 //        infoBatch.Extra2 = string.Empty;
 //        if (spBatch.BatchNameAndProductNameCheckExistence(txtBatchName.Text.Trim(), Convert.ToDecimal(cmbProduct.SelectedValue.ToString()), 0) == false)
 //        {
 //            if (dtpMfgDate.Value <= dtpExpiryDate.Value)
 //            {
 //                spBatch.BatchAddParticularFields(infoBatch);
 //                Messages.SavedMessage();
 //                Clear();
 //            }
 //            else
 //            {
 //                Messages.InformationMessage(" Can't save batch with mfg date greater than expiry date");
 //                txtMfgDate.Select();
 //            }
 //        }
 //        else
 //        {
 //            Messages.InformationMessage(" Already exist");
 //            txtBatchName.Focus();
 //        }
 //    }
 //    catch (Exception ex)
 //    {
 //        MessageBox.Show("B1:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
 //    }
 //}
 //public void EditFunction()
 //{
 //    try
 //    {
 //        BatchSP spBatch = new BatchSP();
 //        BatchInfo infoBatch = new BatchInfo();
 //        infoBatch.BatchNo = txtBatchName.Text.Trim();
 //        infoBatch.ProductId = Convert.ToDecimal(cmbProduct.SelectedValue.ToString());
 //        infoBatch.ManufacturingDate = Convert.ToDateTime(txtMfgDate.Text);
 //        infoBatch.ExpiryDate = Convert.ToDateTime(txtExpiryDate.Text);
 //        infoBatch.narration = txtNarration.Text.Trim();
 //        infoBatch.Extra1 = string.Empty;
 //        infoBatch.Extra2 = string.Empty;
 //        infoBatch.BatchId = decId;
 //        if (spBatch.BatchNameAndProductNameCheckExistence(txtBatchName.Text.Trim(), Convert.ToDecimal(cmbProduct.SelectedValue.ToString()), decBatchId) == false)
 //        {
 //            spBatch.BatchEdit(infoBatch);
 //            Messages.UpdatedMessage();
 //            SearchClear();
 //            Clear();
 //        }
 //        else
 //        {
 //            Messages.InformationMessage("Already exists");
 //            txtBatchName.Focus();
 //        }
 //    }
 //    catch (Exception ex)
 //    {
 //        MessageBox.Show("B2:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
 //    }
 //}
 /// <summary>
 /// Functin to save and update batch
 /// </summary>
 public void SaveOrEdit()
 {
     try
     {
         if (txtBatchName.Text.Trim() == string.Empty)
         {
             Messages.InformationMessage("Enter batch name");
             txtBatchName.Focus();
         }
         else if (cmbProduct.SelectedIndex == -1)
         {
             Messages.InformationMessage("Select product");
             cmbProduct.Focus();
         }
         else
         {
             BatchSP spBatch = new BatchSP();
             BatchInfo infoBatch = new BatchInfo();
             infoBatch.BatchNo = txtBatchName.Text.Trim();
             infoBatch.ProductId = Convert.ToDecimal(cmbProduct.SelectedValue.ToString());
             infoBatch.ManufacturingDate = Convert.ToDateTime(txtMfgDate.Text);
             infoBatch.ExpiryDate = Convert.ToDateTime(txtExpiryDate.Text);
             infoBatch.narration = txtNarration.Text.Trim();
             infoBatch.Extra1 = string.Empty;
             infoBatch.Extra2 = string.Empty;
             Int32 inBarcode = spBatch.AutomaticBarcodeGeneration(); // updated by jaseel
             infoBatch.barcode = Convert.ToString(inBarcode);
             if (btnSave.Text == "Save")
             {
                 //Jamshi
                 //if (PublicVariables.isMessageAdd)
                 //{
                 //    if (Messages.SaveMessage())
                 //    {
                 //        SaveFunction();
                 //    }
                 //}
                 //else
                 //{
                 //    SaveFunction();
                 //}
                 if (Messages.SaveConfirmation())
                 {
                     if (spBatch.BatchNameAndProductNameCheckExistence(txtBatchName.Text.Trim(), Convert.ToDecimal(cmbProduct.SelectedValue.ToString()), 0) == false)
                     {
                         if (dtpMfgDate.Value <= dtpExpiryDate.Value)
                         {
                             spBatch.BatchAddParticularFields(infoBatch);
                             Messages.SavedMessage();
                             Clear();
                         }
                         else
                         {
                             Messages.InformationMessage(" Can't save batch with mfg date greater than expiry date");
                             txtMfgDate.Select();
                         }
                     }
                     else
                     {
                         Messages.InformationMessage(" Already exist");
                         txtBatchName.Focus();
                     }
                 }
             }
             else
             {
                 //Jamshi
                 //if (PublicVariables.isMessageEdit)
                 //{
                 //    if (Messages.UpdateMessage())
                 //    {
                 //        EditFunction();
                 //    }
                 //}
                 //else
                 //{
                 //    EditFunction();
                 //}
                 if (Messages.UpdateConfirmation())
                 {
                     infoBatch.BatchId = decId;
                     if (spBatch.BatchNameAndProductNameCheckExistence(txtBatchName.Text.Trim(), Convert.ToDecimal(cmbProduct.SelectedValue.ToString()), decBatchId) == false)
                     {
                         spBatch.BatchEdit(infoBatch);
                         Messages.UpdatedMessage();
                         SearchClear();
                         Clear();
                     }
                     else
                     {
                         Messages.InformationMessage("Already exists");
                         txtBatchName.Focus();
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("B1:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }