private void QuerybyCondition()
        {
            try
            {
                CheckStateDB();
                CultureInfo ci = new CultureInfo("en-US");
                String start = "", end = "";
                String[] dataSet = new String[4];
                String runYear = this.runNumberYear.Text, runNo = this.runNumberNo.Text;
                if (this.startDate.SelectedDate != null)
                {
                    DateTime startTime = (DateTime)this.startDate.SelectedDate;
                    start = startTime.ToString("dd/MM/yyyy", ci);
                    dataSet[0] = start;
                }
                if (this.finishDate.SelectedDate != null)
                {
                    DateTime finishTime = (DateTime)this.finishDate.SelectedDate;
                    end = finishTime.ToString("dd/MM/yyyy", ci);
                    dataSet[1] = end;
                }
                if ((string.IsNullOrWhiteSpace(runYear) && string.IsNullOrWhiteSpace(runNo)) == false)
                {
                    dataSet[2] = runYear;
                    dataSet[3] = runNo.TrimStart('0');
                }
                String sqlGet = "SELECT rowid, year, finishDate, recordDate, customerId, productId FROM command_card WHERE ";
                String[] searchSet = { "recordDate=@recordDate", "finishDate=@finishDate", "year=@year", "rowid=@rowid" };
                String[] paramList = { "@recordDate", "@finishDate", "@year", "@rowid" };
                String[] paramIn = new String[4];
                String part = "";

                if (dataSet.Length > 0)
                {
                    for (int i = 0; i < dataSet.Length; i++)
                    {
                        if (string.IsNullOrWhiteSpace(dataSet[i]) == false)
                        {
                            part += searchSet[i];
                            paramIn[i] = paramList[i];
                            part += " ";
                        }
                    }
                    part = part.TrimEnd(' ');
                    part = part.Replace(" ", " AND ");
                    sqlGet += part;
                    cmd = new MySqlCommand(sqlGet, conn);
                    for (int j = 0; j < paramList.Length; j++)
                    {
                        if (string.IsNullOrWhiteSpace(paramIn[j]) == false)
                        {
                            cmd.Parameters.AddWithValue(paramIn[j], dataSet[j]);
                        }
                    }

                    reader = cmd.ExecuteReader();
                    String currentDate = DateTime.Now.ToString("dd/MM/yyyy", ci);
                    String jobNo = "";
                    String jobProduct = "";
                    ArrayList product = new ArrayList();
                    String jobCustomer = "";
                    ArrayList customer = new ArrayList();
                    String jobStart = "";
                    String JobEnd = "";
                    while (reader.Read())
                    {
                        jobNo += reader.GetString("year") +"-" +reader.GetString("rowid").PadLeft(5, '0') + " \n ";
                        product.Add(reader.GetString("productId"));
                        customer.Add(reader.GetString("customerId"));
                        jobStart += reader.GetString("recordDate") + " \n ";
                        JobEnd += reader.GetString("finishDate") + " \n ";
                    }
                    reader.Close();
                    for (int i = 0; i < product.Count; i++)
                    {
                        jobProduct += GetProductName((String)product[i]) + "\n";
                        jobCustomer += GetCustomerName((String)customer[i]) + "\n";
                    }
                    String[] jobData = { jobNo, jobProduct, jobCustomer, jobStart, JobEnd};
                    Application.Current.Properties["dataTable"] = jobData;
                    TotalDataPreview ses = new TotalDataPreview();
                    ses.Show();

                }
                else
                {
                    throw new Exception("No choice was selected!");
                }
            }
            catch (Exception ee)
            {
                ErrorLogCreate(ee);
                MessageBox.Show("ไม่มีการเลือกคำค้นหา", "ข้อผิดพลาด");
            }

        }
Example #2
0
        private void QuerybyCondition()
        {
            try
            {
                CheckStateDB();
                CultureInfo ci = new CultureInfo("en-US");
                String      start = "", end = "";
                String[]    dataSet = new String[4];
                String      runYear = this.runNumberYear.Text, runNo = this.runNumberNo.Text;
                if (this.startDate.SelectedDate != null)
                {
                    DateTime startTime = (DateTime)this.startDate.SelectedDate;
                    start      = startTime.ToString("dd/MM/yyyy", ci);
                    dataSet[0] = start;
                }
                if (this.finishDate.SelectedDate != null)
                {
                    DateTime finishTime = (DateTime)this.finishDate.SelectedDate;
                    end        = finishTime.ToString("dd/MM/yyyy", ci);
                    dataSet[1] = end;
                }
                if ((string.IsNullOrWhiteSpace(runYear) && string.IsNullOrWhiteSpace(runNo)) == false)
                {
                    dataSet[2] = runYear;
                    dataSet[3] = runNo.TrimStart('0');
                }
                String   sqlGet    = "SELECT rowid, year, finishDate, recordDate, customerId, productId FROM command_card WHERE ";
                String[] searchSet = { "recordDate=@recordDate", "finishDate=@finishDate", "year=@year", "rowid=@rowid" };
                String[] paramList = { "@recordDate", "@finishDate", "@year", "@rowid" };
                String[] paramIn   = new String[4];
                String   part      = "";

                if (dataSet.Length > 0)
                {
                    for (int i = 0; i < dataSet.Length; i++)
                    {
                        if (string.IsNullOrWhiteSpace(dataSet[i]) == false)
                        {
                            part      += searchSet[i];
                            paramIn[i] = paramList[i];
                            part      += " ";
                        }
                    }
                    part    = part.TrimEnd(' ');
                    part    = part.Replace(" ", " AND ");
                    sqlGet += part;
                    cmd     = new MySqlCommand(sqlGet, conn);
                    for (int j = 0; j < paramList.Length; j++)
                    {
                        if (string.IsNullOrWhiteSpace(paramIn[j]) == false)
                        {
                            cmd.Parameters.AddWithValue(paramIn[j], dataSet[j]);
                        }
                    }

                    reader = cmd.ExecuteReader();
                    String    currentDate = DateTime.Now.ToString("dd/MM/yyyy", ci);
                    String    jobNo       = "";
                    String    jobProduct  = "";
                    ArrayList product     = new ArrayList();
                    String    jobCustomer = "";
                    ArrayList customer    = new ArrayList();
                    String    jobStart    = "";
                    String    JobEnd      = "";
                    while (reader.Read())
                    {
                        jobNo += reader.GetString("year") + "-" + reader.GetString("rowid").PadLeft(5, '0') + " \n ";
                        product.Add(reader.GetString("productId"));
                        customer.Add(reader.GetString("customerId"));
                        jobStart += reader.GetString("recordDate") + " \n ";
                        JobEnd   += reader.GetString("finishDate") + " \n ";
                    }
                    reader.Close();
                    for (int i = 0; i < product.Count; i++)
                    {
                        jobProduct  += GetProductName((String)product[i]) + "\n";
                        jobCustomer += GetCustomerName((String)customer[i]) + "\n";
                    }
                    String[] jobData = { jobNo, jobProduct, jobCustomer, jobStart, JobEnd };
                    Application.Current.Properties["dataTable"] = jobData;
                    TotalDataPreview ses = new TotalDataPreview();
                    ses.Show();
                }
                else
                {
                    throw new Exception("No choice was selected!");
                }
            }
            catch (Exception ee)
            {
                ErrorLogCreate(ee);
                MessageBox.Show("ไม่มีการเลือกคำค้นหา", "ข้อผิดพลาด");
            }
        }