Beispiel #1
0
        private void Grid_PreviewKeyDown_1(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.F2:
                crud.cmdAdd_Click();
                break;

            case Key.F3:
                crud.cmdEdit_Click();
                break;

            case Key.F4:
                String msgDel = crud.cmdDel_Click();
                if (msgDel != "")
                {
                    MessageBox.Show(msgDel, "Thông báo", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                break;

            case Key.F5:
                String msgSave = crud.cmdSave_Click();
                if (msgSave != "")
                {
                    MessageBox.Show(msgSave, "Thông báo", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                break;

            case Key.Escape:
                crud.cmdAbort_Click();
                break;

            case Key.F8:
                Utils.fExit();
                break;
            }
            if (e.Key == Key.Enter)
            {
                if (tblView.FocusedColumn.FieldName == "Masp" && tblView.FocusedColumn.Name == "colMasp")
                {
                    if (grdTichLuyDiem.GetFocusedRowCellValue(colMasp) == null || grdTichLuyDiem.GetFocusedRowCellValue(colMasp).ToString() == "")
                    {
                        tblView.FocusedColumn = colMasp;
                        return;
                    }

                    String sMasp = grdTichLuyDiem.GetCellValue(tblView.FocusedRowHandle, colMasp).ToString();
                    if (sMasp == null || sMasp == "")
                    {
                        tblView.FocusedColumn = colMasp;
                        return;
                    }

                    if (sMasp != "")
                    {
                        if (otblSP != null && otblSP.Rows.Count > 0)
                        {
                            DataRow[] vRow = otblSP.Select(string.Format("Masp='{0}'", sMasp));

                            if (vRow.Length > 0)
                            {
                                string errDuplicateSP = ValidateHelper.checkCodeValueNotDuplicate(TABLE_NAME, CODE_NAME, sMasp, "Mã SP");

                                if (errDuplicateSP.Length > 0)
                                {
                                    tblView.FocusedColumn = colMasp;
                                    Utils.showMessage(errDuplicateSP, "Thông báo");
                                    return;
                                }

                                grdTichLuyDiem.SetCellValue(tblView.FocusedRowHandle, colMasp, vRow[0]["Masp"].ToString());
                            }
                            else
                            {
                                dlg_ChonSanPham oChonSP = new dlg_ChonSanPham(otblSP);
                                oChonSP.ShowDialog();
                                DataRowView vRw = oChonSP.pRowChon;
                                if (vRw != null && vRw.Row.ItemArray.Length > 0)
                                {
                                    string errDuplicateSP = ValidateHelper.checkCodeValueNotDuplicate(TABLE_NAME, CODE_NAME, vRw.Row.ItemArray.GetValue(2).ToString(), "Mã SP");

                                    if (errDuplicateSP.Length > 0)
                                    {
                                        Utils.showMessage(errDuplicateSP, "Thông báo");
                                        return;
                                    }

                                    sMasp = vRw.Row.ItemArray.GetValue(2).ToString().ToUpper();
                                }
                                else
                                {
                                    tblView.FocusedColumn = colMasp;
                                }
                            }
                            //tblView.FocusedColumn = colDoanhSo;
                        }
                        tblView.CloseEditor();
                        tblView.ShowEditor();
                        grdTichLuyDiem.SetCellValue(tblView.FocusedRowHandle, colMasp, sMasp);
                    }
                }
            }
        }
Beispiel #2
0
        private void grdPhieu_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (isEdit == false)
            {
                return;
            }
            if (e.Key == Key.Enter)
            {
                if (tblView.FocusedColumn.FieldName == "Masp" && tblView.FocusedColumn.Name == "colMasp")
                {
                    if (grdPhieu.GetFocusedRowCellValue(colMasp) == null || grdPhieu.GetFocusedRowCellValue(colMasp).ToString() == "")
                    {
                        tblView.FocusedColumn = colMasp;
                        return;
                    }

                    String sMasp = grdPhieu.GetCellValue(tblView.FocusedRowHandle, colMasp).ToString();
                    if (sMasp == null || sMasp == "")
                    {
                        tblView.FocusedColumn = colMasp;
                        return;
                    }

                    if (sMasp != "")
                    {
                        double dSL = 0;
                        try
                        {
                            double.TryParse(grdPhieu.GetCellValue(tblView.FocusedRowHandle, colSoLuong).ToString(), out dSL);
                            if (dSL == 0)
                            {
                                dSL = 1;
                            }
                        }
                        catch { dSL = 1; }

                        if (otblSP != null && otblSP.Rows.Count > 0)
                        {
                            DataRow[] vRow = otblSP.Select(string.Format("Masp='{0}'", sMasp));
                            if (vRow.Length > 0)
                            {
                                grdPhieu.SetCellValue(tblView.FocusedRowHandle, colSanpham, vRow[0]["Tensp"].ToString());
                                grdPhieu.SetCellValue(tblView.FocusedRowHandle, colDVT, vRow[0]["Dvt"].ToString());
                                grdPhieu.SetCellValue(tblView.FocusedRowHandle, colQC, vRow[0]["Quycach"].ToString());
                                grdPhieu.SetCellValue(tblView.FocusedRowHandle, colSoLuong, dSL);
                            }
                            else
                            {
                                dlg_ChonSanPham oChonSP = new dlg_ChonSanPham(otblSP);
                                oChonSP.ShowDialog();
                                DataRowView vRw = oChonSP.pRowChon;
                                if (vRw != null && vRw.Row.ItemArray.Length > 0)
                                {
                                    grdPhieu.SetCellValue(tblView.FocusedRowHandle, colSanpham, vRw.Row.ItemArray.GetValue(3).ToString());
                                    grdPhieu.SetCellValue(tblView.FocusedRowHandle, colDVT, vRw.Row.ItemArray.GetValue(4).ToString());
                                    grdPhieu.SetCellValue(tblView.FocusedRowHandle, colQC, vRw.Row.ItemArray.GetValue(5).ToString());
                                    sMasp = vRw.Row.ItemArray.GetValue(2).ToString().ToUpper();
                                    grdPhieu.SetCellValue(tblView.FocusedRowHandle, colSoLuong, dSL);
                                }
                                else
                                {
                                    tblView.FocusedColumn = colMasp;
                                }
                            }
                        }

                        tblView.CloseEditor();
                        tblView.ShowEditor();
                        grdPhieu.SetCellValue(tblView.FocusedRowHandle, colMasp, sMasp);
                        //tblView.PostEditor();
                    }
                }
            }

            if (e.Key == Key.Delete)
            {
                try
                {
                    if (grdPhieu.GetFocusedRowCellValue(colChanhxectid) == null || grdPhieu.GetFocusedRowCellValue(colChanhxectid).ToString() == "")
                    {
                        e.Handled = true;
                        return;
                    }
                    if (Utils.ConfirmMessage(String.Format("Bạn có chắc muốn xóa {0} không ?", grdPhieu.GetCellValue(tblView.FocusedRowHandle, colMasp).ToString()), "Xác nhận xóa") == true)
                    {
                        tblView.DeleteRow(tblView.FocusedRowHandle);
                    }
                }
                catch (Exception ex) { ex.Data.Clear(); }
            }
        }
        //private void tblViewCT_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        //{

        //}

        private void tblViewCT_PreviewKeyDown1(object sender, System.Windows.Input.KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.F2:
                crud.cmdAdd_Click();
                break;

            case Key.F3:
                crud.cmdEdit_Click();
                break;

            case Key.F4:
                String msg = crud.cmdDel_Click();
                if (msg != "")
                {
                    Utils.showMessage(msg, "Thông báo");
                }
                break;

            case Key.F5:
                String msgSave = crud.cmdSave_Click();
                if (msgSave != "")
                {
                    Utils.showMessage(msgSave, "Thông báo");
                }
                break;

            case Key.Escape:
                crud.cmdAbort_Click();
                break;

            case Key.F8:
                Utils.fExit();
                break;
            }

            if (e.Key == Key.Enter)
            {
                if (tblViewCT.FocusedColumn.FieldName == "Masp" && tblViewCT.FocusedColumn.Name == "colMasp")
                {
                    if (grdBangGiaCT.GetFocusedRowCellValue(colMasp) == null || grdBangGiaCT.GetFocusedRowCellValue(colMasp).ToString() == "")
                    {
                        tblViewCT.FocusedColumn = colMasp;
                        return;
                    }

                    String sMasp = grdBangGiaCT.GetCellValue(tblViewCT.FocusedRowHandle, colMasp).ToString();
                    if (sMasp == null || sMasp == "")
                    {
                        tblViewCT.FocusedColumn = colMasp;
                        return;
                    }

                    if (sMasp != "")
                    {
                        if (otblSP != null && otblSP.Rows.Count > 0)
                        {
                            DataRow[] vRow = otblSP.Select(string.Format("Masp='{0}'", sMasp));

                            if (vRow.Length > 0)
                            {
                                string errDuplicateSP = ValidateHelper.checkCodeValueNotDuplicate(TABLE_NAME, CODE_NAME, sMasp, "Mã SP");

                                if (errDuplicateSP.Length > 0)
                                {
                                    tblViewCT.FocusedColumn = colMasp;
                                    Utils.showMessage(errDuplicateSP, "Thông báo");
                                    return;
                                }

                                grdBangGiaCT.SetCellValue(tblViewCT.FocusedRowHandle, colMaspid, vRow[0]["Maspid"].ToString());
                                grdBangGiaCT.SetCellValue(tblViewCT.FocusedRowHandle, colTenSP, vRow[0]["Tensp"].ToString());
                            }
                            else
                            {
                                dlg_ChonSanPham oChonSP = new dlg_ChonSanPham(otblSP);
                                oChonSP.ShowDialog();
                                DataRowView vRw = oChonSP.pRowChon;
                                if (vRw != null && vRw.Row.ItemArray.Length > 0)
                                {
                                    string errDuplicateSP = ValidateHelper.checkCodeValueNotDuplicate(TABLE_NAME, CODE_NAME, vRw.Row.ItemArray.GetValue(2).ToString(), "Mã SP");

                                    if (errDuplicateSP.Length > 0)
                                    {
                                        Utils.showMessage(errDuplicateSP, "Thông báo");
                                        return;
                                    }

                                    grdBangGiaCT.SetCellValue(tblViewCT.FocusedRowHandle, colMaspid, vRw.Row.ItemArray.GetValue(0).ToString());
                                    grdBangGiaCT.SetCellValue(tblViewCT.FocusedRowHandle, colTenSP, vRw.Row.ItemArray.GetValue(3).ToString());
                                    sMasp = vRw.Row.ItemArray.GetValue(2).ToString().ToUpper();
                                }
                                else
                                {
                                    tblViewCT.FocusedColumn = colMasp;
                                }
                            }
                            tblViewCT.FocusedColumn = colTenSP;
                        }
                        tblViewCT.CloseEditor();
                        tblViewCT.ShowEditor();
                        grdBangGiaCT.SetCellValue(tblViewCT.FocusedRowHandle, colMasp, sMasp);
                        //tblView.PostEditor();
                    }
                }
            }

            if (e.Key == Key.Delete)
            {
                try
                {
                    if (grdBangGiaCT.GetFocusedRowCellValue(colMaspid) == null || grdBangGiaCT.GetFocusedRowCellValue(colMaspid).ToString() == "")
                    {
                        e.Handled = true;
                        return;
                    }
                    if (Utils.ConfirmMessage(String.Format("Bạn có chắc muốn xóa {0} không ?", grdBangGiaCT.GetCellValue(tblViewCT.FocusedRowHandle, colMasp).ToString()), "Xác nhận xóa") == true)
                    {
                        tblViewCT.DeleteRow(tblViewCT.FocusedRowHandle);
                    }
                }
                catch (Exception ex) { ex.Data.Clear(); }
            }
        }