private void dgvReplace_DoubleClick(object sender, EventArgs e)
        {
            if (dgvReplace.Rows.Count > 0 && dgvReplace.CurrentCell.OwningColumn.Name == "GBLNo" && dgvReplace.CurrentCell.Value.ToString() != "")
            {
                int intOpen = GISClass.General.OpenForm(typeof(SamplesLogin));

                if (intOpen == 1)
                {
                    GISClass.General.CloseForm(typeof(SamplesLogin));
                }
                IngredionManifestLog childForm = new IngredionManifestLog();
                childForm.Text      = "INGREDION SAMPLES LOGIN";
                childForm.MdiParent = this.MdiParent;
                childForm.nLogNo    = Convert.ToInt32(dgvReplace.CurrentCell.Value.ToString());
                childForm.nFR       = 1;
                childForm.Show();
                return;
            }
            dgvReplace.Enabled = false; pnlUpdate.Visible = true; pnlUpdate.BringToFront(); btnUpdateOK.Enabled = false; btnUpdateCancel.Enabled = false;
            try
            {
                txtTempID.Text   = dgvReplace.Rows[dgvReplace.CurrentCell.RowIndex].Cells["TempID"].Value.ToString();
                txtGBLNo.Text    = dgvReplace.Rows[dgvReplace.CurrentCell.RowIndex].Cells["GBLNo"].Value.ToString();
                cboSponsors.Text = dgvReplace.Rows[dgvReplace.CurrentCell.RowIndex].Cells["SponsorName"].Value.ToString();
                cboContacts.Text = dgvReplace.Rows[dgvReplace.CurrentCell.RowIndex].Cells["Contact"].Value.ToString();
            }
            catch { }
        }
        private void dgvFile_DoubleClick(object sender, EventArgs e)
        {
            if (dgvFile.Rows.Count > 0 && dgvFile.CurrentCell.OwningColumn.Name == "GBLNo" && dgvFile.CurrentCell.Value.ToString() != "")
            {
                int intOpen = GISClass.General.OpenForm(typeof(SamplesLogin));

                if (intOpen == 1)
                {
                    GISClass.General.CloseForm(typeof(SamplesLogin));
                }
                IngredionManifestLog childForm = new IngredionManifestLog();
                childForm.Text      = "INGREDION SAMPLES LOGIN";
                childForm.MdiParent = this.MdiParent;
                childForm.nLogNo    = Convert.ToInt32(dgvFile.CurrentCell.Value.ToString());
                childForm.nFR       = 1;
                childForm.Show();
            }
        }
