예제 #1
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            // Get value for search
            var dtStart = new DateTime(dtpStart.Value.Year, dtpStart.Value.Month, dtpStart.Value.Day, 0, 0, 0);
            var dtEnd   = new DateTime(dtpEnd.Value.Year, dtpEnd.Value.Month, dtpEnd.Value.Day, 23, 59, 59);

            var strSDate  = dtStart.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond);
            var strEDate  = dtEnd.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond);
            int intUser   = Common.CnvNullToInt(cmbUser.SelectedValue);
            int intType   = Common.CnvNullToInt(((dynamic)cmbType.SelectedItem).Value);
            int intResult = Common.CnvNullToInt(((dynamic)cmbResult.SelectedItem).Value);
            int intStatus = Common.CnvNullToInt(((dynamic)cmbStatus.SelectedItem).Value);

            if (intStatus == (int)clsDBUltity.emMeasureStatus.Complete)
            {
                dgvMeasure.Columns["colEnable"].Visible = false;
                //dgvMeasure.Columns["colDelete"].Visible = true;
            }
            else
            {
                dgvMeasure.Columns["colEnable"].Visible = true;
                //dgvMeasure.Columns["colDelete"].Visible = false;
            }

            using (var objDb = new clsDBUltity())
            {
                // Binding grid measure
                dgvMeasure.DataSource = objDb.GetTBLMeasure(strSDate, strEDate, intUser, intType, intResult, intStatus);
                dgvMeasure.ClearSelection();
                dgvMeasureDetail.DataSource = null;
            }
        }
예제 #2
0
        private static void deleteMeasureRawOld()
        {
            using (var db = new clsDBUltity())
            {
                var dateLimit = DateTime.Now.AddDays(-Common.TimeDeleteMeasureDetailRaw);
                var tbl       = db.GetTBLMeasure(string.Empty, dateLimit.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond));

                if (!Common.TableIsNullOrEmpty(tbl))
                {
                    foreach (System.Data.DataRow row in tbl.Rows)
                    {
                        db.DeleteMeasureRaw(Common.CnvNullToInt(row["measure_id"]));
                    }
                }
            }
        }
예제 #3
0
        private void IntForm()
        {
            PathBase = Application.StartupPath;

            dgvMeasure.AutoGenerateColumns = false;

            using (var objDb = new clsDBUltity())
            {
                // Binding combobox User
                var tblUser = objDb.GetMUser();
                if (tblUser != null)
                {
                    var rowFirst = tblUser.NewRow();
                    rowFirst["username"] = "******";
                    rowFirst["userid"]   = -1;
                    tblUser.Rows.InsertAt(rowFirst, 0);
                    Common.BindingDataTableToComboBox(cmbUser, tblUser, "username", "userid", -1);
                }

                // Binding Type
                cmbType.DisplayMember = "Display";
                cmbType.ValueMember   = "Value";
                cmbType.Items.Add(new { Display = "All type", Value = -1 });
                cmbType.Items.Add(new { Display = "Alarm Test", Value = (int)clsDBUltity.emMeasureType.AlarmTest });
                cmbType.Items.Add(new { Display = "Walking Test", Value = (int)clsDBUltity.emMeasureType.WalkingTest });
                cmbType.SelectedIndex = 0;

                // Binding Status
                cmbStatus.DisplayMember = "Display";
                cmbStatus.ValueMember   = "Value";
                cmbStatus.Items.Add(new { Display = "Complete", Value = (int)clsDBUltity.emMeasureStatus.Complete });
                cmbStatus.Items.Add(new { Display = "Error", Value = (int)clsDBUltity.emMeasureStatus.Error });
                cmbStatus.SelectedIndex = 0;

                var dtStart = new DateTime(dtpStart.Value.Year, dtpStart.Value.Month, dtpStart.Value.Day, 0, 0, 0);
                var dtEnd   = new DateTime(dtpEnd.Value.Year, dtpEnd.Value.Month, dtpEnd.Value.Day, 23, 59, 59);

                var strSDate  = dtStart.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond);
                var strEDate  = dtEnd.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond);
                int intUser   = Common.CnvNullToInt(cmbUser.SelectedValue);
                int intType   = Common.CnvNullToInt(((dynamic)cmbType.SelectedItem).Value);
                int intResult = Common.CnvNullToInt(((dynamic)cmbResult.SelectedItem).Value);
                int intStatus = Common.CnvNullToInt(((dynamic)cmbStatus.SelectedItem).Value);

                // Binding grid measure
                dgvMeasure.DataSource = objDb.GetTBLMeasure(strSDate, strEDate, intUser, intType, intResult, intStatus);
                dgvMeasure.ClearSelection();
                if (dgvMeasure.Rows.Count > 0)
                {
                    dgvMeasure_CellClick(dgvMeasure, new DataGridViewCellEventArgs(0, 0));
                }

                dgvMeasure.Columns["colEnable"].Visible = false;

                if (Common.ModeApp == Common.emModeApp.User)
                {
                    lblStatus.Visible = false;
                    cmbStatus.Visible = false;
                    dgvMeasure.Columns["colDelete"].Visible = false;
                }
            }
        }
