private void pairCustomer()
        {
            itemCustBLL uItemCust   = new itemCustBLL();
            itemCustDAL dalItemCust = new itemCustDAL();

            string cust = cmbCust.Text;

            if (cmbCat.Text.Equals("Part") && !string.IsNullOrEmpty(cust))
            {
                if (!IfExists(txtItemCode.Text, cmbCust.Text))
                {
                    uItemCust.cust_id                = Convert.ToInt32(tool.getCustID(cmbCust.Text));
                    uItemCust.item_code              = txtItemCode.Text;
                    uItemCust.item_cust_added_date   = DateTime.Now;
                    uItemCust.item_cust_added_by     = MainDashboard.USER_ID;
                    uItemCust.forecast_one           = 0;
                    uItemCust.forecast_two           = 0;
                    uItemCust.forecast_three         = 0;
                    uItemCust.forecast_current_month = DateTime.Now.ToString("MMMM");

                    bool success = dalItemCust.Insert(uItemCust);

                    if (!success)
                    {
                        //Failed to insert data
                        MessageBox.Show("Failed to add new item_cust record");
                    }
                }
                else
                {
                    MessageBox.Show("Data already exist.");
                }
            }
        }
        private void pairCustomer(string cust, string itemCode)
        {
            itemCustBLL uItemCust   = new itemCustBLL();
            itemCustDAL dalItemCust = new itemCustDAL();

            if (!tool.IfExists(itemCode, cust))
            {
                uItemCust.cust_id                = Convert.ToInt32(tool.getCustID(cust));
                uItemCust.item_code              = itemCode;
                uItemCust.item_cust_added_date   = DateTime.Now;
                uItemCust.item_cust_added_by     = MainDashboard.USER_ID;
                uItemCust.forecast_one           = 0;
                uItemCust.forecast_two           = 0;
                uItemCust.forecast_three         = 0;
                uItemCust.forecast_current_month = DateTime.Now.ToString("MMMM");

                bool success = dalItemCust.Insert(uItemCust);

                if (!success)
                {
                    //Failed to insert data
                    MessageBox.Show("Failed to add new item_cust record");
                }
            }
            else
            {
                MessageBox.Show("Data already exist.");
            }
        }
Exemplo n.º 3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (Validation())
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure want to insert data to database?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialogResult == DialogResult.Yes)
                {
                    if (!IfExists(cmbItemCode.Text, cmbCust.Text))
                    {
                        uItemCust.cust_id                = Convert.ToInt32(getCustID(cmbCust.Text));
                        uItemCust.item_code              = cmbItemCode.Text;
                        uItemCust.item_cust_added_date   = DateTime.Now;
                        uItemCust.item_cust_added_by     = 0;
                        uItemCust.forecast_one           = 0;
                        uItemCust.forecast_two           = 0;
                        uItemCust.forecast_three         = 0;
                        uItemCust.forecast_current_month = DateTime.Now.ToString("MMMM");


                        bool success = dalItemCust.Insert(uItemCust);

                        if (success == true)
                        {
                            refreshList();
                        }
                        else
                        {
                            //Failed to insert data
                            MessageBox.Show("Failed to add new item_cust record");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Data already exist.");
                    }
                }
            }
        }
        private void dgvForecast_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                var datagridview = sender as DataGridView;

                int      rowIndex    = e.RowIndex;
                DateTime updatedTime = DateTime.Now;


                uItemCust.item_code = dgvForecast.Rows[rowIndex].Cells["item_code"].Value.ToString();
                uItemCust.cust_id   = tool.getCustID(cmbCust.Text);

                uItemCust.forecast_one   = Convert.ToSingle(dgvForecast.Rows[rowIndex].Cells["forecast_one"].Value.ToString());
                uItemCust.forecast_two   = Convert.ToSingle(dgvForecast.Rows[rowIndex].Cells["forecast_two"].Value.ToString());
                uItemCust.forecast_three = Convert.ToSingle(dgvForecast.Rows[rowIndex].Cells["forecast_three"].Value.ToString());
                uItemCust.forecast_four  = Convert.ToSingle(dgvForecast.Rows[rowIndex].Cells["forecast_four"].Value);

                uItemCust.forecast_updated_date  = updatedTime;
                uItemCust.forecast_current_month = cmbForecast1.Text;
                uItemCust.forecast_updated_by    = MainDashboard.USER_ID;

                if (Convert.ToInt32(forecastNum) == 2)
                {
                    newForecast = uItemCust.forecast_one.ToString();
                }
                else if (Convert.ToInt32(forecastNum) == 3)
                {
                    newForecast = uItemCust.forecast_two.ToString();
                }
                else if (Convert.ToInt32(forecastNum) == 4)
                {
                    newForecast = uItemCust.forecast_three.ToString();
                }
                else
                {
                    newForecast = uItemCust.forecast_four.ToString();
                }

                if (oldForecast != newForecast)
                {
                    if (tool.IfExists(uItemCust.item_code, cmbCust.Text))
                    {
                        bool success = dalItemCust.Update(uItemCust);

                        if (!success)
                        {
                            MessageBox.Show("Failed to updated forecast");
                            tool.historyRecord(text.System, "Failed to updated forecast(frmForecast) " + uItemCust.item_code, DateTime.Now, MainDashboard.USER_ID);
                        }
                        else
                        {
                            dgvForecast.Rows[rowIndex].Cells["forecast_updtd_date"].Value = updatedTime;
                            dgvForecast.Rows[rowIndex].Cells["forecast_updtd_by"].Value   = dalUser.getUsername(MainDashboard.USER_ID);
                            tool.historyRecord(text.ForecastEdit, text.getForecastEditString(cmbCust.Text, forecastNum, uItemCust.item_code, oldForecast, newForecast), DateTime.Now, MainDashboard.USER_ID);
                        }
                    }
                    else
                    {
                        bool success = dalItemCust.Insert(uItemCust);
                        //If the data is successfully inserted then the value of success will be true else false
                        if (!success)
                        {
                            MessageBox.Show("Failed to add new forecast");
                            tool.historyRecord(text.System, "Failed to add new forecast(frmForecast) " + uItemCust.item_code, DateTime.Now, MainDashboard.USER_ID);
                        }
                        dgvForecast.Rows[rowIndex].Cells["forecast_updtd_date"].Value = updatedTime;
                        dgvForecast.Rows[rowIndex].Cells["forecast_updtd_by"].Value   = dalUser.getUsername(MainDashboard.USER_ID);
                    }
                }
            }
            catch (Exception ex)
            {
                tool.saveToTextAndMessageToUser(ex);
            }
        }