private List <producttesttemplatedetail> getProdTempDetails(producttesttemplateheader pttemph)
        {
            List <producttesttemplatedetail> PTTempDetails = new List <producttesttemplatedetail>();

            try
            {
                producttesttemplatedetail pttempd = new producttesttemplatedetail();
                for (int i = 0; i < grdProductTestDetail.Rows.Count; i++)
                {
                    pttempd                   = new producttesttemplatedetail();
                    pttempd.DocumentID        = pttemph.DocumentID;
                    pttempd.TemplateNo        = pttemph.TemplateNo;
                    pttempd.TemplateDate      = pttemph.TemplateDate;
                    pttempd.TestDescriptionID = grdProductTestDetail.Rows[i].Cells["TestDescriptionID"].Value.ToString();
                    pttempd.ExpectedResult    = grdProductTestDetail.Rows[i].Cells["ExpectedResult"].Value.ToString();
                    pttempd.SlNo              = Convert.ToInt32(grdProductTestDetail.Rows[i].Cells["SINo"].Value.ToString());
                    pttempd.Remark            = grdProductTestDetail.Rows[i].Cells["Remark"].Value.ToString();
                    PTTempDetails.Add(pttempd);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("getProdTempDetails() : Error getting ProductTemp Details");
                PTTempDetails = null;
            }
            return(PTTempDetails);
        }
 public void clearData()
 {
     try
     {
         grdProductTestDetail.Rows.Clear();
         //----------clear temperory panels
         clearTabPageControls();
         pnlForwarder.Visible         = false;
         dtTemplateDate.Value         = DateTime.Parse("01-01-1900");
         txtTemplateNo.Text           = "";
         txtStockItemId.Text          = "";
         txtModelNo.Text              = "";
         txtModelName.Text            = "";
         btnSelectStockItemID.Enabled = true;
         prevsptheader = new producttesttemplateheader();
         removeControlsFromForwarderPanelTV();
         removeControlsFromModelPanel();
         removeControlsFromPnlLvPanel();
     }
     catch (Exception ex)
     {
     }
 }
 private void grdList_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (e.RowIndex < 0)
         {
             return;
         }
         string columnName = grdList.Columns[e.ColumnIndex].Name;
         if (columnName.Equals("Finalize") || columnName.Equals("Edit") || columnName.Equals("View") || columnName.Equals("LoadDocument"))
         {
             clearData();
             setButtonVisibility(columnName);
             docID = grdList.Rows[e.RowIndex].Cells[0].Value.ToString();
             int rowID = e.RowIndex;
             btnSave.Text = "Update";
             DataGridViewRow row = grdList.Rows[rowID];
             prevsptheader               = new producttesttemplateheader();
             prevsptheader.DocumentID    = grdList.Rows[e.RowIndex].Cells["gDocumentID"].Value.ToString();
             prevsptheader.TemplateNo    = Convert.ToInt32(grdList.Rows[e.RowIndex].Cells["TemplateNo"].Value.ToString());
             prevsptheader.TemplateDate  = DateTime.Parse(grdList.Rows[e.RowIndex].Cells["TemplateDate"].Value.ToString());
             prevsptheader.StockItemID   = grdList.Rows[e.RowIndex].Cells["StockItemID"].Value.ToString();
             prevsptheader.StockItemName = grdList.Rows[e.RowIndex].Cells["StockItemName"].Value.ToString();
             prevsptheader.ModelNo       = grdList.Rows[e.RowIndex].Cells["ModelNo"].Value.ToString();
             prevsptheader.ModelName     = grdList.Rows[e.RowIndex].Cells["ModelName"].Value.ToString();
             if (columnName.Equals("LoadDocument"))
             {
                 string hdrString = "Document Template No:" + prevsptheader.TemplateNo + "\n" +
                                    "Template Date:" + prevsptheader.TemplateDate.ToString("dd-MM-yyyy");
                 //poheader po =PurchaseOrderDB.getPODetailForMR(prevpoh.PONo, prevpoh.PODate);
                 string dicDir = Main.documentDirectory + "\\" + docID;
                 string subDir = prevsptheader.TemplateNo + "-" + prevsptheader.TemplateDate.ToString("yyyyMMddhhmmss");
                 FileManager.LoadDocuments load = new FileManager.LoadDocuments(dicDir, subDir, docID, hdrString);
                 load.ShowDialog();
                 this.RemoveOwnedForm(load);
                 btnCancel_Click_2(null, null);
                 return;
             }
             txtTemplateNo.Text  = prevsptheader.TemplateNo.ToString();
             txtStockItemId.Text = prevsptheader.StockItemID + "-" + prevsptheader.StockItemName;
             txtModelName.Text   = prevsptheader.ModelName;
             txtModelNo.Text     = prevsptheader.ModelNo;
             //+ "-" +prevsptheader.StockItemName;
             dtTemplateDate.Value = prevsptheader.TemplateDate;
             List <producttesttemplatedetail> pttempd = ProductTestTemplateDB.getProductTestTempDetail(prevsptheader);
             grdProductTestDetail.Rows.Clear();
             int i = 0;
             foreach (producttesttemplatedetail pttempdetail in pttempd)
             {
                 if (!AddProductTestTemDetailRow())
                 {
                     MessageBox.Show("Error found in Prod Temp Detail. Please correct before updating the details");
                 }
                 else
                 {
                     grdProductTestDetail.Rows[i].Cells["SINo"].Value = pttempdetail.SlNo;
                     grdProductTestDetail.Rows[i].Cells["TestDescriptionID"].Value = pttempdetail.TestDescriptionID;
                     grdProductTestDetail.Rows[i].Cells["TestDescription"].Value   = pttempdetail.TestDescription;
                     grdProductTestDetail.Rows[i].Cells["ExpectedResult"].Value    = pttempdetail.ExpectedResult;
                     grdProductTestDetail.Rows[i].Cells["Remark"].Value            = pttempdetail.Remark;
                     i++;
                 }
             }
             if (!verifyAndReworkProdDetailGridRows())
             {
                 MessageBox.Show("Error found in Product Templete details. Please correct before updating the details");
             }
             btnSave.Text       = "Update";
             pnlList.Visible    = false;
             pnlAddEdit.Visible = true;
             btnSave.Text       = "Update";
             pnlList.Visible    = false;
             pnlAddEdit.Visible = true;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error");
     }
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            Boolean status = true;

            try
            {
                ProductTestTemplateDB       PTTempDB = new ProductTestTemplateDB();
                producttesttemplateheader   ptlist   = new producttesttemplateheader();
                System.Windows.Forms.Button btn      = sender as System.Windows.Forms.Button;
                string btnText = btnSave.Text;
                try
                {
                    ptlist.DocumentID  = docID;
                    ptlist.StockItemID = txtStockItemId.Text.Substring(0, txtStockItemId.Text.IndexOf('-'));
                    ptlist.ModelNo     = txtModelNo.Text;
                    ptlist.ModelName   = txtModelName.Text;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Validation failed");
                    return;
                }
                if (btnText.Equals("Save"))
                {
                    // ptlist.TemplateNo = DocumentNumberDB.getNewNumber(docID, 1);
                    ptlist.TemplateDate = UpdateTable.getSQLDateTime();
                }
                else
                {
                    ptlist.TemplateNo   = Convert.ToInt32(txtTemplateNo.Text);
                    ptlist.TemplateDate = prevsptheader.TemplateDate;
                }
                if (!PTTempDB.validateProductTestTemp(ptlist))
                {
                    MessageBox.Show("Validation Failed");
                    return;
                }
                if (btnText.Equals("Save"))
                {
                    List <producttesttemplatedetail> PTTempDetails = getProdTempDetails(ptlist);
                    if (PTTempDB.InsertPTHeaderAndDetail(ptlist, PTTempDetails))
                    {
                        MessageBox.Show("Product Test Template Details Added");
                        closeAllPanels();
                        listOption = 1;
                        ListFilteredProdTestTempList(listOption);
                    }
                    else
                    {
                        MessageBox.Show("Failed to Insert Product Test Template Details");
                        status = false;
                    }
                }
                else if (btnText.Equals("Update"))
                {
                    List <producttesttemplatedetail> PTTempDetails = getProdTempDetails(ptlist);
                    if (PTTempDB.updatePTHeaderAndDetail(ptlist, PTTempDetails))
                    {
                        MessageBox.Show("Product Test Template updated");
                        closeAllPanels();
                        listOption = 1;
                        ListFilteredProdTestTempList(listOption);
                    }
                    else
                    {
                        status = false;
                        MessageBox.Show("Failed to update Product Test Template Details");
                    }
                }
                else
                {
                    MessageBox.Show("Validation failed");
                    status = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(" Validation failed");
                status = false;
            }
            if (status)
            {
                setButtonVisibility("btnEditPanel"); //activites are same for cancel, forward,approve, reverse and save
            }
        }