Exemplo n.º 1
0
        private void btnDelWorksheet_Click(object sender, EventArgs e)
        {
            try
            {
                if (bsWorksheet.Current != null)
                {
                    DatabaseSet.工作單Row row = (bsWorksheet.Current as DataRowView).Row as DatabaseSet.工作單Row;

                    string worksheet = row.單號;

                    OleDbConnection conn = DbConnection.Instance;
                    conn.Open();

                    string cmdText = "SELECT COUNT(*) FROM 工時 WHERE 工作單號 = ? ";

                    OleDbParameter paramWs = new OleDbParameter("工作單號", worksheet);

                    OleDbCommand cmd = new OleDbCommand(cmdText, conn);
                    cmd.Parameters.Add(paramWs);

                    int result = (int)cmd.ExecuteScalar();

                    if (result != 0)
                    {
                        MessageBox.Show("工作單 '" + worksheet + "' 已有工時資料登記,無法刪除。");
                    }
                    else if (MessageBox.Show("確定刪除工作單 " + worksheet + " 及其所有相關資料?\n(LaborWage程式裡的相關資料並不會被刪除)", "刪除提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                    {
                        row.Delete();
                        MessageBox.Show("刪除了" + 工作單TableAdapter.Instance.Update(row) + "筆資料");
                    }

                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                Global.ShowError(ex);
            }
        }
Exemplo n.º 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                int hour = int.Parse(txtHour.Text);
                if (hour < 0)
                {
                    throw new SWLHMSException("填寫時數不得小於0");
                }

                if (!ckbOvertime.Checked && hour > _remainHour && !this.IsHoliday)
                {
                    throw new SWLHMSException("填寫時數大於剩餘時數");
                }

                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                Global.ShowError(ex);
            }
        }
