Ejemplo n.º 1
0
        void dgvEditCt_CellValidated(object sender, DataGridViewCellEventArgs e)
        {        //Cai dat cac ham tinh toan
            dgvVoucher dgvEditCt = (dgvVoucher)sender;

            if (this.ActiveControl != dgvEditCt)
            {
                return;
            }

            drCurrent = ((DataRowView)bdsEditCt.Current).Row;
            DataGridViewCell dgvCell       = ((dgvVoucher)sender).CurrentCell;
            string           strColumnName = dgvCell.OwningColumn.Name.ToUpper();

            if (Common.Inlist(strColumnName, "SO_LUONG9"))
            {
                Update_Gia_Vt(drCurrent);
            }

            if (Common.Inlist(strColumnName, "SO_LUONG9,GIA_NT9,TIEN_NT9,TIEN"))
            {
                Voucher.Calc_So_Luong(drCurrent);
                Voucher.Update_TTien(this);
            }

            else if (Common.Inlist(strColumnName, "TIEN"))
            {
                Voucher.Calc_Tien(drCurrent);
                Voucher.Update_TTien(this);
            }

            bdsEditCt.EndEdit();            //Cap nhat lai DataSource
        }
Ejemplo n.º 2
0
        void dgvEditCt_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Space)
            {
                if (dgvEditCt1.CurrentCell.OwningColumn.DataPropertyName == "DVT")
                {
                    drCurrent = ((DataRowView)bdsEditCt.Current).Row;
                    string strMa_Vt     = (string)drCurrent["Ma_Vt"];
                    string strDvt_Old   = (string)drCurrent["Dvt"];
                    string strDvt_Chuan = string.Empty;

                    DataRow drDmVt = DataTool.SQLGetDataRowByID("LIVATTU", "Ma_Vt", strMa_Vt);
                    strDvt_Chuan = (string)drDmVt["Dvt"];

                    string inputMask = (string)drDmVt["Dvt"];

                    for (int i = 1; i <= 3; i++)
                    {
                        inputMask += (string)drDmVt["Dvt" + i] == string.Empty ? string.Empty : "," + (string)drDmVt["Dvt" + i];
                    }

                    if (inputMask != string.Empty)
                    {
                        inputMask += "," + inputMask;
                    }
                    if (inputMask == null || inputMask == string.Empty)
                    {
                        return;
                    }

                    string[] strArrInputMask = inputMask.Split(',');
                    for (int i = 0; i <= strArrInputMask.Length - 1; i++)
                    {
                        if (strArrInputMask[i] == strDvt_Old)
                        {
                            drCurrent["Dvt"] = strArrInputMask[i + 1];
                            break;
                        }
                    }

                    if ((string)drCurrent["Dvt"] == strDvt_Chuan)
                    {
                        drCurrent["He_So9"] = 1;
                    }
                    else
                    {
                        for (int i = 1; i <= 3; i++)
                        {
                            if ((string)drDmVt["Dvt" + i] == (string)drCurrent["Dvt"])
                            {
                                drCurrent["He_So9"] = drDmVt["He_So" + i];
                            }
                        }
                    }

                    Voucher.Calc_So_Luong(drCurrent);
                }
            }
        }
