private void RepairEditB_Click(object sender, EventArgs e)
        {
            Button bt = (Button)sender;


            switch (bt.Text)
            {
            case "Edit":
                EnableRepair();
                break;

            case "Save":
                if (_partDescription != partCB.Text ||
                    _purchasedDate != purchaseDateDTP.Value ||
                    _supplierName != supplierCB.Text ||
                    _invoiceNumber != invoiceNumberTB.Text ||
                    _amount != int.Parse(amountTB.Text))
                {
                    _repairdetail = new RepairDetail(_repairdetail.RepairID, _repairdetail.PartID, purchaseDateDTP.Value, int.Parse(amountTB.Text), invoiceNumberTB.Text, _supplier.RetrieveSupplierID(supplierCB.Text));
                }
                _repairdetail.UpdateRepairDetailInfo(_repairdetail);

                LoadDetails();
                DisableRepair();
                break;
            }
        }
Exemple #2
0
        private void AddItem()
        {
            ListViewItem partLVI = new ListViewItem();

            partSupplierID    = _supplier.RetrieveSupplierID(partSupplierCB.Text);
            partID            = _part.RetrievePartID(partCB.Text);
            purchasedDate     = partDateDTP.Value;
            partInvoiceNumber = partInvoiceNumberTB.Text;
            partDescription   = partCB.Text;
            partAmount        = double.Parse(partAmountTB.Text);

            _repairDetail = new RepairDetail(repairID, partID, purchasedDate, partAmount, partInvoiceNumber, partSupplierID);

            _repairDetails.Add(_repairDetail);

            partLVI.SubItems.Add(partSupplierCB.Text);
            partLVI.SubItems.Add(partDateDTP.Value.ToShortDateString());
            partLVI.SubItems.Add(partInvoiceNumberTB.Text);
            partLVI.SubItems.Add(partCB.Text);
            partLVI.SubItems.Add(partAmountTB.Text);
            partLVI.SubItems.Add(statusCB.Text);
            partListLV.Items.Add(partLVI);

            this.Clear();
        }
        public RepairDetail RetrieveDetailInfo(int repairID)
        {
            RepairDetail temp = new RepairDetail();

            try
            {
                _dbOp.DBConnect();
                MySqlCommand cmd = _dbOp._dbConn.CreateCommand();

                cmd.CommandText = @"SELECT * FROM RepairDetail " + "WHERE RepairID = @RepairID";
                cmd.Parameters.AddWithValue("@RepairID", repairID);

                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    RepairID      = (int)reader.GetValue(0);
                    PartID        = (int)reader.GetValue(1);
                    PurchasedDate = (DateTime)reader.GetValue(2);
                    Amount        = (double)reader.GetValue(3);
                    InvoiceNumber = (string)reader.GetValue(4);
                    SupplierID    = (int)reader.GetValue(5);

                    temp = new RepairDetail(RepairID, PartID, PurchasedDate, Amount, InvoiceNumber, SupplierID);
                }
                reader.Close();
                _dbOp.DBClose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return(temp);
        }
        public void InsertRepairDetail(RepairDetail repairDetail)
        {
            try
            {
                _dbOp.DBConnect();
                MySqlCommand cmd = _dbOp._dbConn.CreateCommand();

                cmd.CommandText = @"INSERT INTO RepairDetail(RepairID,PartID,PurchasedDate,Amount,InvoiceNumber,SupplierID)
                            VALUES(@RepairID,@PartID,@PurchasedDate,@Amount,@InvoiceNumber,@SupplierID)";

                cmd.Parameters.AddWithValue("@RepairID", repairDetail.RepairID);
                cmd.Parameters.AddWithValue("@PartID", repairDetail.PartID);
                cmd.Parameters.AddWithValue("@PurchasedDate", repairDetail.PurchasedDate);
                cmd.Parameters.AddWithValue("@Amount", repairDetail.Amount);
                cmd.Parameters.AddWithValue("@InvoiceNumber", repairDetail.InvoiceNumber);
                cmd.Parameters.AddWithValue("@SupplierID", repairDetail.SupplierID);

                cmd.ExecuteNonQuery();
                _dbOp.DBClose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        public void UpdateRepairDetailInfo(RepairDetail repairDetail)
        {
            try
            {
                _dbOp.DBConnect();

                MySqlCommand cmd = _dbOp._dbConn.CreateCommand();

                cmd.CommandText = @"UPDATE RepairDetail SET RepairID = @RepairID, PartID = @PartID,Amount = @Amount,InvoiceNumber = @InvoiceNumber,SupplierID = @SupplierID " + "WHERE RepairID = @RepairID AND PartID = @PartID";

                cmd.Parameters.AddWithValue("@RepairID", repairDetail.RepairID);
                cmd.Parameters.AddWithValue("@PartID", repairDetail.PartID);
                cmd.Parameters.AddWithValue("@Amount", repairDetail.Amount);
                cmd.Parameters.AddWithValue("@InvoiceNumber", repairDetail.InvoiceNumber);
                cmd.Parameters.AddWithValue("@SupplierID", repairDetail.SupplierID);

                cmd.ExecuteNonQuery();

                MessageBox.Show("Updated Repair Detail has been saved!");

                _dbOp.DBClose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemple #6
0
        private void AddB_Click(object sender, EventArgs e)
        {
            DisableRepair();
            _repairDetail = new RepairDetail(repairID, partID, purchasedDate, partAmount, partInvoiceNumber, partSupplierID);
            AddItem();

            partCB.Focus();
            if (addB.Text == "Update")
            {
                addB.Text = "Add";
            }
        }
        public List <RepairDetail> RetrieveStatementRepair(int partID, string invoiceNumber)
        {
            List <RepairDetail> repairDetailList = new List <RepairDetail>();

            try
            {
                _dbOp.DBConnect();

                MySqlCommand cmd = _dbOp._dbConn.CreateCommand();

                cmd.CommandText = "SELECT * FROM RepairDetail " + "WHERE PartID = @PartID AND InvoiceNumber = @InvoiceNumber";
                cmd.Parameters.AddWithValue("@PartID", partID);
                cmd.Parameters.AddWithValue("@InvoiceNumber", invoiceNumber);

                MySqlDataReader reader = cmd.ExecuteReader();

                RepairDetail temp = new RepairDetail();

                while (reader.Read())
                {
                    RepairID      = (int)reader.GetValue(0);
                    PartID        = (int)reader.GetValue(1);
                    PurchasedDate = (DateTime)reader.GetValue(2);
                    Amount        = (double)reader.GetValue(3);
                    InvoiceNumber = (string)reader.GetValue(4);
                    SupplierID    = (int)reader.GetValue(5);

                    temp = new RepairDetail(RepairID, PartID, PurchasedDate, Amount, InvoiceNumber, SupplierID);

                    repairDetailList.Add(temp);
                }
                reader.Close();

                _dbOp.DBClose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return(repairDetailList);
        }
Exemple #8
0
        private void PartListLV_SelectedIndexChanged(object sender, EventArgs e)
        {
            addB.Text = "Update";
            partSupplierCB.Enabled      = true;
            partDateDTP.Enabled         = true;
            partInvoiceNumberTB.Enabled = true;
            if (partListLV.SelectedItems.Count > 0)
            {
                ListViewItem selectedPart = partListLV.SelectedItems[0];
                string       partItemNo   = selectedPart.SubItems[0].Text;

                partCB.Text         = selectedPart.SubItems[4].Text;
                partID              = _part.RetrievePartID(partCB.Text);
                purchasedDate       = partDateDTP.Value = DateTime.Parse(selectedPart.SubItems[2].Text);
                partSupplierCB.Text = selectedPart.SubItems[1].Text;
                partSupplierID      = _supplier.RetrieveSupplierID(partSupplierCB.Text);
                partInvoiceNumber   = partInvoiceNumberTB.Text = selectedPart.SubItems[3].Text;
                partAmountTB.Text   = selectedPart.SubItems[5].Text;
                partAmount          = double.Parse(partAmountTB.Text);

                _repairDetail = new RepairDetail(repairID, partID, purchasedDate, partAmount, partInvoiceNumber, partSupplierID);
                partListLV.SelectedItems[0].Remove();
            }
        }