Exemplo n.º 3
0
        private void btnDelWorksheet_Click(object sender, EventArgs e)
        {
            try
            {
                string worksheet = tbxWorksheetNumber.Text;

                //OleDbConnection conn = DbConnection.Instance;
                //conn.Open();

                //string cmdText = "SELECT COUNT(*) FROM 工時 WHERE 工作單號 = ? ";

                //OleDbParameter paramWs = new OleDbParameter("工作單號", worksheet);

                //OleDbCommand cmd = new OleDbCommand(cmdText, conn);
                //cmd.Parameters.Add(paramWs);

                //int result = (int)cmd.ExecuteScalar();

                //if (result != 0)
                //{
                //    MessageBox.Show("工作單 '" + worksheet + "' 已有工時資料登記,無法刪除。");
                //}
                //else

                if (MessageBox.Show("確定刪除工作單 " + worksheet + " 及其所有相關資料?\n(LaborWage程式裡的相關資料並不會被刪除)", "刪除提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    _worksheetTable[0].Delete();
                    MessageBox.Show("刪除了" + 工作單TableAdapter.Instance.Update(_worksheetTable) + "筆資料");
                    this.Close();
                }

                //conn.Close();
            }
            catch (Exception ex)
            {
                Global.ShowError(ex);
            }
        }
Exemplo n.º 4
0
 private void btnNGReason_Click(object sender, EventArgs e)
 {
     try
     {
         DataGridViewCell cell = btnNGReason.Tag as DataGridViewCell;
         if (cell != null)
         {
             NGReasonForm form      = new NGReasonForm();
             string       oriReason = cell.Value as string;
             form.NGReason = oriReason;
             if (form.ShowDialog() == DialogResult.OK)
             {
                 string newReason = form.NGReason;
                 cell.Value = newReason;
                 //cell.Value = cell.Value + "\n" + newReason;
             }
         }
     }
     catch (Exception ex)
     {
         Global.ShowError(ex);
     }
 }
Exemplo n.º 5
0
        private void btnStore_Click(object sender, EventArgs e)
        {
            try
            {
                string username  = txtUsername.Text = txtUsername.Text.Trim();
                string password  = txtPassword.Text = txtPassword.Text.Trim();
                int    authority = this.SelectedAuthority;
                try
                {
                    if (authority == -1)
                    {
                        throw new SWLHMSException("請選擇使用者身分");
                    }


                    if (this.EditState == EditStateType.New && _reservedUsername.Contains(username.ToLower()))
                    {
                        throw new SWLHMSException("登入名稱不可為關鍵字 \"admin\", \"manager\", \"ganger\", \"qa\", \"guest\"");
                    }

                    if (this.EditState == EditStateType.Edit)
                    {
                        if (bindingSource.Current != null)
                        {
                            txtPassword.DataBindings[0].WriteValue();
                            txtUsername.DataBindings[0].WriteValue();
                            cbxAuthority.DataBindings[0].WriteValue();
                            bindingSource.EndEdit();
                            DatabaseSet.使用者Row row = this.SelectedRow;
                            //row.帳號 = username;
                            //row.密碼 = password;
                            //row.權限 = authority;

                            int a = 使用者TableAdapter.Instance.Update(row);
                        }
                    }
                    else if (this.EditState == EditStateType.New)
                    {
                        DatabaseSet.使用者Row newRow = this.Table.New使用者Row();
                        newRow.帳號 = username;
                        newRow.密碼 = password;
                        newRow.限  = authority;

                        this.Table.Rows.Add(newRow);

                        使用者TableAdapter.Instance.Update(newRow);
                    }

                    this.EditState = EditStateType.None;
                    this.UpdateIdentities();
                }
                catch (ConstraintException)
                {
                    MessageBox.Show("已存在登入名稱 \"" + username + "\",請指定其他名稱");
                }
            }
            catch (Exception ex)
            {
                Global.ShowError(ex);
            }
            finally
            {
                if (this.EditState == EditStateType.Edit)
                {
                    txtPassword.DataBindings[0].ReadValue();
                    txtUsername.DataBindings[0].ReadValue();
                    cbxAuthority.DataBindings[0].ReadValue();
                }
            }
        }
Exemplo n.º 6
0
        private void btnSrchWorksheet_Click(object sender, EventArgs e)
        {
            try
            {
                //string dateTxt = string.Empty;
                string dateTxt = txtDate.Text;

                //if (txtYear.Text != string.Empty)
                //{
                //    year = int.Parse(txtYear.Text);
                //    dateTxt += year.ToString();

                //    if (txtMonth.Text != string.Empty)
                //    {
                //        month = int.Parse(txtMonth.Text);
                //        dateTxt += month.ToString("00");

                //        if (txtDay.Text != string.Empty)
                //        {
                //            day = int.Parse(txtDay.Text);
                //            dateTxt += day.ToString("00");
                //        }
                //    }
                //}



                // Get the worksheet number by the dateTxt
                OleDbConnection conn         = DbConnection.Instance;
                ConnectionState oriConnState = conn.State;
                if ((conn.State & ConnectionState.Open) != ConnectionState.Open)
                {
                    conn.Open();
                }

                OleDbCommand cmd = new OleDbCommand();
                cmd.Connection = conn;
                if (dateTxt != string.Empty)
                {
                    //cmd.CommandText = "SELECT 單號 FROM 工作單 WHERE 單號 LIKE '" + dateTxt + "%'";
                    cmd.CommandText = "SELECT 單號 FROM 工作單";

                    //產生日期條件
                    List <string> dateFilter = new List <string>();

                    string[] dateFunc = new string[] { "YEAR", "MONTH", "DAY" };

                    string[] dateTxtArr = dateTxt.Split('-');
                    for (int i = 0; i < 3; i++)
                    {
                        if (!string.IsNullOrEmpty(dateTxtArr[i].Trim()))
                        {
                            int val = int.Parse(dateTxtArr[i]);
                            dateFilter.Add(dateFunc[i] + "(單據日期)=" + val);
                        }
                    }

                    if (dateFilter.Count > 0)
                    {
                        cmd.CommandText += " WHERE " + string.Join(" AND ", dateFilter.ToArray());
                    }
                }
                else
                {
                    cmd.CommandText = "SELECT 單號 FROM 工作單";
                }

                OleDbDataReader reader           = cmd.ExecuteReader();
                List <string>   worksheetNumbers = new List <string>();
                while (reader.Read())
                {
                    worksheetNumbers.Add(reader.GetString(0));
                }
                reader.Close();

                if (oriConnState == ConnectionState.Closed)
                {
                    conn.Close();
                }

                cbbWorksheetNubmerS.SelectedIndex = -1;
                cbbWorksheetNubmerS.DataSource    = worksheetNumbers;
            }
            catch (Exception ex)
            {
                Global.ShowError(ex);
            }
        }
Exemplo n.º 7
0
        private void btnStore_Click(object sender, EventArgs e)
        {
            try
            {
                if (_remainHours > 0 && !this.TodayIsHoliday)
                {
                    if (MessageBox.Show("尚有時數未填寫完畢,確定要儲存嗎?", "儲存提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                    {
                        return;
                    }
                }

                //SetFinishDate();

                //重驗後的工時資料刪除時進行復原工作
                int update = 0;

                DatabaseSet.工時DataTable table = (DatabaseSet.工時DataTable)_dataTable.Copy();
                foreach (DataRow row in _dataTable)
                {
                    if (row.RowState == DataRowState.Deleted)
                    {
                        string id = (string)row["編號", DataRowVersion.Original];
                        update += 工時TableAdapter.Instance.DeleteEx(id);
                    }
                }
                foreach (DataRow row in table.Select(null, null, DataViewRowState.Deleted))
                {
                    row.AcceptChanges();
                }

                update += 工時TableAdapter.Instance.Update(table);


                int reinspect;
                int qa = UpdateQATable(out reinspect);

                UpdateFinishDate();

                string msg = "更新了 " + update + " 筆資料";
                if (qa > 0)
                {
                    msg += "\n新增了 " + qa + " 筆待驗資料";
                }
                if (reinspect > 0)
                {
                    msg += "\n重新送驗了 " + reinspect + "筆資料";
                }

                MessageBox.Show(msg);

                UpdateRemainAmount();
                LoadOldHourData();
                LoadNGData();
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                Global.ShowError(ex);
            }
        }
Exemplo n.º 8
0
        private void btnAddList_Click(object sender, EventArgs e)
        {
            try
            {
                decimal hour = decimal.Parse(tbxHour.Text);
                if (_remainHours >= hour || ckbOvertime.Checked || this.TodayIsHoliday)
                {
                    DatabaseSet.工時Row newRow = _dataTable.New工時Row();

                    if (rbProduce.Checked)
                    {
                        //if (dgvPart.CurrentRow != null)
                        if (cbbPart.SelectedIndex != -1)
                        {
                            //string worksheetNumber = dgvPart.CurrentRow.Cells["col單號"].Value.ToString();
                            //string partNumber = dgvPart.CurrentRow.Cells["col品號"].Value.ToString();

                            DataRowView selectedRow     = (DataRowView)cbbPart.SelectedItem;
                            string      worksheetNumber = selectedRow["單號"].ToString();
                            string      partNumber      = selectedRow["品號"].ToString();
                            int         wpID            = (int)selectedRow["編號"];

                            // Check whether finish date is set
                            if (selectedRow["實際完成日"] != DBNull.Value && dtpDate.Value >= (DateTime)selectedRow["實際完成日"])
                            {
                                throw new SWLHMSException("填寫時間 " + dtpDate.Value.ToString("yyyy/MM/dd") + " 已在品號 '" + partNumber + "' 完成日之後");
                            }

                            string borrower = null;

                            // Check the borrow line
                            if (ckbBorrowLine.Checked)
                            {
                                if (cbbBorrowLine.SelectedIndex == -1)
                                {
                                    throw new SWLHMSException("請選擇借入產線");
                                }

                                borrower = (string)this.cbbBorrowLine.SelectedItem;
                            }

                            // Check the number of done
                            if (txtNum.Text.Trim() == string.Empty)
                            {
                                throw new SWLHMSException("未輸入完成數量");
                            }
                            int num = int.Parse(txtNum.Text);


                            /* Only for 1.08.15 below
                             *
                             * // Check whether part number is duplicated
                             * string checkExpr = "工品編號 = '" + wpID + "' AND 工作單號 ='" + worksheetNumber + "'";
                             * if(borrower != null)
                             *      checkExpr += " AND 借入產線 = '" + borrower + "'";
                             * else
                             *      checkExpr += " AND 借入產線 IS NULL ";
                             * if ((int)_dataTable.Compute("Count(品號)", checkExpr) > 0)
                             *      throw new SWLHMSException("品號 '" + partNumber + "' 已存在");
                             */

                            // Check the remain amount
                            if (_remainAmount < num)
                            {
                                throw new SWLHMSException("輸入數量超過剩餘數量");
                            }

                            // hour type
                            HourType hourType = (HourType)cbxHourType.SelectedIndex;

                            string QCN = txtQCN.Text;

                            newRow.FillRow(this.SelectedLaborNumber, dtpDate.Value, worksheetNumber, hour, num, borrower, QCN, wpID, hourType);
                            newRow.新舊        = "*";
                            newRow["品號"]     = partNumber;
                            newRow["工時類型名稱"] = hourType.ToString();

                            _dataTable.Rows.Add(newRow);

                            //if (ckbFinishDate.Checked)
                            //{
                            //    DateTime date = dateFinishDate.Value;
                            //    _finishDateList.Add(newRow, date);
                            //}

                            txtNum.Text = "0";
                            txtQCN.Text = null;
                        }
                    }
                    else
                    {
                        if (cbbNonProduce.SelectedIndex != -1)
                        {
                            if ((int)cbbNonProduce.SelectedValue == Global.NonProduct_Other && tbxRemark.Text == string.Empty)
                            {
                                throw new SWLHMSException("非生產項目為 其他 時,備註欄不得為空");
                            }

                            string borrower = null;
                            // Check the borrow line
                            if (ckbBorrowLine.Checked)
                            {
                                if (cbbBorrowLine.SelectedIndex == -1)
                                {
                                    throw new SWLHMSException("請選擇借入產線");
                                }

                                borrower = (string)this.cbbBorrowLine.SelectedItem;
                            }

                            newRow.FillRow(cbxLaborNumber.SelectedValue.ToString(), dtpDate.Value, hour, (int)cbbNonProduce.SelectedValue, cbbNonProduce.Text, tbxRemark.Text, borrower);
                            newRow.新舊        = "*";
                            newRow["工時類型名稱"] = HourType.一般工時.ToString();
                            _dataTable.Rows.Add(newRow);
                        }
                    }

                    dgvHoursData.AutoResizeColumns();
                    UpdateRemainHour();
                    UpdateRemainAmount();
                }
                else
                {
                    throw new SWLHMSException("填寫時數超過剩餘時數");
                }
            }
            catch (Exception ex)
            {
                Global.ShowError(ex);
            }
        }
Exemplo n.º 9
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                if (_table != null)
                {
                    //檢查是否填寫完整
                    DataTable table = this.InspectMode == InspeceMode.ByPn ? this.GroupTable : _table;

                    DataRow[] rows = table.Select("檢驗=True AND 檢驗結果=False");

                    StringBuilder error = new StringBuilder();

                    foreach (DataRow row in rows)
                    {
                        if (string.IsNullOrEmpty(row["NG原因"] as string))
                        {
                            error.AppendLine("項次" + row["項次"] + " 必須填寫NG原因");
                        }

                        if (string.IsNullOrEmpty(row["NG處理"] as string))
                        {
                            error.AppendLine("項次" + row["項次"] + " 必須選擇NG處理方式");
                        }

                        if (error.Length > 100)
                        {
                            error.AppendLine("...");
                            break;
                        }
                    }
                    if (error.Length != 0)
                    {
                        throw new SWLHMSException(error.ToString());
                    }

                    if (MessageBox.Show("資料經送出後不可再修改,請確認後繼續", "送出確認", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
                    {
                        if (this.InspectMode == InspeceMode.ByPn)
                        {
                            //將GroupTable的內容回填到Table上
                            rows = table.Select("檢驗=True");
                            foreach (DataRow groupRow in rows)
                            {
                                if (!groupRow.IsNull("工作單號") && !groupRow.IsNull("工品編號"))
                                {
                                    string worksheet = groupRow["工作單號"].ToString();
                                    int    wpid      = (int)groupRow["工品編號"];

                                    DataRow[] srcRow = _table.Select("工作單號= '" + worksheet + "' AND 工品編號=" + wpid);
                                    foreach (DataRow row in srcRow)
                                    {
                                        row["檢驗"]   = true;
                                        row["檢驗結果"] = groupRow["檢驗結果"];
                                        row["特許"]   = groupRow["特許"];
                                        row["NG處理"] = groupRow["NG處理"];
                                        row["NG原因"] = groupRow["NG原因"];
                                    }
                                }
                            }
                        }
                        int ok;
                        int update = DatabaseSet.UpdateInspectList(_table, out ok);

                        MessageBox.Show("更新了 " + update + " 筆檢驗資料\n共 " + ok + " 筆檢驗OK");
                        SearchList();
                    }
                }
            }
            catch (Exception ex)
            {
                Global.ShowError(ex);
            }
        }
Exemplo n.º 10
0
        private void btnStoreNP_Click(object sender, EventArgs e)
        {
            try
            {
                int    newNumber = int.Parse(tbxNPNumber.Text);
                string newName   = tbxNPName.Text;

                try
                {
                    if (this.EditState == EditStateType.Edit)
                    {
                        if (bindingSource.Current != null)
                        {
                            DatabaseSet.非生產Row row = (bindingSource.Current as DataRowView).Row as DatabaseSet.非生產Row;

                            if ((int)row["編號", DataRowVersion.Original] == Global.NonProduct_Other)
                            {
                                if (!newName.Contains("其他"))
                                {
                                    throw new SWLHMSException("更改 其他 項目請至少包含\"其他\"兩字以進行區別");
                                }
                                row.稱 = newName;

                                if (newNumber != 100)
                                {
                                    throw new SWLHMSException("其他 項目不得更改編號");
                                }
                            }
                            else
                            {
                                row.FillRow(newNumber, newName);
                            }

                            非生產TableAdapter.Instance.Update(row);;
                        }
                    }
                    else if (this.EditState == EditStateType.New)
                    {
                        DatabaseSet.非生產Row newRow = DatabaseSet.非生產Table.New非生產Row();

                        newRow.FillRow(newNumber, newName);
                        DatabaseSet.非生產Table.Rows.Add(newRow);

                        非生產TableAdapter.Instance.Update(newRow);
                    }
                }
                catch (ConstraintException)
                {
                    MessageBox.Show("已存在非生產項目 " + newNumber + " (" + newName + "),請指定其他編號");
                }

                this.EditState = EditStateType.None;
            }
            catch (Exception ex)
            {
                Global.ShowError(ex);
            }
            finally
            {
                if (this.EditState == EditStateType.Edit)
                {
                    tbxNPNumber.DataBindings[0].ReadValue();
                    tbxNPName.DataBindings[0].ReadValue();
                }
            }
        }