예제 #1
0
        public void Atualizar(Formulario f)
        {
            try
            {
                AbrirConexao(); //abrir conexão..
                Tr  = Con.BeginTransaction();
                Cmd = new SqlCommand("UPDATE Formulario.formulario SET Nome = @v2, Empresa = @v3, Email = @v4 where IdFormulario = @v1", Con, Tr);
                Cmd.Parameters.AddWithValue("@v1", f.IdFormulario);
                Cmd.Parameters.AddWithValue("@v2", f.Nome);
                Cmd.Parameters.AddWithValue("@v3", f.Empresa);
                //Cmd.Parameters.AddWithValue("@v4", f.DataCriacao);
                //Cmd.Parameters.AddWithValue("@v5", f.DataConclusao);
                //Cmd.Parameters.AddWithValue("@v6", f.UltimoAcesso);
                //Cmd.Parameters.AddWithValue("@v7", f.Acessado);
                Cmd.Parameters.AddWithValue("@v4", f.Email);
                Cmd.ExecuteNonQuery();
                Tr.Commit();
            }
            catch (Exception ex)
            {
                if (Tr != null)
                {
                    Tr.Rollback(); // Desfaz a transação..
                }
                throw new Exception("Não foi possível atualizar o Formulário: " + ex.Message);
            }

            finally
            {
                FecharConexao(); //fechar conexão..
            }
        }
예제 #2
0
        public void AtualizaUltimoAcesso(int id)
        {
            try
            {
                AbrirConexao(); //abrir conexão..
                Tr  = Con.BeginTransaction();
                Cmd = new SqlCommand("UPDATE Formulario.formulario SET UltimoAcesso = '" + DateTime.Now.ToString("dd/MM/yyyy hh:mm") + "' where IdFormulario = " + id, Con, Tr);
                string t = "UPDATE Formulario.formulario SET UltimoAcesso = '" + DateTime.Now.ToString("dd/MM/yyyy hh:mm") + "' where IdFormulario = " + id;
                Cmd.ExecuteNonQuery();

                Cmd = new SqlCommand("UPDATE Formulario.Formulario SET Acessado = 'SIM' where IdFormulario = " + id, Con, Tr);
                Cmd.ExecuteNonQuery();

                Tr.Commit();
            }
            catch (Exception ex)
            {
                if (Tr != null)
                {
                    Tr.Rollback(); // Desfaz a transação..
                }
                throw new Exception("Não foi possível atualizar o Formulário: " + ex.Message);
            }

            finally
            {
                FecharConexao(); //fechar conexão..
            }
        }
예제 #3
0
        public void Excluir(int id)
        {
            try
            {
                AbrirConexao();
                Tr  = Con.BeginTransaction();
                Cmd = new SqlCommand("DELETE FROM Formulario.PerguntasPorFormularios WHERE IdFormulario = @v1", Con, Tr);
                Cmd.Parameters.AddWithValue("@v1", id);
                Cmd.ExecuteNonQuery();


                Cmd = new SqlCommand("DELETE FROM Formulario.Formulario WHERE IdFormulario = @v1", Con, Tr);
                Cmd.Parameters.AddWithValue("@v1", id);
                Cmd.ExecuteNonQuery();
                Tr.Commit();
            }
            catch (Exception ex)
            {
                if (Tr != null)
                {
                    Tr.Rollback(); // Desfaz a transação..
                }
                throw new Exception("Não foi possível remover o formulário: " + ex.Message);
            }
        }
예제 #4
0
 public void Atualizar(Perguntas p)
 {
     try
     {
         AbrirConexao();
         Tr  = Con.BeginTransaction();
         Cmd = new SqlCommand("UPDATE Formulario.Perguntas SET descricao = @v2, tipo = @v3 WHERE IdPergunta = @v1", Con, Tr);
         Cmd.Parameters.AddWithValue("@v1", p.IdPergunta);
         Cmd.Parameters.AddWithValue("@v2", p.Descricao);
         Cmd.Parameters.AddWithValue("@v3", p.Tipo);
         Cmd.ExecuteNonQuery();
         Tr.Commit();
     }
     catch (Exception ex)
     {
         if (Tr != null)
         {
             Tr.Rollback(); // Desfaz a transação..
         }
         throw new Exception("Não foi possível atualizar a pergunta: " + ex.Message);
     }
     finally
     {
         FecharConexao(); //fechar conexão..
     }
 }
