private void loadForecastList()
        {
            //get keyword from text box
            string keywords = cmbCust.Text;
            int    index    = 1;

            //check if the keywords has value or not
            if (!string.IsNullOrEmpty(keywords))
            {
                DataTable dt = dalItemCust.custSearch(keywords);

                dt.DefaultView.Sort = "item_name ASC";
                dt = dt.DefaultView.ToTable();

                if (dt.Rows.Count <= 0)
                {
                    MessageBox.Show("no data under this record.");
                }

                dgvForecast.Rows.Clear();
                foreach (DataRow item in dt.Rows)
                {
                    int n = dgvForecast.Rows.Add();
                    dgvForecast.Rows[n].Cells["NO"].Value                  = index;
                    dgvForecast.Rows[n].Cells["item_code"].Value           = item["item_code"].ToString();
                    dgvForecast.Rows[n].Cells["item_name"].Value           = item["item_name"].ToString();
                    dgvForecast.Rows[n].Cells["forecast_one"].Value        = item["forecast_one"] == DBNull.Value ? 0.ToString() : item["forecast_one"].ToString();
                    dgvForecast.Rows[n].Cells["forecast_two"].Value        = item["forecast_two"] == DBNull.Value ? 0.ToString() : item["forecast_two"].ToString();
                    dgvForecast.Rows[n].Cells["forecast_three"].Value      = item["forecast_three"] == DBNull.Value ? 0.ToString() : item["forecast_three"].ToString();
                    dgvForecast.Rows[n].Cells["forecast_four"].Value       = item["forecast_four"] == DBNull.Value? 0.ToString() : item["forecast_four"].ToString();
                    dgvForecast.Rows[n].Cells["forecast_updtd_date"].Value = item["forecast_updated_date"].ToString();
                    index++;

                    if (int.TryParse(item["forecast_updated_by"].ToString(), out int test))
                    {
                        if (Convert.ToInt32(item["forecast_updated_by"]) <= 0)
                        {
                            dgvForecast.Rows[n].Cells["forecast_updtd_by"].Value = "ADMIN";
                        }
                        else
                        {
                            dgvForecast.Rows[n].Cells["forecast_updtd_by"].Value = dalUser.getUsername(Convert.ToInt32(item["forecast_updated_by"]));
                        }
                    }

                    string currentMonth = item["forecast_current_month"]?.ToString();

                    resetCurrentMonth(item["item_code"].ToString(), n, currentMonth);
                }
            }
            else
            {
                dgvForecast.DataSource = null;
            }
            tool.listPaintGreyHeader(dgvForecast);
        }
        private void loadForecastList()
        {
            Cursor = Cursors.WaitCursor;

            btnSearch.Enabled = false;
            frmLoading.ShowLoadingScreen();

            cbEditMode.Checked     = false;
            dgvForecast.DataSource = null;
            string keywords = cmbCustomer.Text;

            CalTotalMonth();
            //MessageBox.Show(getYear("NOVEMBER 2019"));

            //check if the keywords has value or not
            if (!string.IsNullOrEmpty(keywords))
            {
                string itemNameKeyword = cmbPartName.Text;
                string itemCodeKeyword = cmbPartCode.Text;

                DataTable dt_Data = NewForecastTable();
                DataRow   dt_Row;
                DataTable dt = dalItemCust.custSearch(keywords);
                DataTable dt_ItemForecast = dalItemForecast.Select(tool.getCustID(keywords).ToString());
                int       index           = 1;

                dt.DefaultView.Sort = "item_name ASC";

                dt = dt.DefaultView.ToTable();

                foreach (DataRow row in dt.Rows)
                {
                    string itemName = row[dalItem.ItemName].ToString();
                    string itemCode = row[dalItem.ItemCode].ToString();

                    bool itemMatch = itemName.Contains(itemNameKeyword.ToUpper());

                    itemMatch = itemMatch || string.IsNullOrEmpty(itemNameKeyword);

                    itemMatch = itemMatch && (itemCodeKeyword.Equals(itemCode, StringComparison.InvariantCulture) || string.IsNullOrEmpty(itemCodeKeyword));

                    if (itemMatch)
                    {
                        dt_Row = dt_Data.NewRow();

                        dt_Row[headerIndex]    = index;
                        dt_Row[headerPartCode] = itemCode;
                        dt_Row[headerPartName] = itemName;

                        for (int i = 0; i < forecastMonthQty; i++)
                        {
                            //get month and year
                            //MessageBox.Show(getYear(dt_Data.Columns[3 + i].ColumnName));

                            string   headerText = dt_Data.Columns[3 + i].ColumnName;
                            int      year       = Convert.ToInt32(getYear(headerText));
                            int      month      = DateTime.Parse("1." + getMonthName(headerText) + " 2008").Month;
                            DateTime date       = DateTime.MaxValue;
                            //search data
                            DataRow data = tool.getItemForecastDataRow(dt_ItemForecast, itemCode, year, month);

                            if (data != null)
                            {
                                dt_Row[3 + i] = data[dalItemForecast.ForecastQty];

                                if (date == DateTime.MaxValue || date < Convert.ToDateTime(data[dalItemForecast.UpdatedDate]))
                                {
                                    date = Convert.ToDateTime(data[dalItemForecast.UpdatedDate]);
                                    dt_Row[headerUpdatedDate] = data[dalItemForecast.UpdatedDate];

                                    int updatedID = int.TryParse(data[dalItemForecast.UpdatedBy].ToString(), out updatedID) ? updatedID : 0;

                                    if (updatedID <= 0)
                                    {
                                        dt_Row[headerUpdatedBy] = "ADMIN";
                                    }
                                    else
                                    {
                                        dt_Row[headerUpdatedBy] = dalUser.getUsername(updatedID);
                                    }
                                    //dt_Row[headerUpdatedBy] = data[dalItemForecast.UpdatedBy];
                                }
                            }
                            else
                            {
                                dt_Row[3 + i] = 0;
                            }
                        }

                        dt_Data.Rows.Add(dt_Row);
                        index++;
                    }
                }


                if (dt_Data.Rows.Count > 0)
                {
                    dgvForecast.AutoSizeColumnsMode  = DataGridViewAutoSizeColumnsMode.None;
                    dgvForecast.ColumnHeadersVisible = false;
                    dgvForecast.DataSource           = dt_Data;
                    dgvForecastUIEdit(dgvForecast);
                    dgvForecast.ColumnHeadersVisible = true;
                    dgvForecast.AutoSizeColumnsMode  = DataGridViewAutoSizeColumnsMode.DisplayedCells;

                    //dgvForecast.AutoResizeColumns();

                    //dgvForecast.Columns[headerUpdatedBy].Width = 500;
                    dgvForecast.ClearSelection();
                }
            }

            frmLoading.CloseForm();

            btnSearch.Enabled = true;

            Cursor = Cursors.Arrow;
        }
