Exemple #1
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Validation_Form() == true)
            {
                try
                {
                    theDTStock = (DataTable)dgwOpeningStock.DataSource;

                    DataTable dtb = theDTStock.Copy();

                    DataTable dtCheck = (DataTable)dgwOpeningStock.DataSource;
                    DataView  dt11    = dtCheck.DefaultView;

                    theDTStock.PrimaryKey = new DataColumn[] { theDTStock.Columns["ItemId"], theDTStock.Columns["BatchId"], theDTStock.Columns["StoreId"], theDTStock.Columns["ExpiryDate"] };
                    DataView  theDV = new DataView(theDTStock);
                    DataTable dtNew = null;
                    theDV.RowFilter = "ItemId=" + theItemIdGbl + " and BatchId=" + BatchId + " and StoreId=" + StoreId + " and ExpiryDate='" + ExpiryDate + "'";
                    if (theDV.Count > 0)
                    {
                        theDV.Delete(0);

                        dtNew = dt11.ToTable();

                        if (dtNew.Rows.Count > 0)
                        {
                            for (int batchVal = 0; batchVal < dtNew.Rows.Count; batchVal++)
                            {
                                if (dtNew.Rows[batchVal]["BatchNo"].ToString() == txtBatchName.Text.ToString())
                                {
                                    ShowGrid(dtb);
                                    IQCareWindowMsgBox.ShowWindow("DuplicateBatchName", this);
                                    return;
                                }
                            }
                        }
                        DataRow theDRow = theDTStock.NewRow();
                        if (lstSearchBatch.SelectedValue == null)
                        {
                            BindFunctions theBindManager = new BindFunctions();
                            IMasterList   objItemlist    = (IMasterList)ObjectFactory.CreateInstance("BusinessProcess.SCM.BMasterList,BusinessProcess.SCM");
                            DataSet       theDSBatchName = objItemlist.SaveBatchName(txtBatchName.Text, GblIQCare.AppUserId, lstSearch.SelectedValue.ToString(), dtpExpiryDate.Text);
                            theDRow["BatchId"] = Convert.ToString(theDSBatchName.Tables[0].Rows[0]["BatchId"]);
                            theDTBatch.Clear();
                            theDTBatch = theDSBatchName.Tables[1];
                            theBindManager.Win_BindListBox(lstSearchBatch, theDTBatch, "Name", "Id");
                        }
                        else
                        {
                            theDRow["BatchId"] = lstSearchBatch.SelectedValue;
                        }
                        theDRow["ItemId"]         = lstSearch.SelectedValue;
                        theDRow["ItemName"]       = txtItemName.Text;
                        theDRow["StoreId"]        = ddlStore.SelectedValue;
                        theDRow["StoreName"]      = ddlStore.Text;
                        theDRow["DispensingUnit"] = txtDispensingUnit.Text;
                        theDRow["BatchNo"]        = txtBatchName.Text;
                        theDRow["ExpiryDate"]     = string.Format("{0:dd-MMM-yyyy}", dtpExpiryDate.Text);
                        theDRow["Quantity"]       = txtOpeningQty.Text;
                        theDRow["OpeningStock"]   = 0;
                        //theDRow["TransDate"] = string.Format("{0:dd-MMM-yyyy}", dtpExpiryDate.Text);
                        theDTStock.Rows.Add(theDRow);
                    }
                    else
                    {
                        dtNew = dt11.ToTable();
                        if (dtNew.Rows.Count > 0)
                        {
                            for (int batchVal = 0; batchVal < dtNew.Rows.Count; batchVal++)
                            {
                                if (dtNew.Rows[batchVal]["BatchNo"].ToString() == txtBatchName.Text.ToString())
                                {
                                    ShowGrid(theDTStock);
                                    IQCareWindowMsgBox.ShowWindow("DuplicateBatchName", this);
                                    return;
                                }
                            }
                        }

                        DataRow theDRow = theDTStock.NewRow();
                        if (lstSearchBatch.SelectedValue == null)
                        {
                            BindFunctions theBindManager = new BindFunctions();
                            IMasterList   objItemlist    = (IMasterList)ObjectFactory.CreateInstance("BusinessProcess.SCM.BMasterList,BusinessProcess.SCM");
                            //DataSet theDSBatchName = objItemlist.SaveBatchName(txtBatchName.Text, GblIQCare.AppUserId);

                            DataSet theDSBatchName = objItemlist.SaveBatchName(txtBatchName.Text, GblIQCare.AppUserId, lstSearch.SelectedValue.ToString(), dtpExpiryDate.Text);


                            theDRow["BatchId"] = Convert.ToString(theDSBatchName.Tables[0].Rows[0]["BatchId"]);
                            theDTBatch.Clear();
                            theDTBatch = theDSBatchName.Tables[1];
                            theBindManager.Win_BindListBox(lstSearchBatch, theDTBatch, "Name", "Id");
                        }
                        else
                        {
                            theDRow["BatchId"] = lstSearchBatch.SelectedValue;
                        }

                        theDRow["ItemId"]         = lstSearch.SelectedValue;
                        theDRow["ItemName"]       = txtItemName.Text;
                        theDRow["StoreId"]        = ddlStore.SelectedValue;
                        theDRow["StoreName"]      = ddlStore.Text;
                        theDRow["DispensingUnit"] = txtDispensingUnit.Text;
                        theDRow["BatchNo"]        = txtBatchName.Text;
                        theDRow["ExpiryDate"]     = string.Format("{0:dd-MMM-yyyy}", dtpExpiryDate.Text);
                        theDRow["Quantity"]       = txtOpeningQty.Text;
                        theDRow["OpeningStock"]   = 0;
                        //theDRow["TransacDate"] = string.Format("{0:dd-MMM-yyyy}", dtpTransdate.Text);
                        theDTStock.Rows.Add(theDRow);
                    }
                    theDTStock.AcceptChanges();
                    ShowGrid(theDTStock);
                    Clear();
                }
                catch (Exception err)
                {
                    if (err.GetType().FullName == "System.Data.ConstraintException")
                    {
                        IQCareWindowMsgBox.ShowWindow("DuplicateItemName", this);
                    }
                }
            }
        }