Ejemplo n.º 3
0
        private bool CellKeyEnter()
        {        //Ham thuc hien phim Enter: true: thuc hien thanh cong, false: khong thuc hien duoc
            if (dgvEditCt1.CurrentCell == null)
            {
                return(false);
            }

            DataGridViewCell dgvCell          = dgvEditCt1.CurrentCell;
            string           strCurrentColumn = dgvCell.OwningColumn.Name.ToUpper();

            #region Enter tai TEN_VT
            if (Common.Inlist(strCurrentColumn, "TEN_VT"))
            {
                drCurrent = ((DataRowView)bdsEditCt.Current).Row;

                if (drCurrent["Ma_Vt"] == DBNull.Value || (string)drCurrent["Ma_Vt"] == string.Empty)
                {
                    bool bIsCurrentLastRow = dgvEditCt1.bIsCurrentLastRow;

                    bdsEditCt.RemoveCurrent();
                    dtEditCt.AcceptChanges();

                    if (bIsCurrentLastRow)
                    {
                        this.SelectNextControl(dgvEditCt1, true, true, true, true);
                    }

                    return(true);
                }

                return(false);
            }
            #endregion

            #region Enter tai TIEN_NT9
            if (Common.Inlist(strCurrentColumn, "TIEN_NT9"))
            {
                if (txtMa_Tte.Text.Trim() == Element.sysMa_Tte)
                {
                    // Cap nhat tien TIEN_NT9 truoc khi xuong dong
                    double dbTien_Nt9 = 0;
                    if (double.TryParse(dgvEditCt1.CurrentCell.FormattedValue.ToString().Trim(), out dbTien_Nt9))
                    {
                        dgvEditCt1.CancelEdit();
                        drCurrent             = ((DataRowView)bdsEditCt.Current).Row;
                        drCurrent["TIEN_NT9"] = dbTien_Nt9;
                        Voucher.Calc_So_Luong(drCurrent);
                        Voucher.Update_TTien(this);
                    }

                    if (dgvEditCt1.bIsCurrentLastRow)
                    {
                        if (!Voucher.AddRow(this))
                        {
                            this.SelectNextControl(dgvEditCt1, true, true, true, true);
                        }
                        else
                        {
                            dgvEditCt1.FocusNextFirstCell();
                            return(true);
                        }
                    }
                    else
                    {
                        dgvEditCt1.FocusNextFirstCell();
                    }
                }
                return(false);
            }

            #endregion

            #region Enter TIEN
            if (Common.Inlist(strCurrentColumn, "TIEN"))
            {
                if (dgvEditCt1.bIsCurrentLastRow)
                {
                    // Cap nhat Tien truoc khi xuống dòng
                    double dbTien = 0;
                    if (double.TryParse(dgvEditCt1.CurrentCell.FormattedValue.ToString().Trim(), out dbTien))
                    {
                        dgvEditCt1.CancelEdit();
                        drCurrent         = ((DataRowView)bdsEditCt.Current).Row;
                        drCurrent["TIEN"] = dbTien;
                        Voucher.Calc_So_Luong(drCurrent);
                        Voucher.Update_TTien(this);
                    }

                    if (!Voucher.AddRow(this))
                    {
                        return(false);
                    }
                    else
                    {
                        dgvEditCt1.FocusNextFirstCell();
                    }


                    return(true);
                }

                return(false);
            }
            #endregion

            return(false);
        }
Ejemplo n.º 4
0
        private bool dgvLookupMa_Vt(ref DataGridViewCell dgvCell)
        {
            string strValue = string.Empty;

            if (this.ActiveControl.GetType().Name == "DataGridViewTextBoxEditingControl")
            {
                strValue = this.ActiveControl.Text;
            }
            else
            {
                strValue = dgvCell.FormattedValue.ToString().Trim();
            }

            bool bRequire = false;

            //frmVatTu frmLookup = new frmVatTu();
            DataRow drLookup = Lookup.ShowLookup("Ma_Vt", strValue, bRequire, "", "");

            if (bRequire && drLookup == null)
            {
                return(false);
            }

            if (drLookup == null)
            {
                dgvCell.Value = string.Empty;
                dgvCell.Tag   = string.Empty;
            }
            else
            {
                drCurrent = ((DataRowView)bdsEditCt.Current).Row;

                string strMa_Vt_Old = drCurrent["Ma_Vt"] == DBNull.Value ? string.Empty : (string)drCurrent["Ma_Vt"];
                string strMa_Vt     = (string)drLookup["Ma_Vt"];

                dgvEditCt1.CancelEdit();
                dgvCell.Value = drLookup["Ma_Vt"].ToString();
                dgvCell.Tag   = drLookup["Ten_Vt"].ToString();

                //La vat tu dich vu
                if ((string)drLookup["Loai_Vt"] == "0")
                {
                    if ((string)drCurrent["Ten_Vt"] == string.Empty)
                    {
                        drCurrent["Ten_Vt"] = drLookup["Ten_Vt"];
                    }

                    drCurrent["Dvt"] = drLookup["Dvt"];
                }
                else
                {
                    drCurrent["Ten_Vt"] = drLookup["Ten_Vt"];

                    if (strMa_Vt != strMa_Vt_Old)
                    {
                        drCurrent["Dvt"]    = drLookup["Dvt"];
                        drCurrent["He_So9"] = 1;
                        Voucher.Calc_So_Luong(drCurrent);
                    }
                    else
                    {
                        if (drCurrent["Dvt"] == DBNull.Value || (string)drCurrent["Dvt"] == string.Empty)
                        {
                            drCurrent["Dvt"] = drLookup["Dvt"];
                        }
                    }
                }
            }
            return(true);
        }