Ejemplo n.º 3
0
        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            //get keyword from text box
            string keywords = txtSearch.Text;

            //check if the keywords has value or not
            if (!string.IsNullOrEmpty(keywords))
            {
                if (cmbSearch.Text.Equals("Customer"))
                {
                    DataTable dt = dalItemCust.custSearch(keywords);

                    dgvItemCust.Rows.Clear();
                    foreach (DataRow item in dt.Rows)
                    {
                        int n = dgvItemCust.Rows.Add();
                        dgvItemCust.Rows[n].Cells["cust_name"].Value            = item["cust_name"].ToString();
                        dgvItemCust.Rows[n].Cells["item_code"].Value            = item["item_code"].ToString();
                        dgvItemCust.Rows[n].Cells["item_name"].Value            = item["item_name"].ToString();
                        dgvItemCust.Rows[n].Cells["item_cust_added_date"].Value = item["item_cust_added_date"].ToString();
                        dgvItemCust.Rows[n].Cells["item_cust_added_by"].Value   = item["item_cust_added_by"].ToString();
                    }
                }
                else if (cmbSearch.Text.Equals("Item Name"))
                {
                    DataTable dt = dalItemCust.itemSearch(keywords);

                    dgvItemCust.Rows.Clear();
                    foreach (DataRow item in dt.Rows)
                    {
                        int n = dgvItemCust.Rows.Add();
                        dgvItemCust.Rows[n].Cells["cust_name"].Value            = item["cust_name"].ToString();
                        dgvItemCust.Rows[n].Cells["item_code"].Value            = item["item_code"].ToString();
                        dgvItemCust.Rows[n].Cells["item_name"].Value            = item["item_name"].ToString();
                        dgvItemCust.Rows[n].Cells["item_cust_added_date"].Value = item["item_cust_added_date"].ToString();
                        dgvItemCust.Rows[n].Cells["item_cust_added_by"].Value   = item["item_cust_added_by"].ToString();
                    }
                }
                else if (cmbSearch.Text.Equals("Item Code"))
                {
                    DataTable dt = dalItemCust.itemCodeSearch(keywords);

                    dgvItemCust.Rows.Clear();
                    foreach (DataRow item in dt.Rows)
                    {
                        int n = dgvItemCust.Rows.Add();
                        dgvItemCust.Rows[n].Cells["cust_name"].Value            = item["cust_name"].ToString();
                        dgvItemCust.Rows[n].Cells["item_code"].Value            = item["item_code"].ToString();
                        dgvItemCust.Rows[n].Cells["item_name"].Value            = item["item_name"].ToString();
                        dgvItemCust.Rows[n].Cells["item_cust_added_date"].Value = item["item_cust_added_date"].ToString();
                        dgvItemCust.Rows[n].Cells["item_cust_added_by"].Value   = item["item_cust_added_by"].ToString();
                    }
                }
                else
                {
                    loadItemCustomerList();
                }
            }
            else
            {
                loadItemCustomerList();
            }
        }