예제 #4
0
        private void dgvMeasure_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                return;
            }
            dgvMeasureDetail.AutoGenerateColumns = false;

            // btnDelete
            if (e.ColumnIndex == dgvMeasure.Columns["colDelete"].Index && e.RowIndex >= 0)
            {
                var measureid = Common.CnvNullToInt(dgvMeasure.Rows[e.RowIndex].Cells[MeasureID.Index].Value);
                using (var objDb = new clsDBUltity())
                {
                    // Binding grid measure detail
                    if (Common.ComfirmMsg("Do you want delete this record?"))
                    {
                        objDb.DeleteMeasure(measureid);

                        var dtStart = new DateTime(dtpStart.Value.Year, dtpStart.Value.Month, dtpStart.Value.Day, 0, 0, 0);
                        var dtEnd   = new DateTime(dtpEnd.Value.Year, dtpEnd.Value.Month, dtpEnd.Value.Day, 23, 59, 59);

                        var strSDate  = dtStart.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond);
                        var strEDate  = dtEnd.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond);
                        int intUser   = Common.CnvNullToInt(cmbUser.SelectedValue);
                        int intType   = Common.CnvNullToInt(((dynamic)cmbType.SelectedItem).Value);
                        int intResult = Common.CnvNullToInt(((dynamic)cmbResult.SelectedItem).Value);
                        int intStatus = Common.CnvNullToInt(((dynamic)cmbStatus.SelectedItem).Value);

                        // Binding grid measure
                        dgvMeasure.DataSource = objDb.GetTBLMeasure(strSDate, strEDate, intUser, intType, intResult, intStatus);
                        dgvMeasure.ClearSelection();
                        dgvMeasureDetail.DataSource = null;
                        dgvMeasureDetail.ClearSelection();
                    }
                    else
                    {
                        return;
                    }
                }
                return;
            }

            // btnEnable
            if (e.ColumnIndex == dgvMeasure.Columns["colEnable"].Index && e.RowIndex >= 0 && dgvMeasure.Columns["colEnable"].Visible)
            {
                var      measureid_selected = Common.CnvNullToInt(dgvMeasure.Rows[e.RowIndex].Cells[MeasureID.Index].Value);
                var      pathErrors         = Common.PathDataErrors + @"\" + measureid_selected;
                string[] files = null;

                if (Directory.Exists(pathErrors))
                {
                    files = Directory.GetFiles(pathErrors);
                }
                else
                {
                    using (var fbd = new FolderBrowserDialog())
                    {
                        DialogResult result = fbd.ShowDialog();

                        if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
                        {
                            files = Directory.GetFiles(fbd.SelectedPath);
                        }
                        else
                        {
                            return;
                        }
                    }
                }

                xExecuteNonQueryFromFile(files, measureid_selected);
            }

            var measure_id = Common.CnvNullToString(dgvMeasure.Rows[e.RowIndex].Cells[MeasureID.Index].Value);

            using (var objDb = new clsDBUltity())
            {
                // Binding grid measure detail
                dgvMeasureDetail.DataSource = objDb.GetTBLMeasureDetail(measure_id, chkView.Checked);
                dgvMeasureDetail.ClearSelection();
            }

            // keep selected row after onclick
            int index = e.RowIndex;

            dgvMeasure.Rows[index].Selected = true;
        }