예제 #5
0
        private void deleteAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (NP.MSGB("Do you want to delete all ?") == DialogResult.Yes)
            {
                if (this.dgvView.RowCount == 0)
                {
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Data Not Found !!"); return;
                }

                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction();
                try
                {
                    SqlCommand cmdDel = new SqlCommand();
                    NP_Cls.SqlDel = "DELETE FROM t_Routing WHERE (MaterialCode = @MaterialCode) AND (PlantCode = @PlantCode)";
                    cmdDel.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15).Value = this.cbMaterial.SelectedValue;
                    cmdDel.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4).Value     = this.cbPlant.SelectedValue;
                    cmdDel.Connection = oConn; cmdDel.CommandText = NP_Cls.SqlDel; cmdDel.Transaction = Tr;
                    cmdDel.ExecuteNonQuery();

                    NP_Cls.SqlDel = "DELETE FROM t_RoutingDetail WHERE (MaterialCode = @MaterialCode) AND (PlantCode = @PlantCode) AND (WorkCenterCode = @WorkCenterCode)";
                    cmdDel.Parameters.Add("@WorkCenterCode", SqlDbType.NVarChar, 10).Value = this.dgvView["clnName", this.dgvView.CurrentRow.Index].Value;
                    cmdDel.Connection = oConn; cmdDel.CommandText = NP_Cls.SqlDel; cmdDel.Transaction = Tr;
                    cmdDel.ExecuteNonQuery();

                    if (NP._TRanSave(oConn, Tr, NP_Cls.NPTranType.Delete, "t_Routing:t_RoutingDetail", NP_Cls.strUsr))
                    {
                        Tr.Commit();
                        DGV(); Clear(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Delete All Completed !!");
                    }
                    else
                    {
                        NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Try agian !!"); return;
                    }
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #6
0
        private void btnSaveChange_Click(object sender, EventArgs e)
        {
            if (this.dgvView.RowCount == 0)
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Data Not Found !!"); return;
            }
            this.dgvView.EndEdit();
            if (NP.MSGB("Do you want to Save Change Data ?") == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                SqlTransaction Tr;
                oConn.Open(); Tr = oConn.BeginTransaction(); this.dgvView.EndEdit();
                try
                {
                    SqlCommand cmdEdit = new SqlCommand();
                    NP_Cls.SqlInsert = "UPDATE    t_VendorSourceList " +
                                       "SET              Fix = @Fix " +
                                       "WHERE     (VendorCode = @VendorCode) AND (MaterialCode = @MaterialCode)";
                    cmdEdit.Parameters.Add("@VendorCode", SqlDbType.NVarChar, 10);
                    cmdEdit.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15);
                    cmdEdit.Parameters.Add("@Fix", SqlDbType.Bit);

                    for (Int32 i = 0; i < this.dgvView.RowCount; i++)
                    {
                        cmdEdit.Parameters["@VendorCode"].Value   = this.dgvView["clnVendorCode", i].Value.ToString();
                        cmdEdit.Parameters["@MaterialCode"].Value = this.txtMaterialCode.Text.Trim();
                        cmdEdit.Parameters["@Fix"].Value          = ((bool)this.dgvView["clnFix", i].Value);

                        cmdEdit.Connection = oConn; cmdEdit.CommandText = NP_Cls.SqlInsert; cmdEdit.Transaction = Tr;
                        cmdEdit.ExecuteNonQuery();
                    }
                    Tr.Commit();
                    DGV(string.Empty); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Save Change Completed !!"); this.txtMaterialCode.Select();
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Save : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #7
0
    private void btnDelAll_Click(object sender, EventArgs e)
    {
        if (this.dgvView.RowCount == 0)
        {
            NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Data Not Found !!"); return;
        }
        if (NP.MSGB("Do you want to delete all data ?") == DialogResult.Yes)
        {
            oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
            if (oConn.State == ConnectionState.Open)
            {
                oConn.Close();
            }
            oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction();
            try
            {
                SqlCommand cmdDel = new SqlCommand();
                NP_Cls.SqlDel = "DELETE FROM t_BOMDetail WHERE (BOMCode = @BOMCode)";
                cmdDel.Parameters.Add("@BOMCode", SqlDbType.Int).Value = NP_Cls.strBOMCode;
                cmdDel.Connection = oConn; cmdDel.CommandText = NP_Cls.SqlDel; cmdDel.Transaction = Tr;
                cmdDel.ExecuteNonQuery();

                NP_Cls.SqlDel     = "DELETE FROM t_BOM WHERE (BOMCode = @BOMCode)";
                cmdDel.Connection = oConn; cmdDel.CommandText = NP_Cls.SqlDel; cmdDel.Transaction = Tr;
                cmdDel.ExecuteNonQuery();

                if (NP._TRanSave(oConn, Tr, NP_Cls.NPTranType.Delete, "t_BOM:t_BOMDetail", NP_Cls.strUsr))
                {
                    //Tr.Commit(); this.gMaster.Enabled = true; this.btnUnLock.Visible = false; /*this.btnLock.Visible = true;*/
                    this.cbComponent.Enabled = true; this.cbComponent.SelectedIndex = 0; this.lblCode.Text = string.Empty; this.txtQtyComp.Text = string.Empty;
                    this.Clear(); DGV();
                    NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Delete All Completed !!");
                }
                else
                {
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Try agian !!"); return;
                }
            }
            catch (Exception ex)
            {
                if (oConn.State == ConnectionState.Open)
                {
                    Tr.Rollback();
                }
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Delete : " + ex.Message); return;
            }
            finally
            {
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
            }
        }
        else
        {
            return;
        }
    }
예제 #8
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.dgvView.RowCount == 0)
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Data Not Found !!"); return;
            }
            if (NP.MSGB("Do you want to delete BOM ?") == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction();
                try
                {
                    SqlCommand cmdDel = new SqlCommand();
                    NP_Cls.SqlDel = "DELETE FROM t_BOM WHERE (BOMCode = @BOMCode)";
                    cmdDel.Parameters.Add("@BOMCode", SqlDbType.Int).Value = Convert.ToInt32(this.dgvView["clnBOMCode", this.dgvView.CurrentRow.Index].Value.ToString());
                    cmdDel.Connection = oConn; cmdDel.CommandText = NP_Cls.SqlDel; cmdDel.Transaction = Tr;
                    cmdDel.ExecuteNonQuery();

                    NP_Cls.SqlDel = "DELETE FROM t_BOMDetail WHERE (BOMCode = @BOMCode)";
                    //cmdDel.Parameters.Add("@BOMCode", SqlDbType.Int).Value = Convert.ToInt32(this.dgvView["clnBOMCode", this.dgvView.CurrentRow.Index].Value.ToString());
                    cmdDel.Connection = oConn; cmdDel.CommandText = NP_Cls.SqlDel; cmdDel.Transaction = Tr;
                    cmdDel.ExecuteNonQuery();

                    if (NP._TRanSave(oConn, Tr, NP_Cls.NPTranType.Delete, "t_BOM:t_BOMDetail", NP_Cls.strUsr))
                    {
                        Tr.Commit();
                        DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Delete Completed !!");
                    }
                    else
                    {
                        NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Try agian !!"); return;
                    }
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Delete : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #9
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (NP.MSGB("Do you want to delete ?") == DialogResult.Yes)
            {
                if (this.dgvView.RowCount == 0)
                {
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Data Not Found !!"); return;
                }

                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction();
                try
                {
                    SqlCommand cmdEdit = new SqlCommand();
                    NP_Cls.SqlDel = "DELETE FROM t_VendorInfoRecordPeriodsDetail WHERE (ValidPeriodDetailCode = @ValidPeriodDetailCode) AND (ValidPeriodCode = @ValidPeriodCode)";
                    cmdEdit.Parameters.Add("@ValidPeriodDetailCode", SqlDbType.Int).Value = this.dgvView[0, this.dgvView.CurrentRow.Index].Value.ToString();
                    cmdEdit.Parameters.Add("@ValidPeriodCode", SqlDbType.Int).Value       = this.dgvView[1, this.dgvView.CurrentRow.Index].Value.ToString();
                    cmdEdit.Connection = oConn; cmdEdit.CommandText = NP_Cls.SqlDel; cmdEdit.Transaction = Tr;
                    cmdEdit.ExecuteNonQuery();

                    if (NP._TRanSave(oConn, Tr, NP_Cls.NPTranType.Delete, "t_VendorInfoRecordPeriodsDetail", NP_Cls.strUsr))
                    {
                        Tr.Commit();
                        Clear(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Delete Data Completed !!");
                        this.btnAdd.Visible = true; this.btnEdit.Visible = false; this.txtScaleQty.Select();
                    }
                    else
                    {
                        NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Try agian !!"); return;
                    }
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Delete : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #10
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (NP.MSGB("Do you want to delete ?") == DialogResult.Yes)
            {
                if (this.dgvView.RowCount == 0)
                {
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Data Not Found !!"); return;
                }

                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction();
                try
                {
                    SqlCommand cmdEdit = new SqlCommand();
                    NP_Cls.SqlDel = "DELETE FROM t_VendorInfoRecord WHERE (VendorCode = @VendorCode) AND (MaterialCode = @MaterialCode)";
                    cmdEdit.Parameters.Add("@VendorCode", SqlDbType.NVarChar, 10).Value   = this.dgvView[0, this.dgvView.CurrentRow.Index].Value.ToString();
                    cmdEdit.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15).Value = this.dgvView[1, this.dgvView.CurrentRow.Index].Value.ToString();
                    cmdEdit.Connection = oConn; cmdEdit.CommandText = NP_Cls.SqlDel; cmdEdit.Transaction = Tr;
                    cmdEdit.ExecuteNonQuery();

                    NP_Cls.SqlDel      = "DELETE FROM t_VendorSourceList WHERE (VendorCode = @VendorCode) AND (MaterialCode = @MaterialCode)";
                    cmdEdit.Connection = oConn; cmdEdit.CommandText = NP_Cls.SqlDel; cmdEdit.Transaction = Tr;
                    cmdEdit.ExecuteNonQuery();

                    Tr.Commit();
                    Clear(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Delete Data Completed !!"); this.cbVendor.Select();
                    this.btnAdd.Visible = true; this.btnEdit.Visible = false; this.cbVendor.Enabled = true; this.cbMaterial.Enabled = true; this.cbVendor.Select();
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Delete : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #11
0
        //Método para cadastrar Cliente e Endereco
        public void Salvar(Cliente c)
        {
            try
            {
                AbrirConexao();
                Tr = Con.BeginTransaction(); //iniciando uma transação

                //gravando os dados do Cliente
                Cmd = new SqlCommand("insert into Cliente(Nome, Email, DataCadastro) values(@v1, @v2, @v3)", Con, Tr);
                Cmd.Parameters.AddWithValue("@v1", c.Nome);
                Cmd.Parameters.AddWithValue("@v2", c.Email);
                Cmd.Parameters.AddWithValue("@v3", c.DataCadastro);
                Cmd.ExecuteNonQuery(); //executando

                //resgatar o id do cliente que foi cadastrado
                Cmd = new SqlCommand("select ident_current('Cliente') as Codigo", Con, Tr);
                Dr  = Cmd.ExecuteReader();                      //executa e retorna registros

                if (Dr.Read())                                  //verificando se o DataReader obteve algum registro
                {
                    int Codigo = Convert.ToInt32(Dr["Codigo"]); //leitura do Id do Cliente
                    Dr.Close();                                 //fechando o DataReader

                    //gravando o endereço
                    Cmd = new SqlCommand("insert into Endereco(Logradouro, Cep, IdCliente) values(@v1, @v2, @v3)", Con, Tr);
                    Cmd.Parameters.AddWithValue("@v1", c.Residencia.Logradouro);
                    Cmd.Parameters.AddWithValue("@v2", c.Residencia.Cep);
                    Cmd.Parameters.AddWithValue("@v3", Codigo); //chave estrangeira
                    Cmd.ExecuteNonQuery();                      //executar
                }
                else
                {
                    throw new Exception(); //forçar um erro!
                }

                Tr.Commit(); //executando a transação
            }
            catch (Exception e)
            {
                Tr.Rollback(); //desfazer a transação
                throw new Exception("Erro ao salvar cliente: " + e.Message);
            }
            finally
            {
                FecharConexao();
            }
        }
 public void Excluir(int idFormulario, int idPergunta)
 {
     try
     {
         AbrirConexao();
         Tr  = Con.BeginTransaction();
         Cmd = new SqlCommand("DELETE FROM Formulario.PerguntasPorFormularios WHERE IdFormulario = " + idFormulario + " and IdPergunta =" + idPergunta, Con, Tr);
         Cmd.ExecuteNonQuery();
         Tr.Commit();
     }
     catch (Exception ex)
     {
         if (Tr != null)
         {
             Tr.Rollback(); // Desfaz a transação..
         }
         throw new Exception("Não foi possível remover a pergunta: " + ex.Message);
     }
 }
예제 #13
0
 public void Excluir(int id)
 {
     try
     {
         AbrirConexao();
         Tr  = Con.BeginTransaction();
         Cmd = new SqlCommand("DELETE FROM Formulario.Perguntas WHERE IdPergunta = @v1", Con, Tr);
         Cmd.Parameters.AddWithValue("@v1", id);
         Cmd.ExecuteNonQuery();
         Tr.Commit();
     }
     catch (Exception)
     {
         if (Tr != null)
         {
             Tr.Rollback(); // Desfaz a transação..
         }
         throw new Exception("Erro: Pergunta pertence a algum formulário!");
     }
 }
예제 #14
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if ((string.IsNullOrEmpty((this.cbProdOrder.Text.Trim()))) || (this.cbProdOrder.Text.Trim() == "((( Select Production Order )))"))
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please select Production Order: !!"); this.cbProdOrder.Select(); return;
            }
            if ((string.IsNullOrEmpty((this.cbWorkCenter.Text.Trim()))) || (this.cbWorkCenter.Text.Trim() == "((( Select WorkCenter )))"))
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please select Work Center: !!"); this.cbWorkCenter.Select(); return;
            }
            if (!NP.ReqField(this.txtMachine, "Please enter Used Machine !!"))
            {
                return;
            }
            if (!NP.ReqField(this.txtSetup, "Please enter Used Setup !!"))
            {
                return;
            }
            if (!NP.ReqField(this.txtLabor, "Please enter Used Labor !!"))
            {
                return;
            }
            if (!NP.ReqField(this.txtOT, "Please enter Used OT !!"))
            {
                return;
            }

            if (NP.MSGB("Do you want to Close Production Order ?") == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction();
                try
                {
                    SqlCommand cmdIns = new SqlCommand();

                    NP_Cls.SqlInsert = "INSERT INTO t_ProductionCost  (PrdONumber, MaterialCode, PlantCode, WorkCenterCode, UsedMachine, UsedSetup, UsedLabor, UsedOT, UserCreate, DateCreate) VALUES (@PrdONumber, @MaterialCode, @PlantCode, @WorkCenterCode, @UsedMachine, @UsedSetup, @UsedLabor, @UsedOT, @UserCreate, GETDATE())";
                    cmdIns.Parameters.Add("@PrdONumber", SqlDbType.NVarChar, 12).Value     = this.cbProdOrder.SelectedValue;
                    cmdIns.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15).Value   = this.lblMaterialCode.Text.Trim();
                    cmdIns.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4).Value       = this.lblPlantCode.Text.Trim();
                    cmdIns.Parameters.Add("@WorkCenterCode", SqlDbType.NVarChar, 10).Value = this.cbWorkCenter.SelectedValue;
                    cmdIns.Parameters.Add("@UsedMachine", SqlDbType.Decimal).Value         = decimal.Parse(this.txtMachine.Text.Trim());
                    cmdIns.Parameters.Add("@UsedSetup", SqlDbType.Decimal).Value           = decimal.Parse(this.txtSetup.Text.Trim());
                    cmdIns.Parameters.Add("@UsedLabor", SqlDbType.Decimal).Value           = decimal.Parse(this.txtLabor.Text.Trim());
                    cmdIns.Parameters.Add("@UsedOT", SqlDbType.Decimal).Value          = decimal.Parse(this.txtOT.Text.Trim());
                    cmdIns.Parameters.Add("@UserCreate", SqlDbType.NVarChar, 50).Value = NP_Cls.strUsr;
                    cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                    cmdIns.ExecuteNonQuery();

                    // By NP - 2.7.13 - No reason to flag GI Change to OrderStatus = Close
                    NP_Cls.sqlUpdate  = "UPDATE t_PrdOrderDetail SET IsGIClose = 1 WHERE (PrdONumber = @PrdONumber)";
                    cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.sqlUpdate; cmdIns.Transaction = Tr;
                    cmdIns.ExecuteNonQuery();

                    NP_Cls.sqlUpdate  = "UPDATE t_PrdOrder SET OrderStatus = 'Close' WHERE (PrdONumber = @PrdONumber)";
                    cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.sqlUpdate; cmdIns.Transaction = Tr;
                    cmdIns.ExecuteNonQuery();

                    Tr.Commit();
                    Clear(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Close Completed !!");
                    this.cbProdOrder.Select();
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Close : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #15
0
파일: frmDO.cs 프로젝트: yuanyuan0318/WMS
        private void btnAppr_Click(object sender, EventArgs e)
        {
            if (NP.MSGB("Do you want Approve Delivery Order ?") == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr;
                Tr = oConn.BeginTransaction();

                try
                {
                    SqlCommand cmdUpdateStock = new SqlCommand();
                    cmdUpdateStock.Parameters.Add("@Qty", SqlDbType.Decimal);
                    cmdUpdateStock.Parameters.Add("@BatchNumber", SqlDbType.NVarChar, 15);
                    cmdUpdateStock.Parameters.Add("@outputInt", SqlDbType.Int).Direction = ParameterDirection.Output;

                    cmdUpdateStock.Connection  = oConn;
                    cmdUpdateStock.CommandType = CommandType.StoredProcedure;

                    for (byte ins = 0; ins < this.dgvView.RowCount; ins++)
                    {
                        string getSONumberID = this.dgvView["clnAutoID", ins].Value.ToString();

                        NP_Cls.SqlSelect = "SELECT SONumber, BatchNumber, Qty FROM tmp_DOforApprove WHERE (SOAutoID = N'" + getSONumberID + "')";
                        DataSet ds = new DataSet(); ds = NP.GetClientDataSet(NP_Cls.SqlSelect);

                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            cmdUpdateStock.Parameters["@Qty"].Value         = ds.Tables[0].Rows[i]["Qty"].ToString();
                            cmdUpdateStock.Parameters["@BatchNumber"].Value = ds.Tables[0].Rows[i]["BatchNumber"].ToString();
                            cmdUpdateStock.CommandText = "UpdateStockWhenApproveDO";
                            cmdUpdateStock.Transaction = Tr;
                            cmdUpdateStock.ExecuteNonQuery();
                            if (Convert.ToInt32(cmdUpdateStock.Parameters["@OutputInt"].Value) != 1)
                            {
                                Tr.Rollback();
                            }
                        }
                        NP_Cls.SqlDel = "DELETE FROM tmp_DOforApprove WHERE (SOAutoID = '" + getSONumberID + "')"; string strErr1 = string.Empty;
                        if (!NP.SqlCmd(NP_Cls.SqlDel, ref strErr1))
                        {
                            NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Delete : " + strErr1); return;
                        }
                    }

                    Tr.Commit();
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Save : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }

                NP_Cls.sqlUpdate = "UPDATE t_DO SET DOApprove = 1, UserUpdate = '" + NP_Cls.strUsr + "', DateUpdate = GETDATE() WHERE (DONumber = '" + this.txtDO.Text.Trim() + "')"; string strErr = string.Empty;
                if (!NP.SqlCmd(NP_Cls.sqlUpdate, ref strErr))
                {
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Approve : " + strErr); return;
                }

                Clear(); this.txtDO.DropDownStyle = ComboBoxStyle.Simple; this.cbCustomer.Enabled = true;
                this.groupPR.Enabled = true; this.btnAddSO.Visible = true; this.btnSave.Visible = false; this.cbSO.Text = string.Empty; this.cbSO.DataSource = null; this.cbMaterial.DataSource = null; this.cbMaterial.Text = string.Empty;
                this.MyGrid(dgvView); this.txtDO.Text = GetNumber(); this.btnAppr.Visible = false;
                this.cbCustomer.Text = string.Empty; this.cbCustomer.Select(); this.cbCustomer.SelectAll();
            }
            else
            {
                return;
            }
        }
예제 #16
0
파일: frmDO.cs 프로젝트: yuanyuan0318/WMS
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.dgvView.RowCount == 0)
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please select SO Number into DO list !!"); this.cbSO.Select(); return;
            }
            this.dgvView.EndEdit(); this.lessStock = 0;

            for (byte ii = 0; ii < this.dgvView.RowCount; ii++)
            {
                // Check Not add batch number
                if (string.IsNullOrEmpty(this.dgvView["clnBatchNumber", ii].Value.ToString()))
                {
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Mat.Code : " + this.dgvView["clnMaterialCode", ii].Value.ToString() + " dose not add Batch Number !!\nCannot DO. !!"); return;
                }

                // Check Quantity
                if (Convert.ToDouble(this.dgvView["clnQuantity", ii].Value) > Convert.ToDouble(this.dgvView["clnTmpSO", ii].Value))
                {
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Mat.Code : " + this.dgvView["clnMaterialCode", ii].Value.ToString() + " is over SO Qty !!\nCannot DO. !!"); return;
                }
                else
                {
                    if (Convert.ToDouble(this.dgvView["clnQuantity", ii].Value) > Convert.ToDouble(this.dgvView["clnFGStock", ii].Value))
                    {
                        NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Mat.Code : " + this.dgvView["clnMaterialCode", ii].Value.ToString() + " is over Stock !!\nCannot DO. !!"); return;
                    }
                    else if (Convert.ToDouble(this.dgvView["clnQuantity", ii].Value) <= Convert.ToDouble(this.dgvView["clnFGStock", ii].Value))
                    {
                        this.lessStock = 1;
                    }
                }
            }



            string strQuestion = string.Empty;

            if (this.lessStock == 0)
            {
                strQuestion = "Do you want to Save Delivery Order ?";
            }
            else
            {
                strQuestion = "Do you want to Save Delivery Order with less stock Material ?";
            }

            if (NP.MSGB(strQuestion) == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr;
                Tr = oConn.BeginTransaction();

                try
                {
                    SqlCommand cmdIns = new SqlCommand(); SqlCommand cmdInsertTmpStock = new SqlCommand();
                    NP_Cls.SqlInsert = "INSERT INTO t_DODetail (DONumber, MaterialCode, MaterialName, DOQuantity, UnitCode, UnitName, NetPrice, DOAmount, DeliveryDate, PlantCode, PlantName, LocCode, LocName, CurrentUser, SONumber, SOAutoID) " +
                                       "VALUES     (@DONumber,@MaterialCode,@MaterialName,@DOQuantity,@UnitCode,@UnitName,@NetPrice,@DOAmount,@DeliveryDate,@PlantCode,@PlantName,@LocCode,@LocName,@CurrentUser,@SONumber,@SOID)";
                    cmdIns.Parameters.Add("@DONumber", SqlDbType.NVarChar, 12);
                    cmdIns.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15);
                    cmdIns.Parameters.Add("@MaterialName", SqlDbType.NVarChar, 60);
                    cmdIns.Parameters.Add("@DOQuantity", SqlDbType.Decimal);
                    cmdIns.Parameters.Add("@UnitCode", SqlDbType.NVarChar, 3);
                    cmdIns.Parameters.Add("@UnitName", SqlDbType.NVarChar, 20);
                    cmdIns.Parameters.Add("@NetPrice", SqlDbType.Decimal);
                    cmdIns.Parameters.Add("@DOAmount", SqlDbType.Decimal);
                    cmdIns.Parameters.Add("@DeliveryDate", SqlDbType.DateTime);
                    cmdIns.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4);
                    cmdIns.Parameters.Add("@PlantName", SqlDbType.NVarChar, 20);
                    cmdIns.Parameters.Add("@LocCode", SqlDbType.NVarChar, 2);
                    cmdIns.Parameters.Add("@LocName", SqlDbType.NVarChar, 20);
                    cmdIns.Parameters.Add("@CurrentUser", SqlDbType.NVarChar, 50);
                    cmdIns.Parameters.Add("@SONumber", SqlDbType.NVarChar, 12);
                    cmdIns.Parameters.Add("@SOID", SqlDbType.Int);

                    for (byte ins = 0; ins < this.dgvView.RowCount; ins++)
                    {
                        if (Convert.ToDecimal(this.dgvView["clnQuantity", ins].Value) <= Convert.ToDecimal(this.dgvView["clnFGStock", ins].Value))
                        {
                            cmdIns.Parameters["@DONumber"].Value     = this.strGNumber;
                            cmdIns.Parameters["@MaterialCode"].Value = this.dgvView["clnMaterialCode", ins].Value.ToString();
                            cmdIns.Parameters["@MaterialName"].Value = this.dgvView["clnMaterialName", ins].Value.ToString();
                            cmdIns.Parameters["@DOQuantity"].Value   = Convert.ToInt32(this.dgvView["clnQuantity", ins].Value);
                            cmdIns.Parameters["@UnitCode"].Value     = this.dgvView["clnUnitCode", ins].Value.ToString();
                            cmdIns.Parameters["@UnitName"].Value     = this.dgvView["clnUnitName", ins].Value.ToString();
                            cmdIns.Parameters["@NetPrice"].Value     = Convert.ToDecimal(this.dgvView["clnNetPrice", ins].Value);
                            cmdIns.Parameters["@DOAmount"].Value     = Convert.ToDecimal(this.dgvView["clnAmount", ins].Value);
                            cmdIns.Parameters["@CurrentUser"].Value  = NP_Cls.strUsr;
                            cmdIns.Parameters["@DeliveryDate"].Value = Convert.ToDateTime(this.dgvView["clnDeliveryDate", ins].Value);
                            cmdIns.Parameters["@PlantCode"].Value    = this.dgvView["clnPlantCode", ins].Value.ToString();
                            cmdIns.Parameters["@PlantName"].Value    = this.dgvView["clnPlantName", ins].Value.ToString();
                            cmdIns.Parameters["@LocCode"].Value      = this.dgvView["clnLocCode", ins].Value.ToString();
                            cmdIns.Parameters["@LocName"].Value      = this.dgvView["clnLocName", ins].Value.ToString();
                            cmdIns.Parameters["@SONumber"].Value     = this.dgvView["clnSONumber", ins].Value.ToString();
                            cmdIns.Parameters["@SOID"].Value         = this.dgvView["clnAutoID", ins].Value.ToString();


                            cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                            cmdIns.ExecuteNonQuery();

                            NP_Cls.sqlUpdate  = "UPDATE t_SODetail SET DOQuantity = DOQuantity + @DOQuantity WHERE (SONumber = @SONumber) AND (AutoID = @SOID)";
                            cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.sqlUpdate; cmdIns.Transaction = Tr;
                            cmdIns.ExecuteNonQuery();
                        }
                    }
                    #region Insert tmp for do
                    NP_Cls.SqlInsert = "INSERT INTO [tmp_DOforApprove] (SONumber ,BatchNumber ,Qty, SOAutoID) VALUES (@SONumber, @BatchNumber, @Qty, @SOAutoID)";
                    cmdInsertTmpStock.Parameters.Add("@SONumber", SqlDbType.NVarChar, 12);
                    cmdInsertTmpStock.Parameters.Add("@BatchNumber", SqlDbType.NVarChar, 10);
                    cmdInsertTmpStock.Parameters.Add("@SOAutoID", SqlDbType.Int);
                    cmdInsertTmpStock.Parameters.Add("@Qty", SqlDbType.Decimal);
                    for (int i = 0; i < this.dsBatch.Tables[0].Rows.Count; i++)
                    {
                        cmdInsertTmpStock.Parameters["@SONumber"].Value    = this.dsBatch.Tables[0].Rows[i]["SONumber"].ToString();
                        cmdInsertTmpStock.Parameters["@BatchNumber"].Value = this.dsBatch.Tables[0].Rows[i]["BatchNumber"].ToString();
                        cmdInsertTmpStock.Parameters["@SOAutoID"].Value    = this.dsBatch.Tables[0].Rows[i]["SOAutoID"].ToString();
                        cmdInsertTmpStock.Parameters["@Qty"].Value         = Convert.ToDecimal(this.dsBatch.Tables[0].Rows[i]["Qty"]);
                        cmdInsertTmpStock.Connection = oConn; cmdInsertTmpStock.CommandText = NP_Cls.SqlInsert; cmdInsertTmpStock.Transaction = Tr;
                        cmdInsertTmpStock.ExecuteNonQuery();
                    }
                    #endregion


                    if (this.lessStock == 0)
                    {
                        strQuestion = "Save Delivery Order Completed !!";
                    }
                    else
                    {
                        strQuestion = "Save Delivery Order with less stock Material Completed !!";
                    }
                    Tr.Commit(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, strQuestion);
                    Clear();
                    this.groupPR.Enabled = true; this.btnAddSO.Visible = true; this.btnSave.Visible = false; this.cbSO.Text = string.Empty; this.cbSO.DataSource = null; this.cbMaterial.DataSource = null; this.cbMaterial.Text = string.Empty;
                    this.dsPR.Tables.Clear(); this.MyGrid(dgvView); this.txtDO.DropDownStyle = ComboBoxStyle.Simple;
                    BindCBCustomer();
                    this.cbCustomer.Enabled = true; this.txtDO.Text = GetNumber(); this.btnAppr.Visible = false;
                    this.cbCustomer.Text    = string.Empty; this.cbCustomer.Select(); this.cbCustomer.SelectAll();
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Save : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #17
0
파일: frmGI.cs 프로젝트: yuanyuan0318/WMS
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.dgvView.RowCount == 0)
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please select material into GI list !!"); this.cbMaterial.Select(); return;
            }
            this.dgvView.EndEdit(); this.dgvView.Sort(this.dgvView.Columns["clnMaterialCode"], ListSortDirection.Ascending);
            for (byte ii = 0; ii < this.dgvView.RowCount; ii++)
            {
                if (Convert.ToDouble(this.dgvView["clnQuantity", ii].Value) == 0)
                {
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Quantity for GI must more than 0 !!"); return;
                }
            }

            this.dgvView.EndEdit(); this.lessStock = 0; double dTmp = 0;
            DataTable dtTmp = new DataTable(); dtTmp = this.dsPR.Tables[0].Clone();

            dtTmp.Columns.Remove("ItemNo"); dtTmp.Columns.Remove("UnitCode"); dtTmp.Columns.Remove("UnitName"); dtTmp.Columns.Remove("PlantCode");
            dtTmp.Columns.Remove("PlantName"); dtTmp.Columns.Remove("LocCode"); dtTmp.Columns.Remove("LocName"); dtTmp.Columns.Remove("PrdONumber");
            dtTmp.Columns.Remove("MaterialName");  dtTmp.Columns.Remove("BatchNumber");

            Hashtable hsTmp = new Hashtable();

            for (int mm = 0; mm < this.dgvView.RowCount; mm++)
            {
                try
                {
                    hsTmp.Add(this.dsPR.Tables[0].Rows[mm]["MaterialCode"].ToString(), dsPR.Tables[0].Compute("SUM(Qty)", "MaterialCode = " + dsPR.Tables[0].Rows[mm]["MaterialCode"].ToString()));
                    DataRow dr; dr = dtTmp.NewRow();
                    dr[0] = this.dsPR.Tables[0].Rows[mm]["MaterialCode"].ToString(); dr[1] = hsTmp[this.dsPR.Tables[0].Rows[mm]["MaterialCode"].ToString()];
                    dr[2] = Convert.ToDouble(this.dsPR.Tables[0].Rows[mm]["PrdOQty"]); dr[3] = dsPR.Tables[0].Compute("SUM(QI)", "MaterialCode = " + dsPR.Tables[0].Rows[mm]["MaterialCode"].ToString()); dtTmp.Rows.Add(dr);
                }
                catch
                { }
            }
            dtTmp.AcceptChanges();

            for (int ii = 0; ii < dtTmp.Rows.Count; ii++)
            {
                if (Convert.ToDouble(dtTmp.Rows[ii]["Qty"]) > Convert.ToDouble(dtTmp.Rows[ii]["PrdOQty"]))
                {
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Mat.Code : " + this.dgvView["clnMaterialCode", ii].Value.ToString() + " is over Prod.Order Qty !!\nCan not GI. !!"); return;
                }
                else
                {
                    if (Convert.ToDouble(dtTmp.Rows[ii]["Qty"]) > Convert.ToDouble(dtTmp.Rows[ii]["QI"]))
                    {
                        NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Mat.Code : " + this.dgvView["clnMaterialCode", ii].Value.ToString() + " is over Stock !!\nCan not GI. !!"); return;
                    }
                    else if (Convert.ToDouble(dtTmp.Rows[ii]["QI"]) == 0)
                    {
                        NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Mat.Code : " + this.dgvView["clnMaterialCode", ii].Value.ToString() + " Stock is 0 !!\nCan not GI. !!"); return;
                    }
                    else if (Convert.ToDouble(dtTmp.Rows[ii]["Qty"]) < Convert.ToDouble(dtTmp.Rows[ii]["QI"]))
                    {
                        this.lessStock = 1;
                    }
                }
            }

            string strQuestion = string.Empty;

            if (this.lessStock == 0)
            {
                strQuestion = "Do you want to Save Delivery Order ?";
            }
            else
            {
                strQuestion = "Do you want to Save Delivery Order with less stock Material ?";
            }

            if (NP.MSGB("Do you to Save Goods Issue ?") == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr;
                Tr = oConn.BeginTransaction();

                try
                {
                    SqlCommand cmdIns = new SqlCommand();
                    NP_Cls.SqlInsert = "INSERT INTO t_StockMovementDetail " +
                                       "(AutoID, DocNumber, MaterialCode, MaterialName, Quantity, UnitCode, UnitName, PlantCode, PlantName, LocCode, LocName, CurrentUser, RefNumber, BatchNumber) " +
                                       "VALUES     (@ID, @GINumber,@MaterialCode,@MaterialName,@GIQuantity,@UnitCode,@UnitName,@PlantCode,@PlantName,@LocCode,@LocName,@CurrentUser,@PrdONumber, @BatchNumber)";
                    cmdIns.Parameters.Add("@ID", SqlDbType.Int);
                    cmdIns.Parameters.Add("@GINumber", SqlDbType.NVarChar, 12);
                    cmdIns.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15);
                    cmdIns.Parameters.Add("@MaterialName", SqlDbType.NVarChar, 60);
                    cmdIns.Parameters.Add("@GIQuantity", SqlDbType.Decimal);
                    cmdIns.Parameters.Add("@UnitCode", SqlDbType.NVarChar, 3);
                    cmdIns.Parameters.Add("@UnitName", SqlDbType.NVarChar, 20);
                    cmdIns.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4);
                    cmdIns.Parameters.Add("@PlantName", SqlDbType.NVarChar, 20);
                    cmdIns.Parameters.Add("@LocCode", SqlDbType.NVarChar, 2);
                    cmdIns.Parameters.Add("@LocName", SqlDbType.NVarChar, 20);
                    cmdIns.Parameters.Add("@CurrentUser", SqlDbType.NVarChar, 50); cmdIns.Parameters.Add("@BatchNumber", SqlDbType.NVarChar, 10);
                    cmdIns.Parameters.Add("@PrdONumber", SqlDbType.NVarChar, 12); cmdIns.Parameters.Add("@MRPOrder", SqlDbType.NVarChar, 12);
                    cmdIns.Parameters.Add("@IsGIClose", SqlDbType.Bit); cmdIns.Parameters.Add("@MatHead", SqlDbType.NVarChar, 15);


                    for (byte ins = 0; ins < this.dgvView.RowCount; ins++)
                    {
                        cmdIns.Parameters["@ID"].Value           = ins + 1;
                        cmdIns.Parameters["@GINumber"].Value     = this.strGNumber;
                        cmdIns.Parameters["@MaterialCode"].Value = this.dgvView["clnMaterialCode", ins].Value.ToString();
                        cmdIns.Parameters["@MaterialName"].Value = this.dgvView["clnMaterialName", ins].Value.ToString();
                        cmdIns.Parameters["@GIQuantity"].Value   = Convert.ToDouble(this.dgvView["clnQuantity", ins].Value);
                        cmdIns.Parameters["@UnitCode"].Value     = this.dgvView["clnUnitCode", ins].Value.ToString();
                        cmdIns.Parameters["@UnitName"].Value     = this.dgvView["clnUnitName", ins].Value.ToString();
                        cmdIns.Parameters["@CurrentUser"].Value  = NP_Cls.strUsr;
                        cmdIns.Parameters["@PlantCode"].Value    = this.dgvView["clnPlantCode", ins].Value.ToString();
                        cmdIns.Parameters["@PlantName"].Value    = this.dgvView["clnPlantName", ins].Value.ToString();
                        cmdIns.Parameters["@LocCode"].Value      = this.dgvView["clnLocCode", ins].Value.ToString();
                        cmdIns.Parameters["@LocName"].Value      = this.dgvView["clnLocName", ins].Value.ToString();
                        cmdIns.Parameters["@PrdONumber"].Value   = this.cbPrdoOrder.Text.Trim();
                        cmdIns.Parameters["@IsGIClose"].Value    = 0; cmdIns.Parameters["@MRPOrder"].Value = strMRP;
                        cmdIns.Parameters["@MatHead"].Value      = this.lblHeadMaterial.Text.Trim().Split(':')[0].ToString();
                        cmdIns.Parameters["@BatchNumber"].Value  = this.dgvView["clnBatchNumber", ins].Value.ToString();


                        cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                        cmdIns.ExecuteNonQuery();

                        // Update Stock
                        NP_Cls.sqlUpdate  = "UPDATE t_StockOverview SET QI = QI - @GIQuantity WHERE (BatchNumber = @BatchNumber)";
                        cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.sqlUpdate; cmdIns.Transaction = Tr;
                        cmdIns.ExecuteNonQuery();

                        //TODO 22.11.10 Prd Order from MRP
                        if (!string.IsNullOrEmpty(strMRP))
                        {
                            string strTR = "INSERT INTO t_MRPTranOrder (MaterialCode,TranOrder,TranQty,SONumber,IsComponent,MaterialHeader) VALUES (@MaterialCode,@GINumber,@GIQuantity,@MRPOrder,1,@MatHead)";
                            cmdIns.CommandText = strTR; cmdIns.Connection = oConn;
                            cmdIns.Transaction = Tr; cmdIns.ExecuteNonQuery();
                        }
                        //
                    }

                    //           NP_Cls.sqlUpdate = "UPDATE t_PrdOrderDetail SET GIQty = GIQty + @GIQuantity, IsGIClose = @IsGIClose WHERE (PrdONumber = @PrdONumber) AND (ComponentCode = @MaterialCode)";
                    SqlCommand cmdSP = new SqlCommand();
                    cmdSP.Parameters.Add("@PrdOQty", SqlDbType.Decimal); cmdSP.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15);
                    cmdSP.Parameters.Add("@GIQuantity", SqlDbType.Decimal); cmdSP.Parameters.Add("@IsGIClose", SqlDbType.Bit); cmdSP.Parameters.Add("@PrdONumber", SqlDbType.NVarChar, 12);
                    for (byte up = 0; up < this.dgvView.RowCount; up++)
                    {
                        cmdSP.Parameters["@MaterialCode"].Value = this.dgvView["clnMaterialCode", up].Value.ToString();
                        cmdSP.Parameters["@GIQuantity"].Value   = Convert.ToDouble(this.dgvView["clnQuantity", up].Value);
                        cmdSP.Parameters["@IsGIClose"].Value    = 0; //(Convert.ToDouble(this.dgvView["clnQuantity", up].Value) == ? 1 : 0);
                        cmdSP.Parameters["@PrdOQty"].Value      = Convert.ToDouble(this.dgvView["clnPrdOQty", up].Value);
                        cmdSP.Parameters["@PrdONumber"].Value   = this.cbPrdoOrder.Text.Trim();

                        cmdSP.Connection = oConn; cmdSP.CommandType = CommandType.StoredProcedure; cmdSP.CommandText = "sp_GI_Save"; cmdSP.Transaction = Tr;
                        cmdSP.ExecuteNonQuery();
                    }

                    NP_Cls.SqlSelect  = "SELECT IsGIClose FROM t_PrdOrderDetail WHERE (PrdONumber = @PrdONumber)";
                    cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlSelect; cmdIns.Transaction = Tr;
                    SqlDataAdapter da = new SqlDataAdapter(cmdIns); DataSet ds = new DataSet(); da.Fill(ds); bool bTmp = true;
                    for (int cp = 0; cp < ds.Tables[0].Rows.Count; cp++)
                    {
                        bTmp = bTmp && Convert.ToBoolean(ds.Tables[0].Rows[cp][0]);
                    }

                    NP_Cls.sqlUpdate = "UPDATE t_PrdOrder SET IsGI = @IsGI WHERE (PrdONumber = @PrdONumber)";
                    cmdIns.Parameters.Add("@IsGI", SqlDbType.Bit).Value = bTmp;
                    cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.sqlUpdate; cmdIns.Transaction = Tr;
                    cmdIns.ExecuteNonQuery();



                    Tr.Commit(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Save Goods Issue Completed !!");
                    Clear();
                    this.groupPR.Enabled = true; this.btnAddGI.Visible = true; this.btnSave.Visible = false; this.cbMaterial.Text = string.Empty; this.cbMaterial.DataSource = null;
                    this.dsPR.Tables.Clear(); this.MyGrid(dgvView); this.txtGI.Text = GetNumber();

                    NP_Cls.SqlSelect = "SELECT     MaterialCode + ':' + MaterialName AS MatCode, PrdONumber FROM  t_PrdOrder WHERE (IsGI = 0)";
                    NP.BindCB(this.cbPrdoOrder, NP_Cls.SqlSelect, "MatCode", "PrdONumber", "((( Select Prd Number )))");
                    this.cbPrdoOrder.Text = string.Empty; this.cbPrdoOrder.Select();
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add Detail : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #18
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!NP.ReqField(this.cbPrdOrder, "Please select Production Order first !!"))
            {
                return;
            }
            if (!NP.ReqField(this.txtQty, "Please enter Qty !!"))
            {
                return;
            }
            //if (decimal.Parse(lblPrdQty.Text.Trim()) < decimal.Parse(lblGrPrdQty.Text.Trim()) + decimal.Parse(txtQty.Text.Trim()))
            //{
            //    MessageBox.Show("Quantity must less than " + (decimal.Parse(lblPrdQty.Text.Trim()) - decimal.Parse(lblGrPrdQty.Text.Trim())).ToString(), "Warning !!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            //    txtQty.Focus();
            //    txtQty.Text = (decimal.Parse(lblPrdQty.Text.Trim()) - decimal.Parse(lblGrPrdQty.Text.Trim())).ToString();
            //    return;
            //}
            if (NP.MSGB("Do you to Save GR Production ?") == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr;
                Tr = oConn.BeginTransaction();

                try
                {
                    SqlCommand cmdIns = new SqlCommand(); string strTmpBatch = NP_Cls._genBatch(this.lblMatCode.Text.Trim(), oConn, Tr);
                    NP_Cls.SqlInsert = "INSERT INTO t_StockMovement " +
                                       "(DocNumber, TranDate, MovementType,RefNumber, Remark, UserCreate, DateCreate,PlantCode,PlantName,BOMVersion,LocCode,LocName) " +
                                       "VALUES     (@GRPrdNumber,GETDATE(),@MovementType,@PrdONumber,@Remark,@UC,GETDATE(),@PlantCode,@PlantName,@BOMVersion,@LocCode,@LocName)";
                    cmdIns.Parameters.Add("@GRPrdNumber", SqlDbType.NVarChar, 12).Value = this.txtDocNo.Text.Trim();
                    cmdIns.Parameters.Add("@PrdONumber", SqlDbType.NVarChar, 12).Value  = this.cbPrdOrder.Text.Trim();
                    cmdIns.Parameters.Add("@MovementType", SqlDbType.NVarChar, 3).Value = this.lblMoveType.Text.Trim();
                    cmdIns.Parameters.Add("@GRPrdQty", SqlDbType.Decimal).Value         = Convert.ToDecimal(this.txtQty.Text.Trim());
                    cmdIns.Parameters.Add("@BatchNumber", SqlDbType.NVarChar, 10).Value = strTmpBatch;
                    cmdIns.Parameters.Add("@Remark", SqlDbType.NVarChar, 255).Value     = this.txtRemark.Text.Trim();
                    cmdIns.Parameters.Add("@UC", SqlDbType.NVarChar, 50).Value          = NP_Cls.strUsr;
                    cmdIns.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4).Value    = this.lblPlantCode.Text.Trim();
                    cmdIns.Parameters.Add("@PlantName", SqlDbType.NVarChar, 20).Value   = this.lblPlant.Text.Trim();
                    cmdIns.Parameters.Add("@LocCode", SqlDbType.NVarChar, 2).Value      = this.lblLocCode.Text.Trim();
                    cmdIns.Parameters.Add("@LocName", SqlDbType.NVarChar, 20).Value     = this.lblLoc.Text.Trim();
                    cmdIns.Parameters.Add("@BOMVersion", SqlDbType.Int).Value           = Convert.ToInt32(this.lblBomVer.Text.Trim());
                    cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                    cmdIns.ExecuteNonQuery();

                    NP_Cls.SqlInsert = "INSERT INTO t_StockMovementDetail " +
                                       "(AutoID, DocNumber, RefNumber, MaterialCode, MaterialName, Quantity, BatchNumber, CurrentUser, LogDate,PlantCode,PlantName,LocCode,LocName,UnitCode,UnitName) " +
                                       "VALUES     (1, @GRPrdNumber,@PrdONumber,@MaterialCode, @MaterialName,@GRPrdQty,@BatchNumber, @UC, GETDATE(),@PlantCode,@PlantName,@LocCode,@LocName,@UnitCode,@UnitName)";
                    cmdIns.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15).Value = this.lblMatCode.Text.Trim();
                    cmdIns.Parameters.Add("@MaterialName", SqlDbType.NVarChar, 60).Value = this.lblMaterialName.Text.Trim();
                    cmdIns.Parameters.Add("@UnitCode", SqlDbType.NVarChar, 3).Value      = this.lblUnitCode.Text.Trim();
                    cmdIns.Parameters.Add("@UnitName", SqlDbType.NVarChar, 20).Value     = this.lblUnitName.Text.Trim();
                    cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                    cmdIns.ExecuteNonQuery();

                    NP_Cls.SqlInsert  = "INSERT INTO [dbo].[t_GRPrd] ([GRPrdNumber]  ,[PrdONumber]  ,[GRPrdDate]  ,[MovementType]  ,[GRPrdQty]  ,[BatchNumber]  ,[Remark]  ,[UserCreate]  ,[DateCreate]  )       VALUES  (@GRPrdNumber  ,@PrdONumber  ,GETDATE()  ,@MovementType  ,@GRPrdQty  ,@BatchNumber  ,@Remark  ,@UC  ,GetDate())";
                    cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                    cmdIns.ExecuteNonQuery();

                    //TODO Save in Stock Overview // 16.11.10
                    string strTmp = "INSERT INTO t_StockOverview (MaterialCode, BatchNumber, UR, QI, Block, UserCreate, DateCreate, Cost,PlantCode,LocCode,OrigQty,UnitCode) VALUES (@MaterialCode,@BatchNumber,@UR,@QI,@Block,@UC, GETDATE(), @Cost,@PlantCode,@LocCode,@OrigQty,@UnitCode)";

                    //cmdIns.Parameters["@BatchNumber"].Value = strTmpBatch;
                    cmdIns.Parameters.Add("@UR", SqlDbType.Decimal).Value      = 0;
                    cmdIns.Parameters.Add("@QI", SqlDbType.Decimal).Value      = Convert.ToDecimal(this.txtQty.Text.Trim());
                    cmdIns.Parameters.Add("@Block", SqlDbType.Decimal).Value   = 0;
                    cmdIns.Parameters.Add("@Cost", SqlDbType.Decimal).Value    = getCost(oConn, Tr, this.lblMatCode.Text.Trim());
                    cmdIns.Parameters.Add("@OrigQty", SqlDbType.Decimal).Value = Convert.ToDecimal(this.txtQty.Text.Trim());
                    cmdIns.Connection = oConn; cmdIns.CommandText = strTmp; cmdIns.Transaction = Tr;
                    cmdIns.ExecuteNonQuery();



                    strTmp            = "UPDATE t_PrdOrder SET GrPrdQuantity = Isnull(GrPrdQuantity,0) + @QI WHERE (PrdONumber = @PrdONumber)";
                    cmdIns.Connection = oConn; cmdIns.CommandText = strTmp; cmdIns.Transaction = Tr;
                    cmdIns.ExecuteNonQuery();

                    if (decimal.Parse(lblPrdQty.Text.Trim()) <= decimal.Parse(lblGrPrdQty.Text.Trim()) + decimal.Parse(txtQty.Text.Trim()))
                    {
                        strTmp            = "UPDATE t_MRPTranOrder SET IsCompleted = 1 WHERE (MaterialHeader = @MaterialCode) AND (TranOrder = @PrdONumber)";
                        cmdIns.Connection = oConn; cmdIns.CommandText = strTmp; cmdIns.Transaction = Tr;
                        cmdIns.ExecuteNonQuery();

                        strTmp            = "UPDATE t_PrdOrder SET ISGRPrd = 1 WHERE (PrdONumber = @PrdONumber)";
                        cmdIns.Connection = oConn; cmdIns.CommandText = strTmp; cmdIns.Transaction = Tr;
                        cmdIns.ExecuteNonQuery();
                    }

                    Tr.Commit(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Save GR Production Completed !!");
                    Clear();

                    this.txtDocNo.Text = GetNumber();
                    BindMat();
                    this.cbPrdOrder.Text = string.Empty; this.cbPrdOrder.Select();
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add Detail : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #19
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.dgvView.RowCount == 0)
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please select material into transfer list !!"); this.cbMaterial.Select(); return;
            }
            this.dgvView.EndEdit();

            // Check Transfer
            for (int i = 0; i < this.dgvView.Rows.Count; i++)
            {
                if (Convert.ToDecimal(dgvView["clnTranQuantity", i].Value) <= 0)
                {
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Transfer Quantity must be more than 0 !!"); return;
                }
            }

            for (int i = 0; i < this.dgvView.RowCount; i++)
            {
                switch (this.cbMovType.Text.Trim().Split(':')[0])
                {
                case "321":
                    // QI > UR
                    if (double.Parse(this.dgvView["clnTranQuantity", i].Value.ToString()) > double.Parse(this.dgvView["clnQI", i].Value.ToString()))
                    {
                        NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Transfet Quantity more than QI !!"); this.dgvView.CancelEdit(); return;
                    }
                    break;

                case "322":
                    // UR > QI
                    if (double.Parse(this.dgvView["clnTranQuantity", i].Value.ToString()) > double.Parse(this.dgvView["clnUR", i].Value.ToString()))
                    {
                        NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Transfet Quantity more than UR !!"); this.dgvView.CancelEdit(); return;
                    }
                    break;

                case "349":
                    // Block > QI
                    if (double.Parse(this.dgvView["clnTranQuantity", i].Value.ToString()) > double.Parse(this.dgvView["clnBlock", i].Value.ToString()))
                    {
                        NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Transfet Quantity more than Block !!"); this.dgvView.CancelEdit(); return;
                    }
                    break;

                case "350":
                    // QI > Block
                    if (double.Parse(this.dgvView["clnTranQuantity", i].Value.ToString()) > double.Parse(this.dgvView["clnQI", i].Value.ToString()))
                    {
                        NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Transfet Quantity more than QI !!"); this.dgvView.CancelEdit(); return;
                    }
                    break;

                default:
                    NP.MSGB(NP_Cls.NPMgsStyle.Invalid, "Not found type to transfer !!");
                    break;
                }
            }

            if (NP.MSGB("Do you to Save Transfer Stock ?") == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr;
                Tr = oConn.BeginTransaction();

                try
                {
                    SqlCommand cmdIns = new SqlCommand();

                    //if (ad == 0)
                    //{
                    NP_Cls.SqlInsert = "INSERT INTO t_StockMovementDetail (AutoID, DocNumber, MaterialCode, MaterialName, Quantity, UnitCode, UnitName, NetPrice, Amount, DeliveryDate, PlantCode, PlantName, LocCode, LocName, CurrentUser, RefNumber, BatchNumber) " +
                                       "VALUES     (@ID,@PONumber,@MaterialCode,@MaterialName,@POQuantity,@UnitCode,@UnitName,@NetPrice,@POAmount,GETDATE(),@PlantCode,@PlantName,@LocCode,@LocName,@CurrentUser,@refPR,@BatchNumber)";
                    cmdIns.Parameters.Add("@ID", SqlDbType.Int);
                    cmdIns.Parameters.Add("@PONumber", SqlDbType.NVarChar, 12);
                    cmdIns.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15);
                    cmdIns.Parameters.Add("@MaterialName", SqlDbType.NVarChar, 60);
                    cmdIns.Parameters.Add("@POQuantity", SqlDbType.Decimal);
                    cmdIns.Parameters.Add("@UnitCode", SqlDbType.NVarChar, 3);
                    cmdIns.Parameters.Add("@UnitName", SqlDbType.NVarChar, 20);
                    cmdIns.Parameters.Add("@NetPrice", SqlDbType.Decimal);
                    cmdIns.Parameters.Add("@POAmount", SqlDbType.Decimal);
                    //cmdIns.Parameters.Add("@DeliveryDate", SqlDbType.DateTime);
                    cmdIns.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4);
                    cmdIns.Parameters.Add("@PlantName", SqlDbType.NVarChar, 20);
                    cmdIns.Parameters.Add("@LocCode", SqlDbType.NVarChar, 2);
                    cmdIns.Parameters.Add("@LocName", SqlDbType.NVarChar, 20);
                    cmdIns.Parameters.Add("@CurrentUser", SqlDbType.NVarChar, 50);
                    cmdIns.Parameters.Add("@refPR", SqlDbType.NVarChar, 12);
                    cmdIns.Parameters.Add("@BatchNumber", SqlDbType.NVarChar, 10);
                    for (int ad = 0; ad < 2; ad++)
                    {
                        for (byte ins = 0; ins < this.dgvView.RowCount; ins++)
                        {
                            cmdIns.Parameters["@ID"].Value           = Convert.ToInt32(this.dgvView["clnItemNo", ins].Value) + (ad * this.dgvView.RowCount);
                            cmdIns.Parameters["@PONumber"].Value     = this.strGNumber;
                            cmdIns.Parameters["@MaterialCode"].Value = this.dgvView["clnMaterialCode", ins].Value.ToString();
                            cmdIns.Parameters["@MaterialName"].Value = this.dgvView["clnMaterialName", ins].Value.ToString();
                            switch (this.cbMovType.Text.Trim().Split(':')[0])
                            {
                            case "321":
                                // QI > UR
                                cmdIns.Parameters["@refPR"].Value      = (ad == 0 ? "QI X" : "UR");
                                cmdIns.Parameters["@POQuantity"].Value = Convert.ToDouble(this.dgvView["clnTranQuantity", ins].Value);
                                break;

                            case "322":
                                // UR > QI
                                cmdIns.Parameters["@refPR"].Value      = (ad == 0 ? "UR X" : "QI");
                                cmdIns.Parameters["@POQuantity"].Value = Convert.ToDouble(this.dgvView["clnTranQuantity", ins].Value);
                                break;

                            case "349":
                                // Block > QI
                                cmdIns.Parameters["@refPR"].Value      = (ad == 0 ? "Block X" : "QI");
                                cmdIns.Parameters["@POQuantity"].Value = Convert.ToDouble(this.dgvView["clnTranQuantity", ins].Value);
                                break;

                            case "350":
                                // QI > Block
                                cmdIns.Parameters["@refPR"].Value      = (ad == 0 ? "QI X" : "Block");
                                cmdIns.Parameters["@POQuantity"].Value = Convert.ToDouble(this.dgvView["clnTranQuantity", ins].Value);
                                break;

                            default:
                                NP.MSGB(NP_Cls.NPMgsStyle.Invalid, "Not found type to transfer !!");
                                break;
                            }

                            cmdIns.Parameters["@UnitCode"].Value    = this.dgvView["clnUnitCode", ins].Value.ToString();
                            cmdIns.Parameters["@UnitName"].Value    = this.dgvView["clnUnitName", ins].Value.ToString();
                            cmdIns.Parameters["@NetPrice"].Value    = 0; //Convert.ToDouble(this.dgvView[6, ins].Value);
                            cmdIns.Parameters["@POAmount"].Value    = 0; //Convert.ToDouble(this.dgvView[7, ins].Value);
                            cmdIns.Parameters["@CurrentUser"].Value = NP_Cls.strUsr;
                            cmdIns.Parameters["@BatchNumber"].Value = this.dgvView["clnBatchNumber", ins].Value.ToString();
                            cmdIns.Parameters["@PlantCode"].Value   = this.dgvView["clnPlantCode", ins].Value.ToString();
                            cmdIns.Parameters["@PlantName"].Value   = this.dgvView["clnPlantName", ins].Value.ToString();
                            cmdIns.Parameters["@LocCode"].Value     = this.dgvView["clnLocCode", ins].Value.ToString();
                            cmdIns.Parameters["@LocName"].Value     = this.dgvView["clnLocName", ins].Value.ToString();

                            cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                            cmdIns.ExecuteNonQuery();

                            if (ad == 0)
                            {
                                switch (this.cbMovType.Text.Trim().Split(':')[0])
                                {
                                case "321":
                                    // QI > UR
                                    NP_Cls.sqlUpdate = "UPDATE t_StockOverview SET UR = UR + @POQuantity, QI = QI - @POQuantity  WHERE (BatchNumber = @BatchNumber) AND (MaterialCode = @MaterialCode)";
                                    break;

                                case "322":
                                    // UR > QI
                                    NP_Cls.sqlUpdate = "UPDATE t_StockOverview SET QI = QI + @POQuantity, UR = UR - @POQuantity WHERE (BatchNumber = @BatchNumber) AND (MaterialCode = @MaterialCode)";
                                    break;

                                case "349":
                                    // Block > QI
                                    NP_Cls.sqlUpdate = "UPDATE t_StockOverview SET QI = QI + @POQuantity, Block = Block - @POQuantity WHERE (BatchNumber = @BatchNumber) AND (MaterialCode = @MaterialCode)";
                                    break;

                                case "350":
                                    // QI > Block
                                    NP_Cls.sqlUpdate = "UPDATE t_StockOverview SET Block = Block + @POQuantity, QI = QI - @POQuantity WHERE (BatchNumber = @BatchNumber) AND (MaterialCode = @MaterialCode)";
                                    break;

                                default:
                                    NP.MSGB(NP_Cls.NPMgsStyle.Invalid, "Not found type to transfer !!");
                                    break;
                                }

                                cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.sqlUpdate; cmdIns.Transaction = Tr;
                                cmdIns.ExecuteNonQuery();
                            }
                        }
                    }

                    Tr.Commit(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Save Transfer Order Completed !!");
                    Clear();
                    this.groupPR.Enabled = true; this.btnAddHeader.Visible = true; this.btnSave.Visible = false; this.cbMaterial.Text = string.Empty; this.cbMaterial.DataSource = null;
                    this.dsPR.Tables.Clear(); this.MyGrid(dgvView); this.txtPR.Text = GetNumber();

                    this.cbMovType.SelectedIndex = 0; this.cbMovType.Text = string.Empty; this.cbMovType.Select();
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add Detail : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #20
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if ((string.IsNullOrEmpty((this.cbMaterial.Text.Trim()))) || (this.cbMaterial.Text.Trim() == "((( Select Material )))"))
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please enter Material: !!"); this.cbMaterial.Select(); return;
            }
            if ((string.IsNullOrEmpty((this.cbPlant.Text.Trim()))) || (this.cbPlant.Text.Trim() == "((( Select Plant )))"))
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please enter Plant: !!"); this.cbPlant.Select(); return;
            }
            if (NP.ReqField(this.txtBaseQuantity, "Please enter Base Quantity !!") == false)
            {
                return;
            }
            if (NP.ReqField(this.txtStdManHour, "Please enter Standard Man Hour !!") == false)
            {
                return;
            }
            if (NP.ReqField(this.txtHour, "Please enter Hours !!") == false)
            {
                return;
            }
            if ((string.IsNullOrEmpty((this.cbWorkCenter.Text.Trim()))) || (this.cbWorkCenter.Text.Trim() == "((( Select WorkCenter )))"))
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please enter Work Center: !!"); this.cbWorkCenter.Select(); return;
            }

            if (ChkDup())
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Work Center Duplicated !!"); this.cbWorkCenter.Select(); this.cbWorkCenter.SelectAll(); return;
            }

            if (NP.MSGB("Do you want to Add Data ?") == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction();
                try
                {
                    SqlCommand cmdIns = new SqlCommand();
                    NP_Cls.SqlSelect = "SELECT MaterialCode, PlantCode FROM t_Routing WHERE (MaterialCode = @MaterialCode) AND (PlantCode = @PlantCode)";
                    cmdIns.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15).Value = this.cbMaterial.SelectedValue;
                    cmdIns.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4).Value     = this.cbPlant.SelectedValue;
                    cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlSelect; cmdIns.Transaction = Tr;
                    SqlDataAdapter da = new SqlDataAdapter(cmdIns); DataSet ds = new DataSet(); da.Fill(ds);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        NP_Cls.SqlInsert = "INSERT INTO t_RoutingDetail (MaterialCode, PlantCode, WorkCenterCode, LogDate,STDManHour,Hours) VALUES (@MaterialCode,@PlantCode,@WorkCenterCode,GETDATE(),@STDManHour,@Hours)";
                        cmdIns.Parameters.Add("@WorkCenterCode", SqlDbType.NVarChar, 10).Value = this.cbWorkCenter.SelectedValue;
                        cmdIns.Parameters.Add("@STDManHour", SqlDbType.Decimal).Value          = Convert.ToDecimal(this.txtStdManHour.Text.Trim());
                        cmdIns.Parameters.Add("@Hours", SqlDbType.Decimal).Value = Convert.ToDecimal(this.txtHour.Text.Trim());
                        cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                        cmdIns.ExecuteNonQuery();
                    }
                    else
                    {
                        NP_Cls.SqlInsert = "INSERT INTO t_Routing (MaterialCode, PlantCode,Remark,BaseQuantity) VALUES (@MaterialCode,@PlantCode,@Remark,@BaseQuantity)";
                        cmdIns.Parameters.Add("@Remark", SqlDbType.NVarChar, 255).Value = this.txtRemark.Text.Trim();
                        cmdIns.Parameters.Add("@BaseQuantity", SqlDbType.Decimal).Value = Convert.ToDecimal(this.txtBaseQuantity.Text.Trim());
                        cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                        cmdIns.ExecuteNonQuery();

                        NP_Cls.SqlInsert = "INSERT INTO t_RoutingDetail (MaterialCode, PlantCode, WorkCenterCode, LogDate,STDManHour,Hours) VALUES (@MaterialCode,@PlantCode,@WorkCenterCode,GETDATE(),@STDManHour,@Hours)";
                        cmdIns.Parameters.Add("@WorkCenterCode", SqlDbType.NVarChar, 10).Value = this.cbWorkCenter.SelectedValue;
                        cmdIns.Parameters.Add("@STDManHour", SqlDbType.Decimal).Value          = Convert.ToDecimal(this.txtStdManHour.Text.Trim());
                        cmdIns.Parameters.Add("@Hours", SqlDbType.Decimal).Value = Convert.ToDecimal(this.txtHour.Text.Trim());
                        cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                        cmdIns.ExecuteNonQuery();
                    }

                    Tr.Commit();
                    DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Add Data Completed !!");
                    this.cbWorkCenter.Text  = string.Empty; this.cbWorkCenter.Select();
                    this.txtStdManHour.Text = string.Empty; this.txtRemark.Text = string.Empty; this.txtHour.Text = string.Empty;
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #21
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.dgvView.RowCount == 0)
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please select material into PO list !!"); this.cbMaterial.Select(); return;
            }
            this.dgvView.EndEdit();
            for (byte ii = 0; ii < this.dgvView.RowCount; ii++)
            {
                if (Convert.ToInt32(this.dgvView["clnQuantity", ii].Value) == 0)
                {
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Quantity for purchase more than 0 !!"); return;
                }
            }

            if (NP.MSGB("Do you to Save Purchase Order ?") == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(Application.StartupPath + @"\DB\DB.ini"));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr;
                Tr = oConn.BeginTransaction();

                try
                {
                    SqlCommand cmdIns = new SqlCommand();
                    NP_Cls.SqlInsert = "INSERT INTO t_PODetail (PONumber, MaterialCode, MaterialName, POQuantity, UnitCode, UnitName, NetPrice, POAmount, DeliveryDate, PlantCode, PlantName, LocCode, LocName, CurrentUser, PRNumber) " +
                                       "VALUES     (@PONumber,@MaterialCode,@MaterialName,@POQuantity,@UnitCode,@UnitName,@NetPrice,@POAmount,@DeliveryDate,@PlantCode,@PlantName,@LocCode,@LocName,@CurrentUser,@refPR)";
                    cmdIns.Parameters.Add("@PONumber", SqlDbType.NVarChar, 12);
                    cmdIns.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15);
                    cmdIns.Parameters.Add("@MaterialName", SqlDbType.NVarChar, 60);
                    cmdIns.Parameters.Add("@POQuantity", SqlDbType.Decimal);
                    cmdIns.Parameters.Add("@UnitCode", SqlDbType.NVarChar, 3);
                    cmdIns.Parameters.Add("@UnitName", SqlDbType.NVarChar, 20);
                    cmdIns.Parameters.Add("@NetPrice", SqlDbType.Decimal);
                    cmdIns.Parameters.Add("@POAmount", SqlDbType.Decimal);
                    cmdIns.Parameters.Add("@DeliveryDate", SqlDbType.DateTime);
                    cmdIns.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4);
                    cmdIns.Parameters.Add("@PlantName", SqlDbType.NVarChar, 20);
                    cmdIns.Parameters.Add("@LocCode", SqlDbType.NVarChar, 2);
                    cmdIns.Parameters.Add("@LocName", SqlDbType.NVarChar, 20);
                    cmdIns.Parameters.Add("@CurrentUser", SqlDbType.NVarChar, 50);
                    cmdIns.Parameters.Add("@refPR", SqlDbType.NVarChar, 12);


                    for (byte ins = 0; ins < this.dgvView.RowCount; ins++)
                    {
                        cmdIns.Parameters["@PONumber"].Value     = this.strGNumber;
                        cmdIns.Parameters["@MaterialCode"].Value = this.dgvView["clnMaterialCode", ins].Value.ToString();
                        cmdIns.Parameters["@MaterialName"].Value = this.dgvView["clnMaterialName", ins].Value.ToString();
                        cmdIns.Parameters["@POQuantity"].Value   = Convert.ToDouble(this.dgvView["clnQuantity", ins].Value);
                        cmdIns.Parameters["@UnitCode"].Value     = this.dgvView["clnUnitCode", ins].Value.ToString();
                        cmdIns.Parameters["@UnitName"].Value     = this.dgvView["clnUnitName", ins].Value.ToString();
                        cmdIns.Parameters["@NetPrice"].Value     = Convert.ToDouble(this.dgvView["clnNetPrice", ins].Value);
                        cmdIns.Parameters["@POAmount"].Value     = Convert.ToDouble(this.dgvView["clnAmount", ins].Value);
                        cmdIns.Parameters["@CurrentUser"].Value  = NP_Cls.strUsr;
                        cmdIns.Parameters["@DeliveryDate"].Value = Convert.ToDateTime(this.dgvView["clnDeliveryDate", ins].Value);
                        cmdIns.Parameters["@PlantCode"].Value    = this.dgvView["clnPlantCode", ins].Value.ToString();
                        cmdIns.Parameters["@PlantName"].Value    = this.dgvView["clnPlantName", ins].Value.ToString();
                        cmdIns.Parameters["@LocCode"].Value      = this.dgvView["clnLocCode", ins].Value.ToString();
                        cmdIns.Parameters["@LocName"].Value      = this.dgvView["clnLocName", ins].Value.ToString();
                        cmdIns.Parameters["@refPR"].Value        = this.dgvView["clnPRNumber", ins].Value.ToString();

                        cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                        cmdIns.ExecuteNonQuery();
                    }
                    cmdIns.Parameters.Add("@AutoID", SqlDbType.Int);
                    NP_Cls.sqlUpdate = "UPDATE t_PRDetail SET isPO = 1 WHERE (PRNumber = @refPR) AND (MaterialCode = @MaterialCode) AND (AutoID = @AutoID)";
                    for (byte upd = 0; upd < this.dgvView.RowCount; upd++)
                    {
                        cmdIns.Parameters["@refPR"].Value        = this.dgvView["clnPRNumber", upd].Value.ToString();
                        cmdIns.Parameters["@MaterialCode"].Value = this.dgvView["clnMaterialCode", upd].Value.ToString();
                        cmdIns.Parameters["@AutoID"].Value       = this.dgvView["AutoID", upd].Value.ToString();
                        cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.sqlUpdate; cmdIns.Transaction = Tr;
                        cmdIns.ExecuteNonQuery();
                    }
                    Tr.Commit(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Save Purchase Order Completed !!");
                    Clear();
                    this.groupPR.Enabled = true; this.btnAddPR.Visible = true; this.btnSave.Visible = false; this.cbMaterial.Text = string.Empty; this.cbMaterial.DataSource = null;
                    this.dsPR.Tables.Clear(); this.MyGrid(dgvView); this.txtPR.Text = GetNumber();

                    BindVendor();
                    this.cbVendor.Text = string.Empty; this.cbVendor.Select();
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add Detail : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #22
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //if (NP.ReqField(this.cbVendor, "Please enter Vendor: !!") == false) { return; }
            //if (NP.ReqField(this.cbMaterial, "Please enter Material: !!") == false) { return; }
            if ((string.IsNullOrEmpty((this.cbVendor.Text.Trim()))) || (this.cbVendor.Text.Trim() == "((( Select Vendor )))"))
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please enter Vendor: !!"); this.cbVendor.Select(); return;
            }
            if ((string.IsNullOrEmpty((this.cbMaterial.Text.Trim()))) || (this.cbMaterial.Text.Trim() == "((( Select Material )))"))
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please enter Material: !!"); this.cbMaterial.Select(); return;
            }
            //if (NP.ReqField(this.cbPG, "Please enter Purchasing group: !!") == false) { return; }
            if (NP.ReqField(this.txtDelivery, "Please enter Delivery time: !!") == false)
            {
                return;
            }
            if (NP.ReqField(this.txtMinQty, "Please enter Minimum Qty.: !!") == false)
            {
                return;
            }
            if (NP.ReqField(this.txtNetPrice, "Please enter Net Price: !!") == false)
            {
                return;
            }
            if (NP.ReqField(this.cbOrderUnit, "Please enter Order Unit: !!") == false)
            {
                return;
            }
            if (NP.ReqField(this.txtQtyCon, "Please enter Qty.Conversion: !!") == false)
            {
                return;
            }

            if (ChkDup())
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Code Duplicated !!"); this.cbVendor.Select(); return;
            }

            if (NP.MSGB("Do you want to Add Data ?") == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr;
                Tr = oConn.BeginTransaction();
                try
                {
                    SqlCommand cmdIns = new SqlCommand();
                    NP_Cls.SqlInsert = "INSERT INTO t_VendorInfoRecord " +
                                       "(VendorCode, MaterialCode, DeliveryTime, MinimumQty, NetPrice, UnitCode, QtyConversion, Block) " +
                                       "VALUES     (@VendorCode,@MaterialCode,@DeliveryTime,@MinimumQty,@NetPrice,@UnitCode,@QtyConversion,@Block)";
                    cmdIns.Parameters.Add("@VendorCode", SqlDbType.NVarChar, 10).Value   = this.cbVendor.SelectedValue;
                    cmdIns.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15).Value = this.cbMaterial.SelectedValue;
                    //cmdIns.Parameters.Add("@PurchasingGroup", SqlDbType.NVarChar, 3).Value = this.cbPG.SelectedValue;
                    cmdIns.Parameters.Add("@DeliveryTime", SqlDbType.Int).Value     = Convert.ToInt32(string.IsNullOrEmpty(this.txtDelivery.Text.Trim()) ? "0" : this.txtDelivery.Text.Trim());
                    cmdIns.Parameters.Add("@MinimumQty", SqlDbType.Decimal).Value   = Convert.ToDecimal(string.IsNullOrEmpty(this.txtMinQty.Text.Trim()) ? "0" : this.txtMinQty.Text.Trim());
                    cmdIns.Parameters.Add("@NetPrice", SqlDbType.Decimal).Value     = Convert.ToDecimal(string.IsNullOrEmpty(this.txtNetPrice.Text.Trim()) ? "0" : this.txtNetPrice.Text.Trim());
                    cmdIns.Parameters.Add("@UnitCode", SqlDbType.NVarChar, 3).Value = this.cbOrderUnit.SelectedValue;
                    cmdIns.Parameters.Add("@QtyConversion", SqlDbType.Int).Value    = Convert.ToInt32(string.IsNullOrEmpty(this.txtQtyCon.Text.Trim()) ? "0" : this.txtQtyCon.Text.Trim());
                    cmdIns.Parameters.Add("@Block", SqlDbType.Bit).Value            = this.chkBlock.Checked;
                    cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                    cmdIns.ExecuteNonQuery();

                    NP_Cls.SqlInsert = "INSERT INTO t_VendorSourceList (VendorCode, MaterialCode, Fix) VALUES (@VendorCode,@MaterialCode,@Fix)";
                    cmdIns.Parameters.Add("@Fix", SqlDbType.Bit).Value = 0;
                    cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                    cmdIns.ExecuteNonQuery();

                    Tr.Commit();
                    Clear(); DGV(); this.cbMaterial.Enabled = true; this.cbVendor.Enabled = true; this.btnAdd.Visible = true; this.btnEdit.Visible = false;
                    this.cbVendor.Text = string.Empty; this.cbMaterial.Text = string.Empty; this.cbVendor.Select();
                    NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Add Data Completed !!");
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #23
0
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (NP_Cls.AppPR == 0)
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "You have not Permission to Approve B.O.M. !!"); return;
            }
            if (this.dgvView.RowCount == 0)
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Data Not Found to Approve !!"); return;
            }
            if (this.lblAppr.Text.Trim().ToUpper() == "TRUE")
            {
                NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "This BOM is Approve already !!"); return;
            }

            if (NP.MSGB("Do you want to Approve this BOM ?") == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction();
                try
                {
                    SqlCommand cmdEdit = new SqlCommand();
                    NP_Cls.sqlUpdate = "UPDATE   t_BOM SET Approve = @Appr, ApproveUser = @AUSER WHERE (BOMCode = @BOMCode)";
                    cmdEdit.Parameters.Add("@BOMCode", SqlDbType.Int).Value = Convert.ToInt32(this.dgvView["clnBOMCode", this.dgvView.CurrentRow.Index].Value);
                    cmdEdit.Parameters.Add("@Appr", SqlDbType.Bit).Value    = 1; cmdEdit.Parameters.Add("@AUSER", SqlDbType.NVarChar, 10).Value = NP_Cls.strUsr;

                    cmdEdit.Connection = oConn; cmdEdit.CommandText = NP_Cls.sqlUpdate; cmdEdit.Transaction = Tr;
                    cmdEdit.ExecuteNonQuery();

                    if (NP._TRanSave(oConn, Tr, NP_Cls.NPTranType.Update, "t_BOM:Approve", NP_Cls.strUsr))
                    {
                        Tr.Commit(); Clear();
                        DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Approve Completed !!");
                        this.btnAdd.Visible = true; this.btnEdit.Visible = false;
                    }
                    else
                    {
                        NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Try Again !!"); return;
                    }
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Approve : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #24
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if ((string.IsNullOrEmpty((this.cbMaterial.Text.Trim()))) || (this.cbMaterial.Text.Trim() == "((( Select Material )))"))
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please enter Material: !!"); this.cbMaterial.Select(); return;
            }
            if (NP.ReqField(this.cbPlant, "Please enter Plant: !!") == false)
            {
                return;
            }
            if (NP.ReqField(this.cbBOMType, "Please enter B.O.M Type: !!") == false)
            {
                return;
            }
            if (NP.ReqField(this.cbUnit, "Please enter Unit: !!") == false)
            {
                return;
            }
            if (NP.ReqField(this.txtQty, "Please enter Quantity: !!") == false)
            {
                return;
            }
            if (cbMaterial.Text.StartsWith("3"))
            {
                if (!NP.ReqField(this.txtFor, "please enter Formula No : !!"))
                {
                    return;
                }
            }
            if (cbMaterial.Text.StartsWith("5") && cbBOMType.Text == "Mix")
            {
                if (!NP.ReqField(this.txtFor, "please enter Formula No : !!"))
                {
                    return;
                }
            }
            if (NP.MSGB("Do you want to Edit BOM Data ?") == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction();
                try
                {
                    SqlCommand cmdEdit = new SqlCommand();
                    NP_Cls.sqlUpdate = "UPDATE    t_BOM " +
                                       "SET BOMType = @BOMType, UnitCode = @UnitCode, Quantity = @Qty, UserChange = @UC, DateChange = GETDATE(), Remark = @Remark, FormulaNo = @FormulaNo " +
                                       "WHERE     (MaterialCode = @MaterialCode) AND (PlantCode = @PlantCode)";
                    cmdEdit.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15).Value = this.cbMaterial.SelectedValue;
                    cmdEdit.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4).Value     = this.cbPlant.SelectedValue;
                    cmdEdit.Parameters.Add("@BOMType", SqlDbType.NVarChar, 1).Value       = this.cbBOMType.SelectedValue;
                    cmdEdit.Parameters.Add("@UnitCode", SqlDbType.NVarChar, 3).Value      = this.cbUnit.SelectedValue;
                    cmdEdit.Parameters.Add("@Qty", SqlDbType.Decimal).Value             = Convert.ToDouble(this.txtQty.Text.Trim());
                    cmdEdit.Parameters.Add("@UC", SqlDbType.NVarChar, 10).Value         = NP_Cls.strUsr;
                    cmdEdit.Parameters.Add("@Remark", SqlDbType.NVarChar, 200).Value    = this.txtRemark.Text.Trim();
                    cmdEdit.Parameters.Add("@FormulaNo", SqlDbType.NVarChar, 200).Value = this.txtFor.Text.Trim();
                    cmdEdit.Connection = oConn; cmdEdit.CommandText = NP_Cls.sqlUpdate; cmdEdit.Transaction = Tr;
                    cmdEdit.ExecuteNonQuery();

                    // Edit Detail
                    if (!BOMQtyChk(oConn, Tr))
                    {
                        Tr.Commit();
                        if (this.cbBOMType.SelectedValue.ToString().ToUpper() == "M")
                        {
                            NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Edit BOM Data Completed !!\n\n Please Edit Component for this BOM ..");

                            NP_Cls.hBOM = new System.Collections.Hashtable();
                            NP_Cls.hBOM.Add("BOMCode", ((string)GenBOMCode()));
                            NP_Cls.hBOM.Add("Qty", Convert.ToDouble(this.txtQty.Text.Trim()));
                            NP_Cls.hBOM.Add("UnitName", ((string)this.cbUnit.Text));
                            NP_Cls.hBOM.Add("BOMType", ((string)this.cbBOMType.SelectedValue));
                            NP_Cls.hBOM.Add("Approve", Convert.ToBoolean(this.dgvView["clnApprove", this.dgvView.CurrentRow.Index].ToString()));


                            WMS.BOM.frmBOMNewDetail frm = new frmBOMNewDetail();
                            frm.ShowDialog();
                        }
                        this.btnAdd.Visible = true; this.btnEdit.Visible = false; this.cbMaterial.Enabled = true; this.cbPlant.Enabled = true;
                        this.cbMaterial.Select(); this.cbUnit.Enabled = true;
                        Clear(); DGV(); this.cbMaterial.Select();
                    }
                    else
                    {
                        Tr.Commit();
                        Clear();
                        DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Edit BOM Data Completed !!"); this.cbMaterial.Select(); this.cbPlant.Enabled = true; this.cbUnit.Enabled = true;
                        this.btnAdd.Visible = true; this.btnEdit.Visible = false; this.cbMaterial.Enabled = true; this.cbMaterial.Select();
                    }
                    //
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Edit : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #25
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (NP_Cls.hBOM["BOMType"].ToString().ToUpper() == "M")
            {
                if (this.dQtyChk == 0)
                {
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Qty of Component are limite !!"); return;
                }
            }
            if ((string.IsNullOrEmpty((this.cbComponent.Text.Trim()))) || (this.cbComponent.Text.Trim() == "((( Select Component )))"))
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please enter Component: !!"); this.cbComponent.Select(); return;
            }
            if (NP.ReqField(this.txtQtyComp, "Please enter Qty of Component: !!") == false)
            {
                return;
            }
            if (NP.ReqField(this.txtLoss, "Please enter %Loss: !!") == false)
            {
                return;
            }

            if (ChkDup())
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Component Duplicated !!"); this.cbComponent.Select(); return;
            }

            if (this.dgvView.RowCount != 0)
            {
                if (NP_Cls.hBOM["BOMType"].ToString().ToUpper() == "M")
                {
                    Decimal bChk = 0;
                    for (byte i = 0; i < this.dgvView.RowCount; i++)
                    {
                        if (this.dgvView["clnUnitCode", i].Value.ToString().ToUpper() == "G")
                        {
                            bChk += Convert.ToDecimal(this.dgvView["clnQty", i].Value) / 1000;
                        }
                        else
                        {
                            bChk += Convert.ToDecimal(this.dgvView["clnQty", i].Value);
                        }
                    }
                    if (bChk == 100)
                    {
                        NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Qty of Component is equal 100 !!\nCan not add component !!"); this.txtQtyComp.Select(); this.txtQtyComp.SelectAll(); return;
                    }

                    if (this.lblCompUnitCode.Text.Trim().ToUpper() == "G")
                    {
                        if (((Convert.ToDecimal(this.txtQtyComp.Text.Trim()) / 1000) + bChk) > 100)
                        {
                            NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Qty of Component is over 100 !!"); this.txtQtyComp.Select(); this.txtQtyComp.SelectAll(); return;
                        }
                    }
                    else
                    {
                        if ((Convert.ToDecimal(this.txtQtyComp.Text.Trim()) + bChk) > 100)
                        {
                            NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Qty of Component is over 100 !!"); this.txtQtyComp.Select(); this.txtQtyComp.SelectAll(); return;
                        }
                    }
                }
                else
                {
                    Decimal bChk = 0;
                    for (byte i = 0; i < this.dgvView.RowCount; i++)
                    {
                        bChk += Convert.ToDecimal(this.dgvView["clnQty", i].Value);
                    }
                    //if (bChk == Convert.ToDecimal(NP_Cls.hBOM["Qty"].ToString())) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Qty of Component is equal " + NP_Cls.hBOM["Qty"].ToString() + " !!\nCan not add component !!"); this.txtQtyComp.Select(); this.txtQtyComp.SelectAll(); return; }
                    //if ((Convert.ToDecimal(this.txtQtyComp.Text.Trim()) + bChk) > Convert.ToDecimal(NP_Cls.hBOM["Qty"].ToString()))
                    //{
                    //    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Qty of Component is over " + Convert.ToDecimal(NP_Cls.hBOM["Qty"].ToString()) + " !!"); this.txtQtyComp.Select(); this.txtQtyComp.SelectAll(); return;
                    //}
                }
            }
            else
            {
                if (NP_Cls.hBOM["BOMType"].ToString().ToUpper() == "M")
                {
                    if (this.lblCompUnitCode.Text.Trim().ToUpper() == "G")
                    {
                        if ((Convert.ToDecimal(this.txtQtyComp.Text.Trim()) / 1000) > 100)
                        {
                            NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Qty of Component is over 100 !!"); this.txtQtyComp.Select(); this.txtQtyComp.SelectAll(); return;
                        }
                    }
                    else
                    {
                        if (Convert.ToDecimal(this.txtQtyComp.Text.Trim()) > 100)
                        {
                            NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Qty of Component is over 100 !!"); this.txtQtyComp.Select(); this.txtQtyComp.SelectAll(); return;
                        }
                    }
                }
                else
                {
                    //if (Convert.ToDecimal(this.txtQtyComp.Text.Trim()) > Convert.ToDecimal(NP_Cls.hBOM["Qty"].ToString()))
                    //{
                    //    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Qty of Component is over " + NP_Cls.hBOM["Qty"].ToString() + " !!"); this.txtQtyComp.Select(); this.txtQtyComp.SelectAll(); return;
                    //}
                }
            }

            if (NP.MSGB("Do you want to Add BOM Component Data ?") == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction();
                try
                {
                    SqlCommand cmdIns = new SqlCommand();
                    NP_Cls.SqlInsert = "INSERT INTO t_BOMDetail " +
                                       "(BOMCode, Category, MaterialCode, Quantity, LossPercentage, UserCreate, DateCreate, Remark, SortIndex) " +
                                       "VALUES     (@BOMCode,@Category,@MaterialCode,@Quantity,@LP,@UC, GETDATE(), @Remark,@Sort)";
                    cmdIns.Parameters.Add("@BOMCode", SqlDbType.Int).Value = NP_Cls.hBOM["BOMCode"].ToString();
                    cmdIns.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15).Value = this.cbComponent.SelectedValue;
                    cmdIns.Parameters.Add("@Category", SqlDbType.NVarChar, 1).Value      = ChkCategory(oConn, Tr, this.cbComponent.SelectedValue.ToString());
                    cmdIns.Parameters.Add("@Quantity", SqlDbType.Decimal).Value          = ((this.lblCompUnitCode.Text.Trim().ToUpper() == "G") && ((NP_Cls.hBOM["BOMType"].ToString().ToUpper() == "M")) ? (Convert.ToDouble(this.txtQtyComp.Text.Trim()) / 1000) : Convert.ToDouble(this.txtQtyComp.Text.Trim()));
                    cmdIns.Parameters.Add("@LP", SqlDbType.Decimal).Value           = Convert.ToDouble(this.txtLoss.Text.Trim());
                    cmdIns.Parameters.Add("@Sort", SqlDbType.Decimal).Value         = Convert.ToDouble(this.txtIndex.Text.Trim());
                    cmdIns.Parameters.Add("@UC", SqlDbType.NVarChar, 10).Value      = NP_Cls.strUsr;
                    cmdIns.Parameters.Add("@Remark", SqlDbType.NVarChar, 200).Value = this.txtRemark.Text.Trim();
                    cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                    cmdIns.ExecuteNonQuery();

                    Tr.Commit();
                    Clear();
                    DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Add BOM Component Data Completed !!"); this.cbComponent.Select();
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #26
0
        private void btnExit_Click(object sender, EventArgs e)
        {
            if (this.dQtyChk != 0)
            {
                if (NP.MSGB("Qty of Component are not equal Qty of BOM !!\nThe transaction will be reject , Do you want to exit out of save ?") == DialogResult.Yes)
                {
                    // Delete all Transaction
                    oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                    oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction();
                    try
                    {
                        SqlCommand cmdDel = new SqlCommand();
                        NP_Cls.SqlSelect = "SELECT BOMDetailCode FROM t_BOMDetail WHERE (BOMCode = @BOMCode)";
                        cmdDel.Parameters.Add("@BOMCode", SqlDbType.Int).Value = Convert.ToInt32(NP_Cls.hBOM["BOMCode"].ToString());
                        cmdDel.Connection = oConn; cmdDel.CommandText = NP_Cls.SqlSelect; cmdDel.Transaction = Tr;
                        SqlDataAdapter da = new SqlDataAdapter(cmdDel); DataSet ds = new DataSet(); da.Fill(ds);

                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            NP_Cls.SqlDel = "DELETE FROM t_BOMDetail WHERE (BOMCode = @BOMCode)";
                            //cmdDel.Parameters.Add("@BOMCode", SqlDbType.Int).Value = this.dgvView["clnBOMCode", this.dgvView.CurrentRow.Index].Value;
                            cmdDel.Parameters.Add("@BOMDetailCode", SqlDbType.Int).Value = this.dgvView["clnBOMDetailCode", this.dgvView.CurrentRow.Index].Value;
                            cmdDel.Connection = oConn; cmdDel.CommandText = NP_Cls.SqlDel; cmdDel.Transaction = Tr;
                            cmdDel.ExecuteNonQuery();

                            NP_Cls.SqlDel     = "DELETE FROM t_BOM WHERE (BOMCode = @BOMCode)";
                            cmdDel.Connection = oConn; cmdDel.CommandText = NP_Cls.SqlDel; cmdDel.Transaction = Tr;
                            cmdDel.ExecuteNonQuery();

                            if (NP._TRanSave(oConn, Tr, NP_Cls.NPTranType.Delete, "t_BOM:t_BOMDetail", NP_Cls.strUsr))
                            {
                                Tr.Commit();
                                this.Close();
                            }
                            else
                            {
                                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Try agian !!"); return;
                            }
                        }
                        else // Has Row
                        {
                            NP_Cls.SqlDel     = "DELETE FROM t_BOM WHERE (BOMCode = @BOMCode)";
                            cmdDel.Connection = oConn; cmdDel.CommandText = NP_Cls.SqlDel; cmdDel.Transaction = Tr;
                            cmdDel.ExecuteNonQuery();

                            if (NP._TRanSave(oConn, Tr, NP_Cls.NPTranType.Delete, "t_BOM", NP_Cls.strUsr))
                            {
                                Tr.Commit();
                                this.Close();
                            }
                            else
                            {
                                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Try agian !!"); return;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (oConn.State == ConnectionState.Open)
                        {
                            Tr.Rollback();
                        }
                        NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Delete : " + ex.Message); return;
                    }
                    finally
                    {
                        if (oConn.State == ConnectionState.Open)
                        {
                            oConn.Close();
                        }
                    }
                    //
                }
                else
                {
                    return;
                }
            }
            else
            {
                if (NP.MSGB("Do you want to exit this screen ?") == DialogResult.Yes)
                {
                    this.Close();
                }
                else
                {
                    return;
                }
            }
        }
예제 #27
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.dgvView.RowCount == 0)
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please select GR number into GR list !!"); this.cbPONumber.Select(); return;
            }
            this.dgvView.EndEdit();

            if (NP.MSGB("Do you to Save Goods Return ?") == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr;
                Tr = oConn.BeginTransaction();

                try
                {
                    SqlCommand cmdIns = new SqlCommand();
                    NP_Cls.SqlInsert = "INSERT INTO t_GTDetail " +
                                       "(GTNumber, MaterialCode, MaterialName, GTQuantity, UnitCode, UnitName, NetPrice, GTAmount, DeliveryDate, PlantCode, PlantName, LocCode, LocName, BatchNumber, CurrentUser, GRNumber, GRAutoID) " +
                                       "VALUES     (@GTNumber,@MaterialCode,@MaterialName,@GTQuantity,@UnitCode,@UnitName,@NetPrice,@GTAmount,@DeliveryDate,@PlantCode,@PlantName,@LocCode,@LocName,@BatchNumber,@CurrentUser,@GRNumber, @GRID)";
                    cmdIns.Parameters.Add("@GTNumber", SqlDbType.NVarChar, 12);
                    cmdIns.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15);
                    cmdIns.Parameters.Add("@MaterialName", SqlDbType.NVarChar, 60);
                    cmdIns.Parameters.Add("@GTQuantity", SqlDbType.Decimal);
                    cmdIns.Parameters.Add("@UnitCode", SqlDbType.NVarChar, 3);
                    cmdIns.Parameters.Add("@UnitName", SqlDbType.NVarChar, 20);
                    cmdIns.Parameters.Add("@NetPrice", SqlDbType.Decimal);
                    cmdIns.Parameters.Add("@GTAmount", SqlDbType.Decimal);
                    cmdIns.Parameters.Add("@DeliveryDate", SqlDbType.DateTime);
                    cmdIns.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4);
                    cmdIns.Parameters.Add("@PlantName", SqlDbType.NVarChar, 20);
                    cmdIns.Parameters.Add("@LocCode", SqlDbType.NVarChar, 2);
                    cmdIns.Parameters.Add("@LocName", SqlDbType.NVarChar, 20);
                    cmdIns.Parameters.Add("@BatchNumber", SqlDbType.NVarChar, 20);
                    cmdIns.Parameters.Add("@GRNumber", SqlDbType.NVarChar, 12);
                    cmdIns.Parameters.Add("@CurrentUser", SqlDbType.NVarChar, 50);
                    cmdIns.Parameters.Add("@GRID", SqlDbType.Int);
                    for (byte ins = 0; ins < this.dgvView.RowCount; ins++)
                    {
                        if (Convert.ToInt32(this.dgvView[3, ins].Value) != 0)
                        {
                            cmdIns.Parameters["@GTNumber"].Value     = this.strGNumber;
                            cmdIns.Parameters["@MaterialCode"].Value = this.dgvView[1, ins].Value.ToString();
                            cmdIns.Parameters["@MaterialName"].Value = this.dgvView[2, ins].Value.ToString();
                            cmdIns.Parameters["@GTQuantity"].Value   = Convert.ToInt32(this.dgvView[3, ins].Value);
                            cmdIns.Parameters["@UnitCode"].Value     = this.dgvView[5, ins].Value.ToString();
                            cmdIns.Parameters["@UnitName"].Value     = this.dgvView[4, ins].Value.ToString();
                            cmdIns.Parameters["@NetPrice"].Value     = Convert.ToInt32(this.dgvView[11, ins].Value);
                            cmdIns.Parameters["@GTAmount"].Value     = Convert.ToInt32(this.dgvView[12, ins].Value);
                            cmdIns.Parameters["@DeliveryDate"].Value = Convert.ToDateTime(this.dgvView[9, ins].Value);
                            cmdIns.Parameters["@PlantCode"].Value    = this.dgvView[6, ins].Value.ToString();
                            cmdIns.Parameters["@PlantName"].Value    = this.dgvView[13, ins].Value.ToString();
                            cmdIns.Parameters["@LocCode"].Value      = this.dgvView[7, ins].Value.ToString();
                            cmdIns.Parameters["@LocName"].Value      = this.dgvView[14, ins].Value.ToString();
                            cmdIns.Parameters["@BatchNumber"].Value  = this.dgvView[8, ins].Value.ToString();
                            cmdIns.Parameters["@GRNumber"].Value     = this.dgvView[10, ins].Value.ToString();
                            cmdIns.Parameters["@CurrentUser"].Value  = NP_Cls.strUsr;
                            cmdIns.Parameters["@GRID"].Value         = this.dgvView[15, ins].Value.ToString();

                            cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                            cmdIns.ExecuteNonQuery();

                            //NP_Cls.sqlUpdate = "UPDATE t_PODetail SET GRQuantity = @GRQuantity WHERE (PONumber = @PONumber) AND (AutoID = @POID)";
                            //cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.sqlUpdate; cmdIns.Transaction = Tr;
                            //cmdIns.ExecuteNonQuery();
                        }
                    }

                    Tr.Commit(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Save Goods Return Completed !!");
                    Clear();
                    this.groupPR.Enabled = true; this.btnAddPR.Visible = true; this.btnSave.Visible = false; this.cbPONumber.Text = string.Empty; this.cbPONumber.DataSource = null;
                    this.MyGrid(dgvView); this.txtDoc.Text = GetNumber();

                    NP_Cls.SqlSelect = "SELECT DISTINCT VendorName, VendorCode FROM  t_GR WHERE (MovementType = N'101')";
                    NP.BindCB(this.cbVendor, NP_Cls.SqlSelect, "VendorName", "VendorCode", "((( Select Vendor GR )))");
                    this.cbVendor.Text = string.Empty; this.cbVendor.Select();
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add Detail : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #28
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (NP.MSGB("Do you to Save Production Order no Job ?") == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr;
                Tr = oConn.BeginTransaction();

                try
                {
                    if (!Convert.ToBoolean(bView))
                    {
                        SqlCommand cmdIns = new SqlCommand();
                        NP_Cls.SqlInsert = "INSERT INTO t_Borrow (RefNumber, BorrowDate, MaterialCode, MaterialName, BorrowQuantity, UnitCode, UnitName, PlantCode, PlantName, LocCode, LocName, Remark, UserCreate, DateCreate) VALUES (@RefNumber,GETDATE(),@MaterialCode,@MaterialName,@BorrowQuantity,@UnitCode, @UnitName, @PlantCode,@PlantName,@LocCode,@LocName,@Remark,@UserCreate,  GETDATE())";
                        cmdIns.Parameters.Add("@RefNumber", SqlDbType.NVarChar, 12);
                        cmdIns.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15);
                        cmdIns.Parameters.Add("@MaterialName", SqlDbType.NVarChar, 60);
                        cmdIns.Parameters.Add("@BorrowQuantity", SqlDbType.Decimal);
                        cmdIns.Parameters.Add("@UnitCode", SqlDbType.NVarChar, 4);
                        cmdIns.Parameters.Add("@UnitName", SqlDbType.NVarChar, 20);
                        cmdIns.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4);
                        cmdIns.Parameters.Add("@PlantName", SqlDbType.NVarChar, 20);
                        cmdIns.Parameters.Add("@LocCode", SqlDbType.NVarChar, 2);
                        cmdIns.Parameters.Add("@LocName", SqlDbType.NVarChar, 20);
                        cmdIns.Parameters.Add("@Remark", SqlDbType.NVarChar, 255);
                        cmdIns.Parameters.Add("@UserCreate", SqlDbType.NVarChar, 50);

                        //SqlCommand cmdInsDetail = new SqlCommand();
                        //NP_Cls.SqlInsert = "INSERT INTO t_PrdOrderDetail (PrdONumber, ComponentCode, ComponentName, PrdOQuantity, UnitCode, UnitName, PlantCode, PlantName, LocCode, LocName, CurrentUser) VALUES     (@PrdONumber,@ComponentCode,@ComponentName,@PrdOQuantity,@UnitCode,@UnitName,@PlantCode,@PlantName,@LocCode,@LocName,@CurrentUser)";
                        //cmdInsDetail.Parameters.Add("@PrdONumber", SqlDbType.NVarChar, 12);
                        //cmdInsDetail.Parameters.Add("@ComponentCode", SqlDbType.NVarChar, 15);
                        //cmdInsDetail.Parameters.Add("@ComponentName", SqlDbType.NVarChar, 60);
                        //cmdInsDetail.Parameters.Add("@PrdOQuantity", SqlDbType.Decimal);
                        //cmdInsDetail.Parameters.Add("@UnitCode", SqlDbType.NVarChar, 3);
                        //cmdInsDetail.Parameters.Add("@UnitName", SqlDbType.NVarChar, 20);
                        //cmdInsDetail.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4);
                        //cmdInsDetail.Parameters.Add("@PlantName", SqlDbType.NVarChar, 20);
                        //cmdInsDetail.Parameters.Add("@LocCode", SqlDbType.NVarChar, 2);
                        //cmdInsDetail.Parameters.Add("@LocName", SqlDbType.NVarChar, 20);
                        //cmdInsDetail.Parameters.Add("@CurrentUser", SqlDbType.NVarChar, 50);


                        for (byte ins = 0; ins < this.dgvView.RowCount; ins++)
                        {
                            cmdIns.Parameters["@RefNumber"].Value      = this.txtPrdOrder.Text.Trim();
                            cmdIns.Parameters["@MaterialCode"].Value   = this.dgvView["clnMaterialCode", ins].Value.ToString();
                            cmdIns.Parameters["@MaterialName"].Value   = this.dgvView["clnMaterialName", ins].Value.ToString();
                            cmdIns.Parameters["@BorrowQuantity"].Value = Convert.ToDecimal(this.dgvView["clnQuantity", ins].Value);
                            cmdIns.Parameters["@UnitCode"].Value       = this.dgvView["clnUnitCode", ins].Value.ToString();
                            cmdIns.Parameters["@UnitName"].Value       = this.dgvView["clnUnitName", ins].Value.ToString();
                            cmdIns.Parameters["@UserCreate"].Value     = NP_Cls.strUsr;
                            cmdIns.Parameters["@PlantCode"].Value      = this.dgvView["clnPlantCode", ins].Value.ToString();
                            cmdIns.Parameters["@PlantName"].Value      = this.dgvView["clnPlantName", ins].Value.ToString();
                            cmdIns.Parameters["@LocCode"].Value        = this.dgvView["clnLocCode", ins].Value.ToString();
                            cmdIns.Parameters["@LocName"].Value        = this.dgvView["clnLocName", ins].Value.ToString();
                            cmdIns.Parameters["@Remark"].Value         = this.txtRemark.Text.Trim();
                            cmdIns.Parameters.Add("@BatchNumber", SqlDbType.NVarChar, 10).Value = this.dgvView["clnBatch", ins].Value.ToString();

                            cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                            cmdIns.ExecuteNonQuery();

                            // Stock Overview //
                            NP_Cls.sqlUpdate  = "UPDATE   t_StockOverview SET UR = UR - @BorrowQuantity  WHERE (BatchNumber = @BatchNumber)";
                            cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.sqlUpdate; cmdIns.Transaction = Tr;
                            cmdIns.ExecuteNonQuery();
                        }

                        cmdIns.Parameters.Clear();
                        // Master
                        NP_Cls.SqlInsert = "INSERT INTO t_StockMovement " +
                                           "(DocNumber, TranDate, MovementType, RefNumber,  Remark, UserCreate,  DateCreate) " +
                                           "VALUES     (@GINumber, GETDATE(), @MV, @PrdONumber,@Remark,@UD,GETDATE())";
                        Random rnd       = new Random();
                        string tmpString = "BR" + DateTime.Now.Year.ToString(NP_Cls.cul) + rnd.Next(1, 99999);
                        cmdIns.Parameters.Add("@GINumber", SqlDbType.NVarChar, 12).Value   = tmpString;
                        cmdIns.Parameters.Add("@PrdONumber", SqlDbType.NVarChar, 50).Value = this.txtPrdOrder.Text.Trim();
                        cmdIns.Parameters.Add("@MV", SqlDbType.NVarChar, 3).Value          = (!string.IsNullOrEmpty(this.txtPrdOrder.Text.Trim()) ? "261" : "999");
                        cmdIns.Parameters.Add("@Remark", SqlDbType.NVarChar, 500).Value    = this.lblPlant.Text.Trim();
                        cmdIns.Parameters.Add("@UD", SqlDbType.NVarChar, 50).Value         = NP_Cls.strUsr;
                        cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                        cmdIns.ExecuteNonQuery();


                        // Detail
                        cmdIns.Parameters.Clear();
                        NP_Cls.SqlInsert = "INSERT INTO t_StockMovementDetail " +
                                           "(AutoID,DocNumber, MaterialCode, MaterialName, Quantity, UnitCode, UnitName, PlantCode, PlantName, LocCode, LocName, CurrentUser, RefNumber, BatchNumber) " +
                                           "VALUES     (@AutoID, @DocNumber,@MaterialCode,@MaterialName,@GIQuantity,@UnitCode,@UnitName,@PlantCode,@PlantName,@LocCode,@LocName,@CurrentUser,@PrdONumber, @BatchNumber)";
                        cmdIns.Parameters.Add("@AutoID", SqlDbType.Int);
                        cmdIns.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15);
                        cmdIns.Parameters.Add("@MaterialName", SqlDbType.NVarChar, 60);
                        cmdIns.Parameters.Add("@GIQuantity", SqlDbType.Decimal);
                        cmdIns.Parameters.Add("@UnitCode", SqlDbType.NVarChar, 3);
                        cmdIns.Parameters.Add("@UnitName", SqlDbType.NVarChar, 20);
                        cmdIns.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4);
                        cmdIns.Parameters.Add("@PlantName", SqlDbType.NVarChar, 20);
                        cmdIns.Parameters.Add("@LocCode", SqlDbType.NVarChar, 4);
                        cmdIns.Parameters.Add("@LocName", SqlDbType.NVarChar, 20);
                        cmdIns.Parameters.Add("@CurrentUser", SqlDbType.NVarChar, 50);
                        cmdIns.Parameters.Add("@BatchNumber", SqlDbType.NVarChar, 10);
                        cmdIns.Parameters.Add("@PrdONumber", SqlDbType.NVarChar, 12);
                        cmdIns.Parameters.Add("@DocNumber", SqlDbType.NVarChar, 12);

                        for (byte ins = 0; ins < this.dgvView.RowCount; ins++)
                        {
                            cmdIns.Parameters["@AutoID"].Value       = ins;
                            cmdIns.Parameters["@MaterialCode"].Value = this.dgvView["clnMaterialCode", ins].Value.ToString();
                            cmdIns.Parameters["@MaterialName"].Value = this.dgvView["clnMaterialName", ins].Value.ToString();
                            cmdIns.Parameters["@GIQuantity"].Value   = Convert.ToDouble(this.dgvView["clnQuantity", ins].Value.ToString());
                            cmdIns.Parameters["@UnitCode"].Value     = this.dgvView["clnUnitCode", ins].Value.ToString();
                            cmdIns.Parameters["@UnitName"].Value     = this.dgvView["clnUnitName", ins].Value.ToString();
                            cmdIns.Parameters["@CurrentUser"].Value  = NP_Cls.strUsr;
                            cmdIns.Parameters["@PlantCode"].Value    = this.dgvView["clnPlantCode", ins].Value.ToString();
                            cmdIns.Parameters["@PlantName"].Value    = this.dgvView["clnPlantName", ins].Value.ToString();
                            cmdIns.Parameters["@LocCode"].Value      = this.dgvView["clnLocCode", ins].Value.ToString();
                            cmdIns.Parameters["@LocName"].Value      = this.dgvView["clnLocName", ins].Value.ToString();
                            cmdIns.Parameters["@PrdONumber"].Value   = this.txtPrdOrder.Text.Trim();
                            cmdIns.Parameters["@DocNumber"].Value    = tmpString;
                            cmdIns.Parameters["@BatchNumber"].Value  = this.dgvView["clnBatch", ins].Value.ToString();

                            cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr;
                            cmdIns.ExecuteNonQuery();
                        }

                        Tr.Commit(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Save Production Order Completed !!");
                        Clear(); this.btnSave.Visible = false;
                        this.MyGrid(dgvView); this.txtPrdOrder.DropDownStyle = ComboBoxStyle.Simple;
                        BindCB();
                        this.cbMaterialCode.Enabled = true;
                        this.cbMaterialCode.Text    = string.Empty; this.cbMaterialCode.Select(); this.cbMaterialCode.SelectAll();
                    }
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add Detail : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #29
0
        private void btnNewVer_Click(object sender, EventArgs e)
        {
            if (NP.MSGB("Do you want to Create New Version ?") == DialogResult.Yes)
            {
                //this.txtVersion.Text = (Convert.ToInt16(this.txtVersion.Text.Trim()) + 1).ToString();
                //this.cbBOMType.SelectedIndex = 0; this.cbUnit.SelectedIndex = 0;
                //this.txtQty.Text = string.Empty; this.cbMaterial.Enabled = false; this.cbPlant.Enabled = false;

                //            NP_Cls.SqlSelect = "SELECT 0 as ItemNo,    m_Unit.UnitName, t_BOMDetail.Category, t_BOMDetail.MaterialCode, m_Material.MaterialName, t_BOMDetail.Quantity, t_BOM.BOMCode,  t_BOMDetail.BOMDetailCode, t_BOM.Approve, t_BOM.BOMVersion " +
                //            "FROM         t_BOM INNER JOIN " +
                //                      "m_Unit ON t_BOM.UnitCode = m_Unit.UnitCode INNER JOIN " +
                //                      "t_BOMDetail ON t_BOM.BOMCode = t_BOMDetail.BOMCode INNER JOIN " +
                //                      "m_Material ON t_BOMDetail.MaterialCode = m_Material.MaterialCode " +
                //"WHERE     (t_BOM.FileStatus = N'1') AND (t_BOM.PlantCode = N'') AND (t_BOM.MaterialCode = N'')";
                //            this.dgvView.DataSource = NP.GetClientDataSet(NP_Cls.SqlSelect).Tables[0]; this.btnVerAppr.Visible = false; this.btnVerNot.Visible = false;


                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction();
                try
                {
                    SqlCommand cmdEdit = new SqlCommand();
                    NP_Cls.sqlUpdate = "INSERT INTO t_BOM " +
                                       "(MaterialCode, PlantCode, BOMType, UnitCode, Quantity, BOMVersion, UserCreate, DateCreate, FileStatus, Approve, Remark) " +
                                       "SELECT   MaterialCode, PlantCode, BOMType, UnitCode, Quantity, BOMVersion + 1 AS BOMVer, '" + NP_Cls.strUsr + "' AS UC, GETDATE(), FileStatus, 0 as Appr, Remark FROM t_BOM " +
                                       "WHERE (BOMCode = @BOMCode)";
                    cmdEdit.Parameters.Add("@BOMCode", SqlDbType.Int).Value = this.dgvView["clnBOMCode", this.dgvView.CurrentRow.Index].Value.ToString();
                    cmdEdit.Connection = oConn; cmdEdit.CommandText = NP_Cls.sqlUpdate; cmdEdit.Transaction = Tr;
                    cmdEdit.ExecuteNonQuery();

                    NP_Cls.SqlSelect = "SELECT BOMCode FROM t_BOM WHERE (MaterialCode = '" + this.dgvView["clnMaterialCode", this.dgvView.CurrentRow.Index].Value.ToString() + "') AND (PlantCode = '" + this.dgvView["clnPlantCode", this.dgvView.CurrentRow.Index].Value.ToString() + "') Order By BOMCode DESC";
                    string sBOMCode = NP.GetDataWithTran(NP_Cls.SqlSelect, Tr, oConn).Tables[0].Rows[0][0].ToString();
                    NP_Cls.sqlUpdate = "INSERT INTO t_BOMDetail " +
                                       "(BOMCode, Category, MaterialCode, Quantity, LossPercentage, UserCreate, DateCreate) " +
                                       "SELECT   '" + sBOMCode + "' AS BC, Category, MaterialCode, Quantity, LossPercentage, '" + NP_Cls.strUsr + "' AS UC, GETDATE() FROM t_BOMDetail " +
                                       "WHERE (BOMCode = @BOMCode)";
                    cmdEdit.Connection = oConn; cmdEdit.CommandText = NP_Cls.sqlUpdate; cmdEdit.Transaction = Tr;
                    cmdEdit.ExecuteNonQuery();

                    NP_Cls.sqlUpdate = "UPDATE  t_BOM SET FileStatus = @St WHERE (BOMCode = @BOMCode)";
                    //cmdEdit.Parameters.Add("@BOMCode", SqlDbType.Int).Value = this.dgvView["clnBOMCode",this.dgvView.CurrentRow.Index].Value.ToString();
                    cmdEdit.Parameters.Add("@St", SqlDbType.NVarChar, 1).Value = "D";

                    cmdEdit.Connection = oConn; cmdEdit.CommandText = NP_Cls.sqlUpdate; cmdEdit.Transaction = Tr;
                    cmdEdit.ExecuteNonQuery();

                    if (NP._TRanSave(oConn, Tr, NP_Cls.NPTranType.Update, "t_BOM:NewVersion", NP_Cls.strUsr))
                    {
                        Tr.Commit();
                        DGV(); Clear();
                        this.btnAdd.Visible = true; this.btnEdit.Visible = false;
                    }
                    else
                    {
                        NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Try Again !!"); return;
                    }
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Approve : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }
예제 #30
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if ((string.IsNullOrEmpty((this.cbMaterial.Text.Trim()))) || (this.cbMaterial.Text.Trim() == "((( Select Material )))"))
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please enter Material: !!"); this.cbMaterial.Select(); return;
            }
            if ((string.IsNullOrEmpty((this.cbPlant.Text.Trim()))) || (this.cbPlant.Text.Trim() == "((( Select Plant )))"))
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please enter Plant: !!"); this.cbPlant.Select(); return;
            }
            if (NP.ReqField(this.txtBaseQuantity, "Please enter Base Quantity !!") == false)
            {
                return;
            }
            if (NP.ReqField(this.txtStdManHour, "Please enter Standard Man Hour !!") == false)
            {
                return;
            }
            if (NP.ReqField(this.txtHour, "Please enter Hours !!") == false)
            {
                return;
            }
            if ((string.IsNullOrEmpty((this.cbWorkCenter.Text.Trim()))) || (this.cbWorkCenter.Text.Trim() == "((( Select WorkCenter )))"))
            {
                NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please enter Work Center: !!"); this.cbWorkCenter.Select(); return;
            }


            if (NP.MSGB("Do you want to Edit Data ?") == DialogResult.Yes)
            {
                oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB));
                if (oConn.State == ConnectionState.Open)
                {
                    oConn.Close();
                }
                oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction();
                try
                {
                    SqlCommand cmdIns = new SqlCommand();
                    NP_Cls.sqlUpdate = "UPDATE [dbo].[t_Routing] SET [Remark] = @Remark ,[BaseQuantity] = @BaseQuantity WHERE (t_Routing.MaterialCode = '" + cbMaterial.SelectedValue + "') AND (t_Routing.PlantCode = '" + cbPlant.SelectedValue + "') ";
                    cmdIns.Parameters.Add("@Remark", SqlDbType.NVarChar, 255).Value = this.txtRemark.Text.Trim();
                    cmdIns.Parameters.Add("@BaseQuantity", SqlDbType.Decimal).Value = Convert.ToDecimal(this.txtBaseQuantity.Text.Trim());
                    cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.sqlUpdate; cmdIns.Transaction = Tr;
                    cmdIns.ExecuteNonQuery();
                    cmdIns.Parameters.Clear();

                    NP_Cls.sqlUpdate = "UPDATE [dbo].[t_RoutingDetail] SET [LogDate] = GetDate() ,[STDManHour] = @STDManHour ,[Hours] = @Hours WHERE (t_RoutingDetail.MaterialCode = '" + cbMaterial.SelectedValue + "') AND (t_RoutingDetail.PlantCode = '" + cbPlant.SelectedValue + "') AND (t_RoutingDetail.WorkCenterCode = '" + cbWorkCenter.SelectedValue + "')";
                    cmdIns.Parameters.Add("@STDManHour", SqlDbType.Decimal).Value = Convert.ToDecimal(this.txtStdManHour.Text.Trim());
                    cmdIns.Parameters.Add("@Hours", SqlDbType.Decimal).Value      = Convert.ToDecimal(this.txtHour.Text.Trim());
                    cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.sqlUpdate; cmdIns.Transaction = Tr;
                    cmdIns.ExecuteNonQuery();

                    Tr.Commit();
                    DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Edit Data Completed !!");
                    this.cbWorkCenter.Text  = string.Empty; this.cbWorkCenter.Select();
                    this.txtStdManHour.Text = string.Empty; this.txtBaseQuantity.Text = string.Empty; this.txtRemark.Text = string.Empty; this.txtHour.Text = string.Empty;
                    this.btnAdd.Visible     = true; this.btnEdit.Visible = false;
                    this.cbMaterial.Enabled = true; this.cbPlant.Enabled = true; this.cbWorkCenter.Enabled = true;
                }
                catch (Exception ex)
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        Tr.Rollback();
                    }
                    NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return;
                }
                finally
                {
                    if (oConn.State == ConnectionState.Open)
                    {
                        oConn.Close();
                    }
                }
            }
            else
            {
                return;
            }
        }