private void btnSave_Click(object sender, EventArgs e) { if (NP.ReqField(this.txtCode, "Please enter Code: !!") == false) { return; } if (NP.ReqField(this.txtDescription, "Please enter Description: !!") == false) { return; } if (ChkDup()) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Code Duplicated !!"); this.txtCode.Select(); this.txtCode.SelectAll(); return; } if (NP.MSGB("Do you want to Add Data ?") == DialogResult.Yes) { try { DataRow dr; dr = dsPG.Tables[0].NewRow(); dr[0] = this.txtCode.Text.Trim(); dr[1] = this.txtDescription.Text.Trim(); dsPG.Tables[0].Rows.Add(dr); dsPG.WriteXml(NP_Cls.PathPG); dsPG.Clear(); Clear(); GetData(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Add Data Completed !!"); this.txtCode.Focus(); } catch (Exception ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return; } } else { return; } }
private void btnLogin_Click(object sender, EventArgs e) { if (!NP.ReqField(this.txtUserName, "Please enter UserName: !!")) { return; } if (!NP.ReqField(this.txtPassword, "Please enter Password: !!")) { return; } NP_Cls.SqlSelect = "SELECT UserName, Password, UserIP FROM s_User WHERE (UserName = '******'", "") + "') AND (Password = '******'", "") + "')"; DataSet dsUser = new DataSet(); dsUser = NP.GetClientDataSet(NP_Cls.SqlSelect); if (dsUser.Tables[0].Rows.Count > 0) { string strIP = string.Empty; //NP.getip(); if (string.IsNullOrEmpty(dsUser.Tables[0].Rows[0]["UserIP"].ToString())) { //NP_Cls.sqlUpdate = "UPDATE s_User SET UserIP = '" + strIP + "' WHERE (UserName = '******')"; //string strErr = string.Empty; //if (NP.SqlCmd(NP_Cls.sqlUpdate, ref strErr) == false) //{ //NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Warning !! : " + strErr); return; //}NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "You are login !!"); NP_Cls.strUsr = dsUser.Tables[0].Rows[0]["UserName"].ToString(); ManageMenu(NP_Cls.strUsr); this.txtUserName.Text = string.Empty; this.txtPassword.Text = string.Empty; this.txtUserName.Select(); frmMainMenu frmM = new frmMainMenu(); frmM.Show(); this.Hide(); } else { if (strIP == dsUser.Tables[0].Rows[0]["UserIP"].ToString()) { NP_Cls.strUsr = dsUser.Tables[0].Rows[0]["UserName"].ToString(); NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "You are login the same IP !!"); ManageMenu(NP_Cls.strUsr); this.txtUserName.Text = string.Empty; this.txtPassword.Text = string.Empty; this.txtUserName.Select(); frmMainMenu frmM = new frmMainMenu(); frmM.Show(); this.Hide(); } else { NP_Cls.strUsr = string.Empty; NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "You can not login with multi user !!"); return; } } } else { NP_Cls.strUsr = string.Empty; NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Invalid UserName or Password !!"); return; } }
private void btnOverview_Click(object sender, EventArgs e) { if (!NP.ReqField(this.txtBatchNumber, "Please enter Batch Number !!")) { return; } NP_Cls.SqlSelect = "SELECT m_Material.MaterialCode, m_Material.MaterialName, m_Material.MaterialTypeName, m_Unit.UnitName FROM m_Material INNER JOIN m_Unit ON m_Material.UnitCode = m_Unit.UnitCode WHERE (m_Material.MaterialCode = (select MaterialCode from t_StockOverview where t_StockOverview.BatchNumber = N'" + this.txtBatchNumber.Text.Trim() + "')) AND (m_Material.FileStatus = N'1')"; DataSet ds = new DataSet(); ds = NP.GetClientDataSet(NP_Cls.SqlSelect); if (ds.Tables[0].Rows.Count > 0) { if (!ds.Tables[0].Rows[0]["MaterialCode"].ToString().Contains(NP_Cls.MatCodeForDO)) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "BacthNumber Not Match With MaterialCode !!"); this.lblMatCode.Text = string.Empty; this.lblMatName.Text = string.Empty; this.lblMatType.Text = string.Empty; this.lblUnit.Text = string.Empty; this.txtQuantity.Text = string.Empty; this.txtBatchNumber.Select(); this.txtBatchNumber.SelectAll(); return; } this.lblMatCode.Text = ds.Tables[0].Rows[0]["MaterialCode"].ToString(); this.lblMatName.Text = ds.Tables[0].Rows[0]["MaterialName"].ToString(); this.lblMatType.Text = ds.Tables[0].Rows[0]["MaterialTypeName"].ToString(); this.lblUnit.Text = ds.Tables[0].Rows[0]["UnitName"].ToString(); NP_Cls.SqlSelect = "SELECT MaterialCode,BatchNumber, UR FROM t_StockOverview WHERE (BatchNumber = N'" + this.txtBatchNumber.Text.Trim() + "')"; DataSet ds1 = new DataSet(); ds1 = NP.GetClientDataSet(NP_Cls.SqlSelect); //LimitQty = Convert.ToDecimal(ds1.Tables[0].Rows[0]["UR"].ToString()); this.txtQuantity.Text = Convert.ToDecimal(ds1.Tables[0].Rows[0]["UR"].ToString()).ToString("#,#0.000"); this.txtQuantity.Select(); this.txtQuantity.SelectAll(); } else { this.lblMatCode.Text = string.Empty; this.lblMatName.Text = string.Empty; this.lblMatType.Text = string.Empty; this.lblUnit.Text = string.Empty; this.txtQuantity.Text = string.Empty; this.dataGridView1.DataSource = null; NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Data Not Found !!"); this.txtBatchNumber.Select(); this.txtBatchNumber.SelectAll(); return; } }
private void btnAddDetail_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.cbMaterial.Text.Trim())) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please add Transfer Header first !!"); return; } else { if (this.cbMaterial.SelectedIndex == 0) { NP.ReqField(this.cbMaterial, "Please select material first !!"); return; } else { if (this.dsPR.Tables[0].Rows.Count > 0) { for (byte ii = 0; ii < this.dsPR.Tables[0].Rows.Count; ii++) { if ((this.cbMaterial.Text.Trim().Split(':')[0].ToString() == this.dsPR.Tables[0].Rows[ii]["MaterialCode"].ToString()) && (this.cbMaterial.Text.Trim().Split(':')[1].ToString() == this.dsPR.Tables[0].Rows[ii]["BatchNumber"].ToString())) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "This material is in Transfer List !!"); this.cbMaterial.Select(); return; } } } else if (this.dsPR.Tables[0].Rows.Count == 0) { // NP_Cls.SqlSelect = "SELECT 1 AS ItemNo, t_StockOverview.MaterialCode, m_Material.MaterialName, t_StockOverview.BatchNumber, t_StockOverview.UR, t_StockOverview.QI, t_StockOverview.Block, 0 AS TranQuantity, m_Unit.UnitName, m_Plant.PlantName, m_Location.LocName, t_StockOverview.PlantCode, t_StockOverview.LocCode, t_StockOverview.UnitCode FROM t_StockOverview INNER JOIN m_Material ON t_StockOverview.MaterialCode = m_Material.MaterialCode INNER JOIN m_Unit ON t_StockOverview.UnitCode = m_Unit.UnitCode INNER JOIN m_Plant ON t_StockOverview.PlantCode = m_Plant.PlantCode INNER JOIN m_Location ON t_StockOverview.LocCode = m_Location.LocCode WHERE (t_StockOverview.MaterialCode = '" + this.cbMaterial.Text.Trim().Split(':')[0].Trim() + "') AND (t_StockOverview.BatchNumber = '" + this.cbMaterial.Text.Trim().Split(':')[1].Trim() + "')"; DataSet ds = new DataSet(); ds = NP.GetClientDataSet(NP_Cls.SqlSelect); foreach (DataRow item in ds.Tables[0].Rows) { this.dsPR.Tables[0].ImportRow(item); } for (byte ii = 0; ii < this.dsPR.Tables[0].Rows.Count; ii++) { this.dsPR.Tables[0].Rows[ii]["ItemNo"] = Convert.ToInt32(ii + 1); } this.dsPR.AcceptChanges(); this.dgvView.DataSource = this.dsPR.Tables[0]; this.dgvView.ClearSelection(); return; // } // if Row > 1 DataRow dr; dr = this.dsPR.Tables[0].NewRow(); NP_Cls.SqlSelect = "SELECT 1 AS ItemNo, t_StockOverview.MaterialCode, m_Material.MaterialName, t_StockOverview.BatchNumber, t_StockOverview.UR, t_StockOverview.QI, t_StockOverview.Block, 0 AS TranQuantity, m_Unit.UnitName, m_Plant.PlantName, m_Location.LocName, t_StockOverview.PlantCode, t_StockOverview.LocCode, t_StockOverview.UnitCode FROM t_StockOverview INNER JOIN m_Material ON t_StockOverview.MaterialCode = m_Material.MaterialCode INNER JOIN m_Unit ON t_StockOverview.UnitCode = m_Unit.UnitCode INNER JOIN m_Plant ON t_StockOverview.PlantCode = m_Plant.PlantCode INNER JOIN m_Location ON t_StockOverview.LocCode = m_Location.LocCode WHERE (t_StockOverview.MaterialCode = '" + this.cbMaterial.Text.Trim().Split(':')[0].Trim() + "') AND (t_StockOverview.BatchNumber = '" + this.cbMaterial.Text.Trim().Split(':')[1].Trim() + "')"; DataSet ds2 = new DataSet(); ds2 = NP.GetClientDataSet(NP_Cls.SqlSelect); foreach (DataRow item in ds2.Tables[0].Rows) { this.dsPR.Tables[0].ImportRow(item); } for (byte ii = 0; ii < this.dsPR.Tables[0].Rows.Count; ii++) { this.dsPR.Tables[0].Rows[ii]["ItemNo"] = Convert.ToInt32(ii + 1); } this.dsPR.AcceptChanges(); this.dgvView.DataSource = this.dsPR.Tables[0]; this.dgvView.ClearSelection(); } } }
private void btnAddDetail_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.cbMaterial.Text.Trim())) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please add PO Header first !!"); return; } else { if (this.cbMaterial.SelectedIndex == 0) { NP.ReqField(this.cbMaterial, "Please select material first !!"); return; } else { if (this.dsPR.Tables[0].Rows.Count > 0) { for (byte ii = 0; ii < this.dsPR.Tables[0].Rows.Count; ii++) { if ((this.cbMaterial.Text.Trim().Split(':')[1].ToString() == this.dsPR.Tables[0].Rows[ii]["MaterialCode"].ToString()) && (this.cbMaterial.Text.Trim().Split(':')[0].ToString() == this.dsPR.Tables[0].Rows[ii]["PRNumber"].ToString())) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "This material is in PO List !!"); this.cbMaterial.Select(); return; } } } else if (this.dsPR.Tables[0].Rows.Count == 0) { // NP_Cls.SqlSelect = "SELECT t_PRDetail.AutoID,1 AS ItemNo, t_PRDetail.MaterialCode, t_PRDetail.MaterialName, t_PRDetail.PRQuantity AS Qty, t_PRDetail.UnitCode, t_PRDetail.UnitName, t_PRDetail.NetPrice, t_PRDetail.PRAmount AS Amt, t_PRDetail.DeliveryDate, t_PR.PRNumber, t_PRDetail.PlantCode, t_PRDetail.PlantName, t_PRDetail.LocCode, t_PRDetail.LocName FROM t_PRDetail INNER JOIN t_PR ON t_PRDetail.PRNumber = t_PR.PRNumber WHERE (t_PRDetail.MaterialCode = N'" + this.cbMaterial.Text.Trim().Split(':')[1].ToString() + "') AND (t_PR.VendorCode = N'" + this.cbVendor.Text.Trim().Split(':')[0] + "') AND (t_PR.PRNumber = N'" + this.cbMaterial.Text.Trim().Split(':')[0].ToString() + "')"; DataSet ds = new DataSet(); ds = NP.GetClientDataSet(NP_Cls.SqlSelect); foreach (DataRow item in ds.Tables[0].Rows) { this.dsPR.Tables[0].ImportRow(item); } for (byte ii = 0; ii < this.dsPR.Tables[0].Rows.Count; ii++) { this.dsPR.Tables[0].Rows[ii]["ItemNo"] = Convert.ToInt32(ii + 1); } this.dsPR.AcceptChanges(); this.dgvView.DataSource = this.dsPR.Tables[0]; return; // } // if Row > 1 DataRow dr; dr = this.dsPR.Tables[0].NewRow(); NP_Cls.SqlSelect = "SELECT t_PRDetail.AutoID,1 AS ItemNo, t_PRDetail.MaterialCode, t_PRDetail.MaterialName, t_PRDetail.PRQuantity AS Qty, t_PRDetail.UnitCode, t_PRDetail.UnitName, t_PRDetail.NetPrice, t_PRDetail.PRAmount AS Amt, t_PRDetail.DeliveryDate, t_PR.PRNumber, t_PRDetail.PlantCode, t_PRDetail.PlantName, t_PRDetail.LocCode, t_PRDetail.LocName FROM t_PRDetail INNER JOIN t_PR ON t_PRDetail.PRNumber = t_PR.PRNumber WHERE (t_PRDetail.MaterialCode = N'" + this.cbMaterial.Text.Trim().Split(':')[1].ToString() + "') AND (t_PR.VendorCode = N'" + this.cbVendor.Text.Trim().Split(':')[0] + "') AND (t_PR.PRNumber = N'" + this.cbMaterial.Text.Trim().Split(':')[0].ToString() + "')"; DataSet ds2 = new DataSet(); ds2 = NP.GetClientDataSet(NP_Cls.SqlSelect); foreach (DataRow item in ds2.Tables[0].Rows) { this.dsPR.Tables[0].ImportRow(item); } for (byte ii = 0; ii < this.dsPR.Tables[0].Rows.Count; ii++) { this.dsPR.Tables[0].Rows[ii]["ItemNo"] = Convert.ToInt32(ii + 1); } this.dsPR.AcceptChanges(); this.dgvView.DataSource = this.dsPR.Tables[0]; } } }
private void btnOverview_Click(object sender, EventArgs e) { if (!NP.ReqField(this.txtMatCode, "Please enter Material Code !!")) { return; } NP_Cls.SqlSelect = "SELECT t_StockMovement.DocNumber, t_StockMovement.TranDate, t_StockMovement.MovementType, t_StockMovementDetail.MaterialCode, t_StockMovementDetail.MaterialName, t_StockMovementDetail.Quantity, t_StockMovementDetail.UnitCode, t_StockMovementDetail.RefNumber, '' AS CL FROM t_StockMovement INNER JOIN t_StockMovementDetail ON t_StockMovement.DocNumber = t_StockMovementDetail.DocNumber WHERE (t_StockMovementDetail.MaterialCode = N'" + this.txtMatCode.Text.Trim() + "' AND t_StockMovementDetail.RefNumber not like '%X%') ORDER BY t_StockMovement.TranDate"; DataSet ds = new DataSet(); ds = NP.GetClientDataSet(NP_Cls.SqlSelect); if (ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (ds.Tables[0].Rows[i]["DocNumber"].ToString().Contains("TR")) { if (ds.Tables[0].Rows[i]["RefNumber"].ToString().Contains("X")) { ds.Tables[0].Rows[i]["CL"] = "red"; } else { ds.Tables[0].Rows[i]["CL"] = "green"; } } else if (ds.Tables[0].Rows[i]["DocNumber"].ToString().Contains("GR")) { ds.Tables[0].Rows[i]["CL"] = "green"; } else if (ds.Tables[0].Rows[i]["DocNumber"].ToString().Contains("PD")) { ds.Tables[0].Rows[i]["CL"] = "red"; } } this.pDesc.Visible = true; this.lblMatName.Text = ds.Tables[0].Rows[0]["MaterialName"].ToString(); this.dataGridView1.DataSource = ds.Tables[0]; this.dataGridView1.ClearSelection(); for (int d = 0; d < this.dataGridView1.RowCount; d++) { if (this.dataGridView1["clnCL", d].Value.ToString().IndexOf("red") > -1) { this.dataGridView1.Rows[d].DefaultCellStyle.BackColor = Color.LightCoral; } else if (this.dataGridView1["clnCL", d].Value.ToString().IndexOf("green") > -1) { this.dataGridView1.Rows[d].DefaultCellStyle.BackColor = Color.PaleGreen; } } this.dataGridView1.Columns["clnCL"].Visible = false; } else { this.pDesc.Visible = false; NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Data Not Found !!"); this.txtMatCode.Select(); this.txtMatCode.SelectAll(); return; } }
private void btnUpdate_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.cbPONumber.Text.Trim())) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please add GT Header first !!"); return; } else { if (this.cbPONumber.SelectedIndex == 0) { NP.ReqField(this.cbPONumber, "Please select GR Number first !!"); return; } else { if (this.dsPR.Tables[0].Rows.Count > 0) { for (byte ii = 0; ii < this.dsPR.Tables[0].Rows.Count; ii++) { if (this.cbPONumber.Text.Trim() == this.dsPR.Tables[0].Rows[ii]["GRNumber"].ToString()) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "This GR Number is in GT List !!"); this.cbPONumber.Select(); return; } } } else if (this.dsPR.Tables[0].Rows.Count == 0) { // NP_Cls.SqlSelect = "SELECT 0 AS ItemNo, t_GRDetail.MaterialCode, t_GRDetail.MaterialName, t_GRDetail.GRQuantity AS GTQty, t_GRDetail.UnitCode, t_GRDetail.UnitName, t_GRDetail.PlantCode, t_GRDetail.LocCode, t_GRDetail.BatchNumber, t_GRDetail.DeliveryDate, t_GRDetail.GRNumber, t_GRDetail.NetPrice, t_GRDetail.GRAmount AS GTAmt, t_GRDetail.PlantName, t_GRDetail.LocName, t_GRDetail.AutoID FROM t_GR INNER JOIN t_GRDetail ON t_GR.GRNumber = t_GRDetail.GRNumber WHERE (t_GRDetail.GRNumber = N'" + this.cbPONumber.Text.Trim() + "') AND (t_GR.VendorCode = N'" + this.cbVendor.Text.Trim() + "') AND (t_GR.MovementType = N'101')"; this.dsPR = NP.GetClientDataSet(NP_Cls.SqlSelect); for (byte ii = 0; ii < this.dsPR.Tables[0].Rows.Count; ii++) { this.dsPR.Tables[0].Rows[ii]["ItemNo"] = Convert.ToInt32(ii + 1); } this.dsPR.AcceptChanges(); this.dgvView.DataSource = this.dsPR.Tables[0]; return; // } // if Row > 1 NP_Cls.SqlSelect = "SELECT 0 AS ItemNo, t_GRDetail.MaterialCode, t_GRDetail.MaterialName, t_GRDetail.GRQuantity AS GTQty, t_GRDetail.UnitCode, t_GRDetail.UnitName, t_GRDetail.PlantCode, t_GRDetail.LocCode, t_GRDetail.BatchNumber, t_GRDetail.DeliveryDate, t_GRDetail.GRNumber, t_GRDetail.NetPrice, t_GRDetail.GRAmount AS GTAmt, t_GRDetail.PlantName, t_GRDetail.LocName, t_GRDetail.AutoID FROM t_GR INNER JOIN t_GRDetail ON t_GR.GRNumber = t_GRDetail.GRNumber WHERE (t_GRDetail.GRNumber = N'" + this.cbPONumber.Text.Trim() + "') AND (t_GR.VendorCode = N'" + this.cbVendor.Text.Trim() + "') AND (t_GR.MovementType = N'101')"; DataSet ds = new DataSet(); ds = NP.GetClientDataSet(NP_Cls.SqlSelect); foreach (DataRow item in ds.Tables[0].Rows) { this.dsPR.Tables[0].ImportRow(item); } for (byte ii = 0; ii < this.dsPR.Tables[0].Rows.Count; ii++) { this.dsPR.Tables[0].Rows[ii]["ItemNo"] = Convert.ToInt32(ii + 1); } this.dsPR.AcceptChanges(); this.dgvView.DataSource = this.dsPR.Tables[0]; } } }
private void btnAdd_Click(object sender, EventArgs e) { try { if (NP.ReqField(this.cbDepartment, "Please enter Department: !!") == false) { return; } if (NP.ReqField(this.cbLevel, "Please enter Level: !!") == false) { 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(); try { SqlCommand cmdIns = new SqlCommand(); NP_Cls.SqlInsert = "INSERT INTO s_Level " + "(DepartmentCode, AuthLevel, Per, UserCreate, DateCreate, FileStatus) " + "VALUES (@DepartmentCode,@AuthLevel,@Per,@UC, GETDATE(),@St)"; cmdIns.Parameters.Add("@DepartmentCode", SqlDbType.NVarChar, 3).Value = this.cbDepartment.SelectedValue; cmdIns.Parameters.Add("@AuthLevel", SqlDbType.NVarChar, 1).Value = this.cbLevel.Text.Trim(); cmdIns.Parameters.Add("@Per", SqlDbType.NVarChar).Value = ((string)GenPer()); cmdIns.Parameters.Add("@UC", SqlDbType.NVarChar, 10).Value = NP_Cls.strUsr; cmdIns.Parameters.Add("@St", SqlDbType.NVarChar, 1).Value = "1"; cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.ExecuteNonQuery(); Clear(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Add Data Completed !!"); this.cbDepartment.Select(); } catch (Exception ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return; } finally { if (oConn.State == ConnectionState.Open) { oConn.Close(); } } } else { return; } } catch (Exception ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return; } }
private void btnOverview_Click(object sender, EventArgs e) { if (!NP.ReqField(this.txtMatCode, "Please enter Material Code !!")) { return; } NP_Cls.SqlSelect = "SELECT m_Material.MaterialCode, m_Material.MaterialName, m_Material.MaterialTypeName, m_Unit.UnitName FROM m_Material INNER JOIN m_Unit ON m_Material.UnitCode = m_Unit.UnitCode WHERE (m_Material.MaterialCode = N'" + this.txtMatCode.Text.Trim() + "') AND (m_Material.FileStatus = N'1')"; DataSet ds = new DataSet(); ds = NP.GetClientDataSet(NP_Cls.SqlSelect); if (ds.Tables[0].Rows.Count > 0) { this.pDesc.Visible = true; this.lblMatName.Text = ds.Tables[0].Rows[0]["MaterialName"].ToString(); this.lblMatType.Text = ds.Tables[0].Rows[0]["MaterialTypeName"].ToString(); this.lblUnit.Text = ds.Tables[0].Rows[0]["UnitName"].ToString(); NP_Cls.SqlSelect = "SELECT BatchNumber, UR , QI, Block FROM t_StockOverview WHERE (MaterialCode = N'" + this.txtMatCode.Text.Trim() + "')"; this.dataGridView1.DataSource = NP.GetClientDataSet(NP_Cls.SqlSelect).Tables[0]; } else { this.pDesc.Visible = false; NP_Cls.SqlSelect = "SELECT BatchNumber, UR, QI, Block FROM t_StockOverview WHERE (MaterialCode = N'" + this.txtMatCode.Text.Trim() + "')"; this.dataGridView1.DataSource = NP.GetClientDataSet(NP_Cls.SqlSelect).Tables[0]; NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Data Not Found !!"); this.txtMatCode.Select(); this.txtMatCode.SelectAll(); return; } }
private void btnAdd_Click(object sender, EventArgs e) { if (!NP.ReqField(this.cbMaterialCode, "Please select Material !!")) { return; } if (!NP.ReqField(this.txtBatch, "Please entry Batch Number !!")) { return; } if (!NP.ReqField(this.txtQty, "Please select Quantity !!")) { return; } try { if (!string.IsNullOrEmpty(this.txtQty.Text.Trim())) { if (Convert.ToDouble(this.txtQty.Text.Trim()) <= 0) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please enter Qty: greater than 0 !!"); this.txtQty.Select(); this.txtQty.SelectAll(); return; } NP_Cls.SqlSelect = "SELECT 0 AS ItemNo, t_StockOverview.MaterialCode, m_Material.MaterialName, t_StockOverview.BatchNumber, t_StockOverview.UR, " + this.txtQty.Text.Trim() + " AS Qty, t_StockOverview.UnitCode, m_Unit.UnitName, t_StockOverview.PlantCode, m_Plant.PlantName, t_StockOverview.LocCode, m_Location.LocName FROM m_Material INNER JOIN t_StockOverview ON m_Material.MaterialCode = t_StockOverview.MaterialCode INNER JOIN m_Unit ON t_StockOverview.UnitCode = m_Unit.UnitCode INNER JOIN m_Plant ON t_StockOverview.PlantCode = m_Plant.PlantCode INNER JOIN m_Location ON t_StockOverview.LocCode = m_Location.LocCode WHERE (m_Material.MaterialCode = N'" + this.cbMaterialCode.Text.Trim().Split(':')[0].Trim() + "') AND ( t_StockOverview.BatchNumber = '" + this.txtBatch.Text.Trim() + "')"; DataSet dsTmp = new DataSet(); dsTmp = NP.GetClientDataSet(NP_Cls.SqlSelect); if (dsTmp.Tables[0].Rows.Count == 0) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Not found this Material in Stock .. Cannot Issue !!"); this.btnSave.Visible = false; this.cbMaterialCode.Select(); this.cbMaterialCode.SelectAll(); return; } else { if ((double.Parse(dsTmp.Tables[0].Rows[0]["UR"].ToString()) <= 0) || (string.IsNullOrEmpty(dsTmp.Tables[0].Rows[0]["UR"].ToString()))) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "UR Quantity = 0 .. Cannot Issue !!"); this.btnSave.Visible = false; this.cbMaterialCode.Select(); this.cbMaterialCode.SelectAll(); return; } else if (double.Parse(dsTmp.Tables[0].Rows[0]["UR"].ToString()) < double.Parse(this.txtQty.Text.Trim())) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "UR Quantity less than Issue Quantity .. Cannot Issue !!"); this.btnSave.Visible = false; this.txtQty.Select(); this.txtQty.SelectAll(); return; } this.btnSave.Visible = true; } for (int i = 0; i < dsTmp.Tables[0].Rows.Count; i++) { dsTmp.Tables[0].Rows[i][0] = i + 1; } this.dgvView.DataSource = dsTmp.Tables[0]; } else { this.txtQty.Select(); this.txtQty.SelectAll(); } } catch (SqlException ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Detail : " + ex.Message); return; } }
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; } }
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; } }
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; } }
private void btnAddDetail_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.cbSO.Text.Trim()) || (this.cbSO.SelectedIndex == 0)) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please add DO Header first !!"); this.cbSO.Select(); this.cbSO.SelectAll(); return; } else if (string.IsNullOrEmpty(this.cbMaterial.Text.Trim()) || (this.cbMaterial.SelectedIndex == 0)) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please select material first !!"); this.cbMaterial.Select(); this.cbMaterial.SelectAll(); return; } else { string strTmpCode = string.Empty; double dStock = 0.0; if (this.cbSO.SelectedIndex == 0) { NP.ReqField(this.cbSO, "Please select SO Number first !!"); return; } else { if (this.dsPR.Tables[0].Rows.Count > 0) { for (byte ii = 0; ii < this.dsPR.Tables[0].Rows.Count; ii++) { if (this.cbMaterial.SelectedValue.ToString() == this.dsPR.Tables[0].Rows[ii]["AutoID"].ToString()) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "This SO Number is in DO List !!"); this.cbSO.Select(); return; } } } else if (this.dsPR.Tables[0].Rows.Count == 0) { // NP_Cls.SqlSelect = "SELECT 1 AS ItemNo,'' as BatchNumber,t_SODetail.DOQuantity, t_SODetail.MaterialCode, t_SODetail.MaterialName, isnull(t_SODetail.SOQuantity,0) - isnull(t_SODetail.DOQuantity,0) AS Qty, t_SODetail.UnitCode, t_SODetail.UnitName, t_SODetail.NetPrice, t_SODetail.SOAmount AS Amt, t_SODetail.DeliveryDate, t_SODetail.PlantCode, t_SODetail.PlantName, t_SODetail.LocCode, t_SODetail.LocName, t_SO.SONumber, t_SODetail.AutoID, ISNULL(t_StockOverview.UR,0) AS UR,t_SODetail.SOQuantity AS TmpSO FROM t_SO INNER JOIN t_SODetail ON t_SO.SONumber = t_SODetail.SONumber LEFT OUTER JOIN t_StockOverview ON t_SODetail.MaterialCode = t_StockOverview.MaterialCode WHERE (t_SODetail.AutoID = N'" + this.cbMaterial.SelectedValue + "') ORDER BY t_SODetail.MaterialCode, t_SODetail.DeliveryDate"; DataSet ds = new DataSet(); ds = NP.GetClientDataSet(NP_Cls.SqlSelect); foreach (DataRow item in ds.Tables[0].Rows) { this.dsPR.Tables[0].ImportRow(item); } //strTmpCode = string.Empty; dStock = 0.0; //for (byte ii = 0; ii < this.dsPR.Tables[0].Rows.Count; ii++) //{ // this.dsPR.Tables[0].Rows[ii]["ItemNo"] = Convert.ToInt32(ii + 1); // //this.dsPR.Tables[0].Rows[ii]["Qty"] = Convert.ToDecimal(this.dsPR.Tables[0].Rows[ii]["Qty"]) - Convert.ToDecimal(this.dsPR.Tables[0].Rows[ii]["DOQuantity"]); // if (ii > 0) // { // if (this.dsPR.Tables[0].Rows[ii]["MaterialCode"].ToString().Trim().Contains(strTmpCode)) // { // if (dStock > 0) // { // dStock -= double.Parse(this.dsPR.Tables[0].Rows[ii]["Qty"].ToString()); // } // this.dsPR.Tables[0].Rows[ii]["UR"] = dStock; // } // else // { // dStock = double.Parse(this.dsPR.Tables[0].Rows[ii]["UR"].ToString()); // } // } //} this.dsPR.AcceptChanges(); this.dgvView.DataSource = this.dsPR.Tables[0]; this.dgvView.ClearSelection(); return; // } // if Row > 1 DataRow dr; dr = this.dsPR.Tables[0].NewRow(); NP_Cls.SqlSelect = "SELECT 1 AS ItemNo,'' as BatchNumber,t_SODetail.DOQuantity, t_SODetail.MaterialCode, t_SODetail.MaterialName, isnull(t_SODetail.SOQuantity,0) - isnull(t_SODetail.DOQuantity,0) AS Qty, t_SODetail.UnitCode, t_SODetail.UnitName, t_SODetail.NetPrice, t_SODetail.SOAmount AS Amt, t_SODetail.DeliveryDate, t_SODetail.PlantCode, t_SODetail.PlantName, t_SODetail.LocCode, t_SODetail.LocName, t_SO.SONumber, t_SODetail.AutoID, ISNULL(t_StockOverview.UR,0) AS UR,t_SODetail.SOQuantity AS TmpSO FROM t_SO INNER JOIN t_SODetail ON t_SO.SONumber = t_SODetail.SONumber LEFT OUTER JOIN t_StockOverview ON t_SODetail.MaterialCode = t_StockOverview.MaterialCode WHERE (t_SODetail.AutoID = N'" + this.cbMaterial.SelectedValue + "') ORDER BY t_SODetail.MaterialCode, t_SODetail.DeliveryDate"; DataSet ds2 = new DataSet(); ds2 = NP.GetClientDataSet(NP_Cls.SqlSelect); foreach (DataRow item in ds2.Tables[0].Rows) { this.dsPR.Tables[0].ImportRow(item); } //strTmpCode = string.Empty; dStock = 0.0; //for (byte ii = 0; ii < this.dsPR.Tables[0].Rows.Count; ii++) //{ // this.dsPR.Tables[0].Rows[ii]["ItemNo"] = Convert.ToInt32(ii + 1); // //this.dsPR.Tables[0].Rows[ii]["Qty"] = Convert.ToDecimal(this.dsPR.Tables[0].Rows[ii]["Qty"]) - Convert.ToDecimal(this.dsPR.Tables[0].Rows[ii]["DOQuantity"]); // if (ii > 0) // { // if (this.dsPR.Tables[0].Rows[ii]["MaterialCode"].ToString().Trim().Contains(strTmpCode)) // { // if (dStock > 0) // { // dStock -= double.Parse(this.dsPR.Tables[0].Rows[ii]["Qty"].ToString()); // } // this.dsPR.Tables[0].Rows[ii]["UR"] = dStock; // } // else // { // dStock = double.Parse(this.dsPR.Tables[0].Rows[ii]["UR"].ToString()); // } // } //} this.dsPR.AcceptChanges(); this.dgvView.DataSource = this.dsPR.Tables[0]; this.dgvView.ClearSelection(); } } }
private void btnAddDetail_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.cbMaterial.Text.Trim())) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please add GI Header first !!"); return; } else { if (this.cbMaterial.SelectedIndex == 0) { NP.ReqField(this.cbMaterial, "Please select material first !!"); return; } else { if (this.dsPR.Tables[0].Rows.Count > 0) { //if (this.moreMat == 0) //{ // for (byte ii = 0; ii < this.dsPR.Tables[0].Rows.Count; ii++) // { // if (this.cbMaterial.Text.Trim() == this.dsPR.Tables[0].Rows[ii]["MaterialCode"].ToString()) // { // NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "This material is in GI List !!"); this.cbMaterial.Select(); return; // } // } //} } else if (this.dsPR.Tables[0].Rows.Count == 0) { // NP_Cls.SqlSelect = "SELECT top(1) 1 AS ItemNo, t_PrdOrderDetail.UnitCode, t_PrdOrderDetail.UnitName, t_PrdOrderDetail.PlantCode, t_PrdOrderDetail.PlantName, t_PrdOrderDetail.LocCode, t_PrdOrderDetail.LocName, t_PrdOrderDetail.PrdONumber, t_PrdOrderDetail.ComponentCode AS MaterialCode, t_PrdOrderDetail.ComponentName AS MaterialName, t_PrdOrderDetail.PrdOQuantity AS Qty, t_PrdOrderDetail.PrdOQuantity AS PrdOQty, ISNULL(t_StockOverview.QI,0) AS QI, t_StockOverview.BatchNumber FROM t_PrdOrder INNER JOIN t_PrdOrderDetail ON t_PrdOrder.PrdONumber = t_PrdOrderDetail.PrdONumber LEFT OUTER JOIN t_StockOverview ON t_PrdOrderDetail.ComponentCode = t_StockOverview.MaterialCode WHERE (t_PrdOrderDetail.ComponentCode = N'" + this.cbMaterial.Text.Trim().Split(':')[0] + "') AND (t_PrdOrderDetail.PrdONumber = N'" + this.cbPrdoOrder.Text.Trim() + "') Order By BatchNumber "; DataSet ds = new DataSet(); ds = NP.GetClientDataSet(NP_Cls.SqlSelect); foreach (DataRow item in ds.Tables[0].Rows) { this.dsPR.Tables[0].ImportRow(item); } for (byte ii = 0; ii < this.dsPR.Tables[0].Rows.Count; ii++) { this.dsPR.Tables[0].Rows[ii]["ItemNo"] = Convert.ToInt32(ii + 1); } this.dsPR.AcceptChanges(); this.dgvView.DataSource = this.dsPR.Tables[0]; this.dgvView.ClearSelection(); return; // } // if Row > 1 DataRow dr; dr = this.dsPR.Tables[0].NewRow(); for (int mm = 0; mm < this.dgvView.RowCount; mm++) { if (this.dgvView["clnMaterialCode", mm].Value.ToString() == this.cbMaterial.Text.Trim().Split(':')[0]) { if (Convert.ToDouble(this.dgvView["clnFGStock", mm].Value) >= Convert.ToDouble(this.dgvView["clnQuantity", mm].Value)) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "This material is in GI List and enough for GI."); this.cbMaterial.Select(); return; } else { this.moreMat = 1; } } } if (this.moreMat == 0) { NP_Cls.SqlSelect = "SELECT Top(1) 1 AS ItemNo, t_PrdOrderDetail.UnitCode, t_PrdOrderDetail.UnitName, t_PrdOrderDetail.PlantCode, t_PrdOrderDetail.PlantName, t_PrdOrderDetail.LocCode, t_PrdOrderDetail.LocName, t_PrdOrderDetail.PrdONumber, t_PrdOrderDetail.ComponentCode AS MaterialCode, t_PrdOrderDetail.ComponentName AS MaterialName, t_PrdOrderDetail.PrdOQuantity AS Qty, t_PrdOrderDetail.PrdOQuantity AS PrdOQty, ISNULL(t_StockOverview.QI,0) AS QI, t_StockOverview.BatchNumber FROM t_PrdOrder INNER JOIN t_PrdOrderDetail ON t_PrdOrder.PrdONumber = t_PrdOrderDetail.PrdONumber LEFT OUTER JOIN t_StockOverview ON t_PrdOrderDetail.ComponentCode = t_StockOverview.MaterialCode WHERE (t_PrdOrderDetail.ComponentCode = N'" + this.cbMaterial.Text.Trim().Split(':')[0] + "') AND (t_PrdOrderDetail.PrdONumber = N'" + this.cbPrdoOrder.Text.Trim() + "') Order By BatchNumber"; } else { string strTmpB = string.Empty; for (int m = 0; m < this.dgvView.RowCount; m++) { if (this.cbMaterial.Text.Trim().Split(':')[0] == dgvView["clnMaterialCode", m].Value.ToString()) { if (string.IsNullOrEmpty(strTmpB)) { strTmpB = dgvView["clnBatchNumber", m].Value.ToString(); } else { strTmpB = "," + dgvView["clnBatchNumber", m].Value.ToString(); } } } NP_Cls.SqlSelect = "SELECT 1 AS ItemNo, t_PrdOrderDetail.UnitCode, t_PrdOrderDetail.UnitName, t_PrdOrderDetail.PlantCode, t_PrdOrderDetail.PlantName, t_PrdOrderDetail.LocCode, t_PrdOrderDetail.LocName, t_PrdOrderDetail.PrdONumber, t_PrdOrderDetail.ComponentCode AS MaterialCode, t_PrdOrderDetail.ComponentName AS MaterialName, t_PrdOrderDetail.PrdOQuantity AS Qty, t_PrdOrderDetail.PrdOQuantity AS PrdOQty, ISNULL(t_StockOverview.QI,0) AS QI, t_StockOverview.BatchNumber FROM t_PrdOrder INNER JOIN t_PrdOrderDetail ON t_PrdOrder.PrdONumber = t_PrdOrderDetail.PrdONumber LEFT OUTER JOIN t_StockOverview ON t_PrdOrderDetail.ComponentCode = t_StockOverview.MaterialCode WHERE (t_PrdOrderDetail.ComponentCode = N'" + this.cbMaterial.Text.Trim().Split(':')[0] + "') AND (t_PrdOrderDetail.PrdONumber = N'" + this.cbPrdoOrder.Text.Trim() + "') AND (t_StockOverview.BatchNumber NOT IN ('" + strTmpB + "'))"; } DataSet ds2 = new DataSet(); ds2 = NP.GetClientDataSet(NP_Cls.SqlSelect); foreach (DataRow item in ds2.Tables[0].Rows) { this.dsPR.Tables[0].ImportRow(item); } for (byte ii = 0; ii < this.dsPR.Tables[0].Rows.Count; ii++) { this.dsPR.Tables[0].Rows[ii]["ItemNo"] = Convert.ToInt32(ii + 1); } this.dsPR.AcceptChanges(); this.dgvView.DataSource = this.dsPR.Tables[0]; this.dgvView.ClearSelection(); } } }
private void btnAdd_Click(object sender, EventArgs e) { try { if (NP.ReqField(this.txtCode, "Please enter Material Code: !!") == false) { return; } if (NP.ReqField(this.txtBatch, "Please enter Batch: !!") == false) { return; } if (NP.ReqField(this.txtPlant, "Please enter Plant: !!") == false) { return; } if (NP.ReqField(this.txtLocation, "Please enter Location: !!") == false) { return; } if (NP.ReqField(this.txtUnit, "Please enter Unit: !!") == false) { return; } if (NP.ReqField(this.txtUR, "Please enter UR: !!") == false) { return; } if (NP.ReqField(this.txtQI, "Please enter QI: !!") == false) { return; } if (NP.ReqField(this.txtBlock, "Please enter Block: !!") == false) { return; } if (NP.ReqField(this.txtCost, "Please enter Cost: !!") == false) { return; } if (IsMaterial()) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Material Code is not in system !!"); this.txtCode.Select(); this.txtCode.SelectAll(); return; } if (ChkDup()) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Material Code & Batch Duplicated !!"); this.txtCode.Select(); this.txtCode.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(); try { SqlCommand cmdIns = new SqlCommand(); NP_Cls.SqlInsert = "INSERT INTO t_StockOverview " + "(MaterialCode, BatchNumber, PlantCode, LocCode, UnitCode, UR, QI, Block, Cost, UserCreate, DateCreate) " + "VALUES (@MaterialCode,@BatchNumber,@PlantCode,@LocCode,@UnitCode,@UR,@QI,@Block,@Cost,@UC,GETDATE())"; cmdIns.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15).Value = this.txtCode.Text.Trim(); cmdIns.Parameters.Add("@BatchNumber", SqlDbType.NVarChar, 10).Value = this.txtBatch.Text.Trim(); cmdIns.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4).Value = this.txtPlant.Text.Trim(); cmdIns.Parameters.Add("@LocCode", SqlDbType.NVarChar, 2).Value = this.txtLocation.Text.Trim(); cmdIns.Parameters.Add("@UnitCode", SqlDbType.NVarChar, 3).Value = this.txtUnit.Text.Trim(); cmdIns.Parameters.Add("@UR", SqlDbType.Decimal).Value = Convert.ToDecimal(this.txtUR.Text.Trim()); cmdIns.Parameters.Add("@QI", SqlDbType.Decimal).Value = Convert.ToDecimal(this.txtQI.Text.Trim()); cmdIns.Parameters.Add("@Block", SqlDbType.Decimal).Value = Convert.ToDecimal(this.txtBlock.Text.Trim()); cmdIns.Parameters.Add("@Cost", SqlDbType.Decimal).Value = Convert.ToDecimal(this.txtCost.Text.Trim()); cmdIns.Parameters.Add("@UC", SqlDbType.NVarChar, 20).Value = NP_Cls.strUsr; cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.ExecuteNonQuery(); Clear(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Add Data Completed !!"); this.txtCode.Focus(); } catch (Exception ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return; } finally { if (oConn.State == ConnectionState.Open) { oConn.Close(); } } } else { return; } } catch (Exception ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return; } }
private void btnAdd_Click(object sender, EventArgs e) { if (NP.ReqField(this.txtCode, "Please enter Code: !!") == false) { return; } if (NP.ReqField(this.txtName, "Please enter Name: !!") == false) { return; } if (NP.ReqField(this.cbPG, "Please enter Purchasing group: !!") == false) { return; } if (NP.ReqField(this.cbCurrencyCode, "Please enter Currency: !!") == false) { return; } if (NP.ReqField(this.txtTerm, "Please enter Term of patment: !!") == false) { return; } try { byte bRe = 0; if (ChkDup(ref bRe)) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Code Duplicated !!"); this.txtCode.Select(); this.txtCode.SelectAll(); return; } else { if (bRe == 1) { Clear(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Update Data Completed !!"); this.txtCode.Focus(); return; } } } catch (Exception ex) { NP.MSGB("Erro Dup : " + ex.Message); return; } if (NP.MSGB("Do you want to Add Data ?") == DialogResult.Yes) { oConn = new SqlConnection(NP.ReadFileDB(Application.StartupPath + @"\DB\DB.ini")); if (oConn.State == ConnectionState.Open) { oConn.Close(); } oConn.Open(); try { SqlCommand cmdIns = new SqlCommand(); NP_Cls.SqlInsert = "INSERT INTO m_Vendor (Remark,VendorCode, VendorName, PurchasingGroup,VendorAddress, VendorPostalCode, VendorTelephone, VendorFax, CurrencyCode, TermsOfPayment, UserCreate, DateCreate, FileStatus, VendorContactPerson, VendorMobile, VendorEmail) VALUES (@Remark,@Code,@Name,@PG,@Address,@PostalCode,@Tel,@Fax,@OrderCurr,@Terms,@UC,getdate(),@St,@ContactP,@Mobile,@Email)"; cmdIns.Parameters.Add("@Code", SqlDbType.NVarChar, 10).Value = this.txtCode.Text.Trim(); cmdIns.Parameters.Add("@Name", SqlDbType.NVarChar, 60).Value = this.txtName.Text.Trim(); cmdIns.Parameters.Add("@PG", SqlDbType.NVarChar, 3).Value = this.cbPG.SelectedValue; cmdIns.Parameters.Add("@Address", SqlDbType.NVarChar, 120).Value = this.txtAddress.Text.Trim(); cmdIns.Parameters.Add("@PostalCode", SqlDbType.NVarChar, 20).Value = this.txtPostal.Text.Trim(); cmdIns.Parameters.Add("@Tel", SqlDbType.NVarChar, 30).Value = this.txtTele.Text.Trim(); cmdIns.Parameters.Add("@Fax", SqlDbType.NVarChar, 20).Value = this.txtFax.Text.Trim(); cmdIns.Parameters.Add("@OrderCurr", SqlDbType.NVarChar, 3).Value = this.cbCurrencyCode.SelectedValue; cmdIns.Parameters.Add("@Terms", SqlDbType.NVarChar, 20).Value = this.txtTerm.Text.Trim(); cmdIns.Parameters.Add("@UC", SqlDbType.NVarChar, 10).Value = NP_Cls.strUsr; cmdIns.Parameters.Add("@St", SqlDbType.NVarChar, 1).Value = "1"; cmdIns.Parameters.Add("@ContactP", SqlDbType.NVarChar, 50).Value = this.txtContactNo.Text.Trim(); cmdIns.Parameters.Add("@Mobile", SqlDbType.NVarChar, 60).Value = this.txtMobileNo.Text.Trim(); cmdIns.Parameters.Add("@Email", SqlDbType.NVarChar, 100).Value = this.txtEmail.Text.Trim(); cmdIns.Parameters.Add("@Remark", SqlDbType.NVarChar, 200).Value = this.txtRemark.Text.Trim(); cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.ExecuteNonQuery(); Clear(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Add Data Completed !!"); this.txtCode.Focus(); } catch (Exception ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); } finally { if (oConn.State == ConnectionState.Open) { oConn.Close(); } } } else { return; } }
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; } }
private void btnAdd_Click(object sender, EventArgs e) { try { if (NP.ReqField(this.txtCode, "Please enter Code: !!") == false) { return; } if (NP.ReqField(this.txtName, "Please enter Unit of Measure: !!") == false) { return; } try { byte bRe = 0; if (ChkDup(ref bRe)) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Code Duplicated !!"); this.txtCode.Select(); this.txtCode.SelectAll(); return; } else { if (bRe == 1) { Clear(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Update Data Completed !!"); this.txtCode.Focus(); return; } } } catch (Exception ex) { NP.MSGB("Erro Dup : " + ex.Message); 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(); try { SqlCommand cmdIns = new SqlCommand(); NP_Cls.SqlInsert = "INSERT INTO m_Unit (UnitCode, UnitName, Remark, UserCreate, DateCreate, FileStatus) VALUES (@Code,@Name,@Remark,@UC,getdate(),@St)"; cmdIns.Parameters.Add("@Code", SqlDbType.NVarChar, 10).Value = this.txtCode.Text.Trim(); cmdIns.Parameters.Add("@Name", SqlDbType.NVarChar, 60).Value = this.txtName.Text.Trim(); cmdIns.Parameters.Add("@Remark", SqlDbType.NVarChar, 255).Value = this.txtRemark.Text.Trim(); cmdIns.Parameters.Add("@UC", SqlDbType.NVarChar, 10).Value = NP_Cls.strUsr; cmdIns.Parameters.Add("@St", SqlDbType.NVarChar, 1).Value = "1"; cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.ExecuteNonQuery(); Clear(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Add Data Completed !!"); this.txtCode.Focus(); } catch (Exception ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return; } finally { if (oConn.State == ConnectionState.Open) { oConn.Close(); } } } else { return; } } catch (Exception ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return; } }
private void btnAdd_Click(object sender, EventArgs e) { try { if (NP.ReqField(this.txtEmpCode, "Please enter EmployeeCode: !!") == false) { return; } if (NP.ReqField(this.txtFirstName, "Please enter FirstName: !!") == false) { return; } if (NP.ReqField(this.txtLastName, "Please enter LastName: !!") == false) { return; } if (NP.ReqField(this.cbDepartment, "Please enter Department: !!") == false) { return; } if (NP.ReqField(this.cbLevel, "Please enter Level: !!") == false) { return; } if (NP.ReqField(this.txtUserName, "Please enter UserName: !!") == false) { return; } if (NP.ReqField(this.txtPass, "Please enter Password: !!") == false) { return; } if (NP.ReqField(this.txtConf, "Please enter Confirm: !!") == false) { return; } if (this.txtPass.Text.Trim() != this.txtConf.Text.Trim()) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Miss match password !!"); return; } if (ChkDup()) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Employee Code Or UserName Duplicated !!"); this.txtEmpCode.Select(); this.txtEmpCode.SelectAll(); return; } if (NP.MSGB("Do you want to Add User Data ?") == DialogResult.Yes) { oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB)); if (oConn.State == ConnectionState.Open) { oConn.Close(); } oConn.Open(); try { SqlCommand cmdIns = new SqlCommand(); NP_Cls.SqlInsert = "INSERT INTO s_User " + "(EmployeeCode, EmployeeFirstName, EmployeeLastName, DepartmentCode, AuthLevel, UserName, Password, UserCreate, DateCreate, FileStatus) " + "VALUES (@EmployeeCode,@EmployeeFirstName,@EmployeeLastName,@DepartmentCode,@AuthLevel,@UserName,@Password,@UC, GETDATE(),@St)"; cmdIns.Parameters.Add("@EmployeeCode", SqlDbType.NVarChar, 10).Value = this.txtEmpCode.Text.Trim(); cmdIns.Parameters.Add("@EmployeeFirstName", SqlDbType.NVarChar, 20).Value = this.txtFirstName.Text.Trim(); cmdIns.Parameters.Add("@EmployeeLastName", SqlDbType.NVarChar, 20).Value = this.txtLastName.Text.Trim(); cmdIns.Parameters.Add("@DepartmentCode", SqlDbType.NVarChar, 3).Value = this.cbDepartment.SelectedValue; cmdIns.Parameters.Add("@AuthLevel", SqlDbType.NVarChar, 1).Value = this.cbLevel.Text;; cmdIns.Parameters.Add("@UserName", SqlDbType.NVarChar, 10).Value = this.txtUserName.Text.Trim(); cmdIns.Parameters.Add("@Password", SqlDbType.NVarChar, 10).Value = this.txtPass.Text.Trim(); cmdIns.Parameters.Add("@UC", SqlDbType.NVarChar, 10).Value = NP_Cls.strUsr; cmdIns.Parameters.Add("@St", SqlDbType.NVarChar, 1).Value = "1"; cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.ExecuteNonQuery(); Clear(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Add Data Completed !!"); this.txtEmpCode.Focus(); } catch (Exception ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return; } finally { if (oConn.State == ConnectionState.Open) { oConn.Close(); } } } else { return; } } catch (Exception ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return; } }
private void btnAdd_Click(object sender, EventArgs e) { if (NP.ReqField(this.txtCode, "Please enter Code: !!") == false) { return; } if (NP.ReqField(this.txtName, "Please enter Name: !!") == false) { return; } if (NP.ReqField(this.cbUnit, "Please choose Unit: !!") == false) { return; } if (NP.ReqField(this.cbPlant, "Please choose Plant: !!") == false) { return; } if (NP.ReqField(this.cbLoc, "Please choose Location: !!") == false) { return; } if (this.cbMT.SelectedIndex == -1) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please choose Material Type: !!"); this.cbMT.Select(); return; } if (this.txtProcureType.SelectedIndex == -1) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Please choose Procurement Type: !!"); this.txtProcureType.Select(); return; } try { byte bRe = 0; if (ChkDup(ref bRe)) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Code Duplicated !!"); this.txtCode.Select(); this.txtCode.SelectAll(); return; } else { if (bRe == 1) { Clear(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Update Data Completed !!"); this.txtCode.Focus(); return; } } } catch (Exception ex) { NP.MSGB("Erro Dup : " + ex.Message); return; } if (NP.MSGB("Do you want to Add Data ?") == DialogResult.Yes) { oConn = new SqlConnection(NP.ReadFileDB(Application.StartupPath + @"\DB\DB.ini")); if (oConn.State == ConnectionState.Open) { oConn.Close(); } oConn.Open(); try { SqlCommand cmdIns = new SqlCommand(); NP_Cls.SqlInsert = "INSERT INTO m_Material " + "(MaterialCode, MaterialName, ChemicalName, MaterialTypeName, MaterialGroupCode, UnitCode, PlantCode, LocCode, CustomerProduct, ProcurementType, GRProcessingTime, " + "DeliveryTime, InHouseProduction, ShelfLife, MovAvgPrice, StandardCost, UserCreate, DateCreate, FileStatus) " + "VALUES (@MaterialCode,@MaterialName,@ChemicalName,@MaterialTypeName,@MaterialGroupCode,@UnitCode,@PlantCode,@LocCode,@CustomerProduct,@ProcurementType," + "@GRProcessingTime,@DeliveryTime,@InHouseProduction,@ShelfLife,@MovAvgPrice,@StandardCost,@UC, GETDATE(),@St)"; cmdIns.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15).Value = this.txtCode.Text.Trim(); cmdIns.Parameters.Add("@MaterialName", SqlDbType.NVarChar, 60).Value = this.txtName.Text.Trim(); cmdIns.Parameters.Add("@ChemicalName", SqlDbType.NVarChar, 60).Value = this.txtChemicalName.Text.Trim(); cmdIns.Parameters.Add("@MaterialTypeName", SqlDbType.NVarChar, 20).Value = this.cbMT.Text.Trim(); cmdIns.Parameters.Add("@MaterialGroupCode", SqlDbType.NVarChar, 3).Value = this.cbMaterialGroup.SelectedValue; cmdIns.Parameters.Add("@UnitCode", SqlDbType.NVarChar, 3).Value = this.cbUnit.SelectedValue; cmdIns.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4).Value = this.cbPlant.SelectedValue; cmdIns.Parameters.Add("@LocCode", SqlDbType.NVarChar, 2).Value = this.cbLoc.SelectedValue; cmdIns.Parameters.Add("@CustomerProduct", SqlDbType.NVarChar, 15).Value = this.txtCustProduct.Text.Trim(); cmdIns.Parameters.Add("@ProcurementType", SqlDbType.NVarChar, 1).Value = this.txtProcureType.Text.Trim(); cmdIns.Parameters.Add("@GRProcessingTime", SqlDbType.Decimal).Value = Convert.ToDecimal(string.IsNullOrEmpty(this.txtGR.Text.Trim()) ? "0" : this.txtGR.Text.Trim()); cmdIns.Parameters.Add("@DeliveryTime", SqlDbType.Decimal).Value = Convert.ToDecimal(string.IsNullOrEmpty(this.txtDelivery.Text.Trim()) ? "0" : this.txtDelivery.Text.Trim()); cmdIns.Parameters.Add("@InHouseProduction", SqlDbType.Decimal).Value = Convert.ToDecimal(string.IsNullOrEmpty(this.txtInHouse.Text.Trim()) ? "0" : this.txtInHouse.Text.Trim()); cmdIns.Parameters.Add("@ShelfLife", SqlDbType.Decimal).Value = Convert.ToDecimal(string.IsNullOrEmpty(this.txtShelfLife.Text.Trim()) ? "0" : this.txtShelfLife.Text.Trim()); cmdIns.Parameters.Add("@MovAvgPrice", SqlDbType.Decimal).Value = Convert.ToDecimal(string.IsNullOrEmpty(this.txtMovAvg.Text.Trim()) ? "0" : this.txtMovAvg.Text.Trim()); cmdIns.Parameters.Add("@StandardCost", SqlDbType.Decimal).Value = Convert.ToDecimal(string.IsNullOrEmpty(this.txtStandardCost.Text.Trim()) ? "0" : this.txtStandardCost.Text.Trim()); cmdIns.Parameters.Add("@UC", SqlDbType.NVarChar, 10).Value = NP_Cls.strUsr; cmdIns.Parameters.Add("@St", SqlDbType.NVarChar, 1).Value = "1"; cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.ExecuteNonQuery(); Clear(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Add Data Completed !!"); this.txtCode.Focus(); } catch (Exception ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Edit : " + ex.Message); return; } finally { if (oConn.State == ConnectionState.Open) { oConn.Close(); } } } else { return; } }
private void btnAdd_Click(object sender, EventArgs e) { try { if (NP.ReqField(this.txtScaleQty, "Please enter Scale Qty: !!") == false) { return; } if (NP.ReqField(this.txtRate, "Please enter Unit of Rate: !!") == false) { return; } if (ChkDup()) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Code Duplicated !!"); this.txtScaleQty.Select(); this.txtScaleQty.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(); try { SqlCommand cmdIns = new SqlCommand(); NP_Cls.SqlInsert = "INSERT INTO t_VendorInfoRecordPeriodsDetail " + "(ValidPeriodCode, ScaleQty, Rate, UserCreate, DateCreate, FileStatus) " + "VALUES (@ValidPeriodCode,@ScaleQty,@Rate,@UC, GETDATE(), @St)"; cmdIns.Parameters.Add("@ValidPeriodCode", SqlDbType.Int).Value = NP_Cls.strValidCode; cmdIns.Parameters.Add("@ValidPeriodDetailCode", SqlDbType.Int).Value = NP_Cls.strValidCode; cmdIns.Parameters.Add("@ScaleQty", SqlDbType.Decimal).Value = Convert.ToDecimal(this.txtScaleQty.Text.Trim() == string.Empty ? "0" : this.txtScaleQty.Text.Trim()); cmdIns.Parameters.Add("@Rate", SqlDbType.Decimal).Value = Convert.ToDecimal(this.txtRate.Text.Trim() == string.Empty ? "0" : this.txtRate.Text.Trim()); cmdIns.Parameters.Add("@UC", SqlDbType.NVarChar, 10).Value = NP_Cls.strUsr; cmdIns.Parameters.Add("@St", SqlDbType.NVarChar, 1).Value = "1"; cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.ExecuteNonQuery(); Clear(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Add Data Completed !!"); this.txtScaleQty.Select(); } catch (Exception ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return; } finally { if (oConn.State == ConnectionState.Open) { oConn.Close(); } } } else { return; } } catch (Exception ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return; } }
private void btnAdd_Click(object sender, EventArgs e) { //if (NP.ReqField(this.cbMaterial, "Please enter Material: !!") == false) { 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.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 (ChkDup()) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Material & Plant Duplicated !!"); this.cbMaterial.Select(); return; } if (NP.MSGB("Do you want to Add BOM Data ?") == DialogResult.Yes) { oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB)); if (oConn.State == ConnectionState.Open) { oConn.Close(); } oConn.Open(); try { SqlCommand cmdIns = new SqlCommand(); BuildVersion(); NP_Cls.SqlInsert = "INSERT INTO t_BOM " + "(MaterialCode, PlantCode, BOMType, UnitCode, Quantity, BOMVersion, UserCreate, DateCreate, FileStatus, Approve, Remark, FormulaNo) " + "VALUES (@MaterialCode,@PlantCode,@BOMType,@UnitCode,@Quantity,@BOMVersion,@UC, GETDATE(),@St,@Appr, @Remark, @FormulaNo)"; //cmdIns.Parameters.Add("@BOMCode", SqlDbType.Int).Value = NP_Cls.strBOMCode; cmdIns.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15).Value = this.cbMaterial.SelectedValue; cmdIns.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4).Value = this.cbPlant.SelectedValue; cmdIns.Parameters.Add("@BOMType", SqlDbType.NVarChar, 1).Value = this.cbBOMType.SelectedValue; cmdIns.Parameters.Add("@UnitCode", SqlDbType.NVarChar, 3).Value = this.cbUnit.SelectedValue; cmdIns.Parameters.Add("@Quantity", SqlDbType.Decimal).Value = Convert.ToDouble(this.txtQty.Text.Trim()); cmdIns.Parameters.Add("@BOMVersion", SqlDbType.Int).Value = this.strVersion; cmdIns.Parameters.Add("@UC", SqlDbType.NVarChar, 10).Value = NP_Cls.strUsr; cmdIns.Parameters.Add("@St", SqlDbType.NVarChar, 1).Value = "1"; cmdIns.Parameters.Add("@Appr", SqlDbType.Bit).Value = 0; cmdIns.Parameters.Add("@Remark", SqlDbType.NVarChar, 200).Value = this.txtRemark.Text.Trim(); cmdIns.Parameters.Add("@FormulaNo", SqlDbType.NVarChar, 200).Value = this.txtFor.Text.Trim(); cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.ExecuteNonQuery(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Add BOM Data Completed !!\n\n Please Add Component for this BOM .."); this.cbUnit.Enabled = true; 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(false)); NP_Cls.hBOM.Add("Material", this.cbMaterial.SelectedValue.ToString()); WMS.BOM.frmBOMNewDetail frm = new frmBOMNewDetail(); frm.lblSCode.Text = this.cbMaterial.SelectedValue.ToString(); frm.lblSName.Text = this.cbMaterial.Text.ToString().Split(':')[1].Trim(); frm.ShowDialog(); Clear(); DGV(); this.cbMaterial.Select(); } catch (Exception ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Add : " + ex.Message); return; } finally { if (oConn.State == ConnectionState.Open) { oConn.Close(); } } } else { return; } }
private void btnAdd_Click(object sender, EventArgs e) { if (NP.ReqField(this.cbMaterial, "Please enter Material: !!") == false) { 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 (NP.ReqField(this.cbComponent, "Please enter Component: !!") == false) { return; } if (NP.ReqField(this.txtQtyComp, "Please enter Qty of Component: !!") == false) { return; } if (ChkDup()) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Code Duplicated !!"); this.cbComponent.Select(); return; } if (this.dgvView.RowCount != 0) { Double bChk = 0; for (byte i = 0; i < this.dgvView.RowCount; i++) { bChk += Convert.ToDouble(this.dgvView["clnQty", i].Value); } if ((Convert.ToDouble(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 { if (this.cbBOMType.SelectedValue.ToString().ToUpper() == "M") { if (Convert.ToDouble(this.txtQtyComp.Text.Trim()) > 100) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Qty of Component is over 100 !!"); this.txtQtyComp.Select(); this.txtQtyComp.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_BOM WHERE (MaterialCode = @MaterialCode) AND (PlantCode = @PlantCode) AND (BOMVersion = @Ver)"; cmdIns.Parameters.Add("@MaterialCode", SqlDbType.NVarChar, 15).Value = this.cbMaterial.SelectedValue; cmdIns.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 4).Value = this.cbPlant.SelectedValue; cmdIns.Parameters.Add("@Ver", SqlDbType.NVarChar, 20).Value = this.txtVersion.Text.Trim(); 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) { GenVCode(); NP_Cls.SqlInsert = "INSERT INTO t_BOM " + "(BOMCode, MaterialCode, PlantCode, BOMType, UnitCode, Quantity, BOMVersion, UserCreate, DateCreate, FileStatus, Approve) " + "VALUES (@BOMCode,@MaterialCode,@PlantCode,@BOMType,@UnitCode,@Quantity,@BOMVersion,@UC, GETDATE(),@St,@Appr)"; cmdIns.Parameters.Add("@BOMCode", SqlDbType.Int).Value = NP_Cls.strBOMCode; cmdIns.Parameters.Add("@BOMType", SqlDbType.NVarChar, 1).Value = this.cbBOMType.SelectedValue; cmdIns.Parameters.Add("@UnitCode", SqlDbType.NVarChar, 3).Value = this.cbUnit.SelectedValue; cmdIns.Parameters.Add("@Quantity", SqlDbType.Int).Value = Convert.ToInt32(this.txtQty.Text.Trim()); cmdIns.Parameters.Add("@BOMVersion", SqlDbType.Int).Value = this.txtVersion.Text.Trim(); cmdIns.Parameters.Add("@UC", SqlDbType.NVarChar, 10).Value = NP_Cls.strUsr; cmdIns.Parameters.Add("@St", SqlDbType.NVarChar, 1).Value = "1"; cmdIns.Parameters.Add("@Appr", SqlDbType.Bit).Value = 0; cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr; cmdIns.ExecuteNonQuery(); NP_Cls.SqlInsert = "INSERT INTO t_BOMDetail " + "(BOMCode, Category, MaterialCode, Quantity) " + "VALUES (@BOMCode,@Category,@CompCode,@QtyComp)"; cmdIns.Parameters.Add("@CompCode", 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("@QtyComp", SqlDbType.Decimal).Value = Convert.ToDouble(this.txtQtyComp.Text.Trim()); cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr; cmdIns.ExecuteNonQuery(); Tr.Commit(); this.cbComponent.SelectedIndex = 0; this.txtQtyComp.Text = string.Empty; DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Add Data Completed !!"); this.cbMaterial.Select(); } else { NP_Cls.strBOMCode = this.dgvView["clnBOMCode", 0].Value.ToString(); NP_Cls.SqlInsert = "INSERT INTO t_BOMDetail " + "(BOMCode, Category, MaterialCode, Quantity) " + "VALUES (@BOMCode,@Category,@CompCode,@QtyComp)"; cmdIns.Parameters.Add("@BOMCode", SqlDbType.Int).Value = NP_Cls.strBOMCode; cmdIns.Parameters.Add("@CompCode", 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("@QtyComp", SqlDbType.Decimal).Value = Convert.ToDouble(this.txtQtyComp.Text.Trim()); cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.Transaction = Tr; cmdIns.ExecuteNonQuery(); Tr.Commit(); this.cbComponent.SelectedIndex = 0; this.txtQtyComp.Text = string.Empty; DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Add Data Completed !!"); this.cbMaterial.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; } }
private void btnAdd_Click(object sender, EventArgs e) { if (NP.ReqField(this.txtCode, "Please enter Code: !!") == false) { return; } if (NP.ReqField(this.txtName, "Please enter Name: !!") == false) { return; } try { byte bRe = 0; if (ChkDup(ref bRe)) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Code Duplicated !!"); this.txtCode.Select(); this.txtCode.SelectAll(); return; } else { if (bRe == 1) { Clear(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Update Data Completed !!"); this.txtCode.Focus(); return; } } } catch (Exception ex) { NP.MSGB("Erro Dup : " + ex.Message); return; } if (NP.MSGB("Do you want to Add Data ?") == DialogResult.Yes) { oConn = new SqlConnection(NP.ReadFileDB(Application.StartupPath + @"\DB\DB.ini")); if (oConn.State == ConnectionState.Open) { oConn.Close(); } oConn.Open(); try { SqlCommand cmdIns = new SqlCommand(); NP_Cls.SqlInsert = "INSERT INTO m_WorkCenter " + " (WorkCenterCode, WorkCenterName, PlantCode, WorkCenterMachine, WorkCenterSetup, WorkCenterLabor, WorkCenterOT, UserCreate, DateCreate, FileStatus) " + "VALUES (@WorkCenterCode,@WorkCenterName,@PlantCode,@WorkCenterMachine,@WorkCenterSetup,@WorkCenterLabor,@WorkCenterOT,@UC, GETDATE(),@St)"; cmdIns.Parameters.Add("@WorkCenterCode", SqlDbType.NVarChar, 10).Value = this.txtCode.Text.Trim(); cmdIns.Parameters.Add("@WorkCenterName", SqlDbType.NVarChar, 40).Value = this.txtName.Text.Trim(); cmdIns.Parameters.Add("@PlantCode", SqlDbType.NVarChar, 10).Value = this.cbPlant.SelectedValue; cmdIns.Parameters.Add("@WorkCenterMachine", SqlDbType.Int).Value = Convert.ToInt32(string.IsNullOrEmpty(this.txtMachine.Text.Trim()) ? "0" : this.txtMachine.Text.Trim()); cmdIns.Parameters.Add("@WorkCenterSetup", SqlDbType.Int).Value = Convert.ToInt32(string.IsNullOrEmpty(this.txtSetup.Text.Trim()) ? "0" : this.txtSetup.Text.Trim()); cmdIns.Parameters.Add("@WorkCenterLabor", SqlDbType.Int).Value = Convert.ToInt32(string.IsNullOrEmpty(this.txtLabor.Text.Trim()) ? "0" : this.txtLabor.Text.Trim()); cmdIns.Parameters.Add("@WorkCenterOT", SqlDbType.Int).Value = Convert.ToInt32(string.IsNullOrEmpty(this.txtOT.Text.Trim()) ? "0" : this.txtOT.Text.Trim()); cmdIns.Parameters.Add("@UC", SqlDbType.NVarChar, 10).Value = NP_Cls.strUsr; cmdIns.Parameters.Add("@St", SqlDbType.NVarChar, 1).Value = "1"; cmdIns.Connection = oConn; cmdIns.CommandText = NP_Cls.SqlInsert; cmdIns.ExecuteNonQuery(); Clear(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Add Data Completed !!"); this.txtCode.Focus(); } catch (Exception ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Edit : " + ex.Message); return; } finally { if (oConn.State == ConnectionState.Open) { oConn.Close(); } } } else { return; } }
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; } }