Пример #3
0
        private void btnOKPrint_Click(object sender, EventArgs e)
        {
            if (cboFillCodes.SelectedIndex == -1)
            {
                MessageBox.Show("Please select fill code.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                cboFillCodes.Text = "";
                return;
            }

            //Log Master Record
            //Int32 nLogNo = GISClass.General.NewID("LogMaster", "GBLNo");
            Int32 nLogNo = GISClass.General.NewGBLNo("LogMaster", "GBLNo");

            int           nBags  = Convert.ToInt16(txtBags.Text);
            SqlConnection sqlcnn = GISClass.DBConnection.GISConnection();

            if (sqlcnn == null)
            {
                MessageBox.Show("Connection problem encountered. Please try again later.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            SqlCommand sqlcmd = new SqlCommand();

            sqlcmd.Connection = sqlcnn;
            sqlcmd.Parameters.AddWithValue("@nMode", 1);
            sqlcmd.Parameters.AddWithValue("@SampleNo", nLogNo);
            sqlcmd.Parameters.AddWithValue("@RecDte", DateTime.Now);
            sqlcmd.Parameters.AddWithValue("@SpID", Convert.ToInt16(cboSponsorID.Text));
            sqlcmd.Parameters.AddWithValue("@ConID", cboContacts.SelectedValue);
            sqlcmd.Parameters.AddWithValue("@Article", cboFillCodes.Text);
            sqlcmd.Parameters.AddWithValue("@CtlSub", DBNull.Value);
            sqlcmd.Parameters.AddWithValue("@SampDesc", (nBags - 1).ToString() + " whirl-pack bags, containing white powder.");
            sqlcmd.Parameters.AddWithValue("@AddlNotes", DBNull.Value);
            sqlcmd.Parameters.AddWithValue("@SSNo", txtSSFormNo.Text);
            sqlcmd.Parameters.AddWithValue("@Rush", DBNull.Value);
            sqlcmd.Parameters.AddWithValue("@StorageCode", 1);
            sqlcmd.Parameters.AddWithValue("@StorageDesc", DBNull.Value);
            sqlcmd.Parameters.AddWithValue("@ReceiptCode", 1);
            sqlcmd.Parameters.AddWithValue("@Locked", 0);
            sqlcmd.Parameters.AddWithValue("@AnaDone", DBNull.Value);
            sqlcmd.Parameters.AddWithValue("@MngrChecked", DBNull.Value);
            sqlcmd.Parameters.AddWithValue("@DteCancelled", DBNull.Value);
            sqlcmd.Parameters.AddWithValue("@RetestNo", 0);
            sqlcmd.Parameters.AddWithValue("@UserID", LogIn.nUserID);

            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.CommandText = "spAddEditLogMstr";
            try
            {
                sqlcmd.ExecuteNonQuery();
            }
            catch (System.Data.SqlClient.SqlException exSql)
            {
                if (exSql.Message.ToString().IndexOf("PRIMARY KEY") >= 0)
                {
                    MessageBox.Show(exSql.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                sqlcmd.Dispose(); sqlcnn.Close(); sqlcnn.Dispose();
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                sqlcmd.Dispose(); sqlcnn.Close(); sqlcnn.Dispose();
                return;
            }
            sqlcmd.Dispose();

            //Log Samples
            for (int i = 0; i < nBags; i++)
            {
                sqlcmd            = new SqlCommand();
                sqlcmd.Connection = sqlcnn;

                sqlcmd.Parameters.AddWithValue("@nMode", 1);
                sqlcmd.Parameters.AddWithValue("@LogNo", nLogNo);
                sqlcmd.Parameters.AddWithValue("@SlashID", i);
                if (i == 0)//Composite Sample entry
                {
                    sqlcmd.Parameters.AddWithValue("@SlashNo", txtCompBag.Text);
                    sqlcmd.Parameters.AddWithValue("@SampleDesc", "Bags 1-" + nBags.ToString() + " Comp.");
                    sqlcmd.Parameters.AddWithValue("@AddlData", "<SamplesData><Value1>" + txtLotNo.Text + "</Value1><Value2></Value2></SamplesData>");
                }
                else
                {
                    sqlcmd.Parameters.AddWithValue("@SlashNo", i.ToString("000"));
                    sqlcmd.Parameters.AddWithValue("@SampleDesc", "Bag #" + i.ToString());
                    sqlcmd.Parameters.AddWithValue("@AddlData", "<SamplesData><Value1>" + txtLotNo.Text + "</Value1><Value2></Value2></SamplesData>");
                }
                sqlcmd.Parameters.AddWithValue("@UserID", LogIn.nUserID);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.CommandText = "spAddEditLogSample";
                try
                {
                    sqlcmd.ExecuteNonQuery();
                }
                catch (System.Data.SqlClient.SqlException exSql)
                {
                    if (exSql.Message.ToString().IndexOf("PRIMARY KEY") >= 0)
                    {
                        MessageBox.Show(exSql.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        sqlcmd.Dispose(); sqlcnn.Close(); sqlcnn.Dispose();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    sqlcmd.Dispose(); sqlcnn.Close(); sqlcnn.Dispose();
                    return;
                }
            }
            sqlcmd.Dispose();

            //Lot Tests
            DataTable dtLogTests = new DataTable();

            dtLogTests = GISClass.Ingredion.SpecialBatch(cboFillCodes.Text);
            for (int i = 0; i < dtLogTests.Rows.Count; i++)
            {
                sqlcmd            = new SqlCommand();
                sqlcmd.Connection = sqlcnn;

                sqlcmd.Parameters.AddWithValue("@nMode", 1);
                sqlcmd.Parameters.AddWithValue("@LogNo", nLogNo);
                sqlcmd.Parameters.AddWithValue("@SC", dtLogTests.Rows[i]["ServiceCode"]);
                sqlcmd.Parameters.AddWithValue("@ProtNo", DBNull.Value);
                sqlcmd.Parameters.AddWithValue("@StartDte", DateTime.Now);
                sqlcmd.Parameters.AddWithValue("@EndDte", DateTime.Now.AddDays(5));
                sqlcmd.Parameters.AddWithValue("@QuoteNo", txtQuoteNo.Text);
                sqlcmd.Parameters.AddWithValue("@PONo", txtPONo.Text);
                sqlcmd.Parameters.AddWithValue("@Samples", "1");
                sqlcmd.Parameters.AddWithValue("@Slashes", "1");
                sqlcmd.Parameters.AddWithValue("@BookNo", txtBookNo.Text);
                sqlcmd.Parameters.AddWithValue("@BillQty", dtLogTests.Rows[i]["BillQty"]);
                sqlcmd.Parameters.AddWithValue("@EC", DBNull.Value);
                sqlcmd.Parameters.AddWithValue("@ECType", DBNull.Value);
                sqlcmd.Parameters.AddWithValue("@ECLen", DBNull.Value);
                sqlcmd.Parameters.AddWithValue("@ECEndDte", DBNull.Value);
                sqlcmd.Parameters.AddWithValue("@DteSampled", DBNull.Value);
                sqlcmd.Parameters.AddWithValue("@ExtData", "<SCExtData></SCExtData>");
                sqlcmd.Parameters.AddWithValue("@AddlNotes", "");
                sqlcmd.Parameters.AddWithValue("@UserID", LogIn.nUserID);

                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.CommandText = "spAddEditLogTest";
                try
                {
                    sqlcmd.ExecuteNonQuery();
                }
                catch (System.Data.SqlClient.SqlException exSql)
                {
                    if (exSql.Message.ToString().IndexOf("PRIMARY KEY") >= 0)
                    {
                        MessageBox.Show(exSql.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        sqlcmd.Dispose(); sqlcnn.Close(); sqlcnn.Dispose();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    sqlcmd.Dispose(); sqlcnn.Close(); sqlcnn.Dispose();
                    return;
                }
            }
            sqlcmd.Dispose();

            //LogTestSamples
            //INGREDION Test Results Table
            //DataTable dtSC = new DataTable();
            //dtSC = GISClass.Ingredion.SpecialBatchSC(cboFillCodes.Text);
            for (int i = 0; i < dtLogTests.Rows.Count; i++)
            {
                sqlcmd            = new SqlCommand();
                sqlcmd.Connection = sqlcnn;

                sqlcmd.Parameters.AddWithValue("@nMode", 1);
                sqlcmd.Parameters.AddWithValue("@LogNo", nLogNo);
                sqlcmd.Parameters.AddWithValue("@SC", dtLogTests.Rows[i]["ServiceCode"]);
                sqlcmd.Parameters.AddWithValue("@DateTested", DBNull.Value);
                sqlcmd.Parameters.AddWithValue("@TestResult", DBNull.Value);
                sqlcmd.Parameters.AddWithValue("@Note", DBNull.Value);
                sqlcmd.Parameters.AddWithValue("@AnalystID", DBNull.Value);
                sqlcmd.Parameters.AddWithValue("@UserID", LogIn.nUserID);

                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.CommandText = "spAddEditIngredionData";
                try
                {
                    sqlcmd.ExecuteNonQuery();
                }
                catch (System.Data.SqlClient.SqlException exSql)
                {
                    if (exSql.Message.ToString().IndexOf("PRIMARY KEY") >= 0)
                    {
                        MessageBox.Show(exSql.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        sqlcmd.Dispose(); sqlcnn.Close(); sqlcnn.Dispose();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    sqlcmd.Dispose(); sqlcnn.Close(); sqlcnn.Dispose();
                    return;
                }
            }
            sqlcmd.Dispose();
            //Main Test Results Table
            byte      nSwSC = 0, nSwSlash = 0; string strSlash = "";
            DataTable dtSlashSC = new DataTable();

            dtSlashSC = GISClass.Ingredion.SpecialBatchSlash(cboFillCodes.Text);
            for (int i = 0; i < dtSlashSC.Rows.Count; i++)
            {
                nSwSC = 0; nSwSlash = 0;

                strSlash = dtSlashSC.Rows[i]["SlashNo"].ToString();
                try
                {
                    int nS = Convert.ToInt16(strSlash);
                    strSlash = nS.ToString("00");
                }
                catch { }

                for (int j = 0; j < dtLogTests.Rows.Count; j++)
                {
                    if (dtSlashSC.Rows[i]["ServiceCode"].ToString() == dtLogTests.Rows[j]["ServiceCode"].ToString())
                    {
                        nSwSC = 1;
                        break;
                    }
                }

                for (int k = 0; k < nBags; k++)
                {
                    if (strSlash == k.ToString("00"))
                    {
                        nSwSlash = 1;
                        break;
                    }
                }

                if (nSwSC == 1 && nSwSlash == 1)
                {
                    sqlcmd            = new SqlCommand();
                    sqlcmd.Connection = sqlcnn;
                    sqlcmd.Parameters.AddWithValue("@nMode", 1);
                    sqlcmd.Parameters.AddWithValue("@LogNo", nLogNo);
                    sqlcmd.Parameters.AddWithValue("@SC", dtSlashSC.Rows[i]["ServiceCode"]);
                    sqlcmd.Parameters.AddWithValue("@SlashNo", strSlash);
                    sqlcmd.Parameters.AddWithValue("@SpID", DBNull.Value);
                    sqlcmd.Parameters.AddWithValue("@TestResults", "<TestData></TestData>");
                    sqlcmd.Parameters.AddWithValue("@UserID", LogIn.nUserID);

                    sqlcmd.CommandType = CommandType.StoredProcedure;
                    sqlcmd.CommandText = "spAddEditSlashSC";
                    try
                    {
                        sqlcmd.ExecuteNonQuery();
                    }
                    catch (System.Data.SqlClient.SqlException exSql)
                    {
                        if (exSql.Message.ToString().IndexOf("PRIMARY KEY") >= 0)
                        {
                            MessageBox.Show(exSql.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            sqlcmd.Dispose(); sqlcnn.Close(); sqlcnn.Dispose();
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        sqlcmd.Dispose(); sqlcnn.Close(); sqlcnn.Dispose();
                        return;
                    }
                }
            }
            //Billing Reference
            DataTable dt = GISClass.Quotations.LoadLoginTests(txtQuoteNo.Text);

            if (dt == null)
            {
                MessageBox.Show("Connection problems. Please contact your system administrator.");
                return;
            }

            for (int i = 0; i < dtLogTests.Rows.Count; i++)
            {
                for (int j = 0; j < dt.Rows.Count; j++)
                {
                    if (dtLogTests.Rows[i]["Servicecode"].ToString().Trim() == dt.Rows[j]["ServiceCode"].ToString().Trim())
                    {
                        string strQ   = txtQuoteNo.Text;
                        int    nI     = strQ.IndexOf("R");
                        string strQNo = strQ.Substring(0, nI - 1);
                        string strRNo = strQ.Substring((nI + 1), strQ.Length - (nI + 1));

                        sqlcmd            = new SqlCommand();
                        sqlcmd.Connection = sqlcnn;
                        sqlcmd.Parameters.AddWithValue("@nMode", 1);
                        sqlcmd.Parameters.AddWithValue("@LogNo", nLogNo);
                        sqlcmd.Parameters.AddWithValue("@SC", dtLogTests.Rows[i]["ServiceCode"]);
                        sqlcmd.Parameters.AddWithValue("@QuoteNo", strQNo);
                        sqlcmd.Parameters.AddWithValue("@RevNo", Convert.ToInt16(strRNo));
                        sqlcmd.Parameters.AddWithValue("@ControlNo", dt.Rows[j]["ControlNo"]);
                        sqlcmd.Parameters.AddWithValue("@BillQty", dtLogTests.Rows[i]["BillQty"]);
                        if (dt.Rows[j]["UnitPrice"] != DBNull.Value && dt.Rows[j]["UnitPrice"].ToString() != "0")
                        {
                            sqlcmd.Parameters.AddWithValue("@UnitPrice", dt.Rows[j]["UnitPrice"]);
                        }
                        else
                        {
                            sqlcmd.Parameters.AddWithValue("@UnitPrice", DBNull.Value);
                        }
                        sqlcmd.Parameters.AddWithValue("@Rush", DBNull.Value);
                        sqlcmd.Parameters.AddWithValue("@RushPrice", DBNull.Value);
                        sqlcmd.Parameters.AddWithValue("@UserID", LogIn.nUserID);

                        sqlcmd.CommandType = CommandType.StoredProcedure;
                        sqlcmd.CommandText = "spAddEditBillRef";
                        try
                        {
                            sqlcmd.ExecuteNonQuery();
                        }
                        catch (System.Data.SqlClient.SqlException exSql)
                        {
                            if (exSql.Message.ToString().IndexOf("PRIMARY KEY") >= 0)
                            {
                                MessageBox.Show(exSql.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                sqlcmd.Dispose(); sqlcnn.Close(); sqlcnn.Dispose();
                                return;
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            sqlcmd.Dispose(); sqlcnn.Close(); sqlcnn.Dispose();
                            return;
                        }
                        sqlcmd.Dispose();
                    }
                }
            }
            sqlcmd.Dispose(); sqlcnn.Close(); sqlcnn.Dispose();
            //Inserts Record to Sample Tracking Database - TestStatus Table 10/10/2017
            GISClass.Samples.AddTestStatus(nLogNo);

            //MessageBox.Show("Special batch login successfully saved.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);

            int intOpen = GISClass.General.OpenForm(typeof(SamplesLogin));

            if (intOpen == 1)
            {
                GISClass.General.CloseForm(typeof(SamplesLogin));
            }
            IngredionManifestLog childForm = new IngredionManifestLog();

            childForm.MdiParent = this.MdiParent;
            childForm.Text      = "INGREDION LOGINS";
            childForm.nLogNo    = nLogNo;
            childForm.nFR       = 1;
            childForm.Show();
            this.Dispose();
        }