public Boolean init(string dbname, string workingdir)
        {
            string          sqlStr;
            OleDbDataReader oleReader;

            contractDb       = new db(dbname);
            edit             = false;
            laisuat          = 0;
            MaHD             = "";
            HTTra            = TraDinhKy;
            optTraDK.Checked = true;
            dbfile           = dbname;
            frmNhapTN        = new NhapKyTraNo();
            frmNhapTN.saved  = false;
            dirWork          = workingdir;
            if (contractDb == null)
            {
                MessageBox.Show("Loi ket noi den database");
                this.Close();
            }
            sqlStr = "SELECT [MaKH] FROM [KHACHHANG] ORDER BY [MaKH]";
            try
            {
                oleReader = contractDb.genDataReader(sqlStr);
                while (oleReader.Read())
                {
                    cbxMaKH.Items.Add(oleReader[0].ToString());
                }
                cbxMaKH.Text = cbxMaKH.Items[0].ToString();
                sqlStr       = "SELECT [LaiSuat], [LoaiLS] FROM [LAISUAT]";
                oleReader    = contractDb.genDataReader(sqlStr);
                LSChovay     = new ArrayList();
                LSHuydong    = new ArrayList();
                while (oleReader.Read())
                {
                    if (oleReader["LoaiLS"].ToString() == "1")
                    {
                        LSChovay.Add(oleReader["LaiSuat"].ToString());
                        cbxLaisuat.Items.Add(oleReader["LaiSuat"].ToString());
                    }
                    else
                    {
                        LSHuydong.Add(oleReader["LaiSuat"].ToString());
                    }
                }
                Create_List_CT();
                return(true);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                contractDb.close();
                this.Close();
                return(false);
            }
        }
 public Boolean init(string dbname, string workingdir)
 {
     string sqlStr;
     OleDbDataReader oleReader;
     contractDb = new db(dbname);
     edit = false;
     laisuat = 0;
     MaHD = "";
     HTTra = TraDinhKy;
     optTraDK.Checked = true;
     dbfile = dbname;
     frmNhapTN = new NhapKyTraNo();
     frmNhapTN.saved = false;
     dirWork = workingdir;
     if (contractDb == null)
     {
         MessageBox.Show("Loi ket noi den database");
         this.Close();
     }
     sqlStr = "SELECT [MaKH] FROM [KHACHHANG] ORDER BY [MaKH]";
     try
     {
         oleReader = contractDb.genDataReader(sqlStr);
         while (oleReader.Read())
         {
             cbxMaKH.Items.Add(oleReader[0].ToString());
         }
         cbxMaKH.Text = cbxMaKH.Items[0].ToString();
         sqlStr = "SELECT [LaiSuat], [LoaiLS] FROM [LAISUAT]";
         oleReader = contractDb.genDataReader(sqlStr);
         LSChovay = new ArrayList();
         LSHuydong = new ArrayList();
         while (oleReader.Read())
         {
             if (oleReader["LoaiLS"].ToString() == "1")
             {
                 LSChovay.Add(oleReader["LaiSuat"].ToString());
                 cbxLaisuat.Items.Add(oleReader["LaiSuat"].ToString());
             }
             else LSHuydong.Add(oleReader["LaiSuat"].ToString());
         }
         Create_List_CT();
         return true;
     }
     catch (Exception ex)
     {
         //MessageBox.Show(ex.Message);
         contractDb.close();
         this.Close();
         return false;
     }
 }
 public void init(string dbName)
 {
     string sqlStr;
     string matien, sotien;
     OleDbDataReader oleReader;
     CashDB = new db(dbName);
     sqlStr = "SELECT [Matien], [SoLuong] FROM [Tien]";
     oleReader = CashDB.genDataReader(sqlStr);
     if (oleReader == null)
         return;
     try
     {
         while (oleReader.Read())
         {
             matien = oleReader["Matien"].ToString();
             sotien = oleReader["SoLuong"].ToString();
             if (matien == "TienVon")
                 txtTienvon.Text = sotien;
             else if (matien == "Tienlai")
                 txtLai.Text = sotien;
             else txtTienmat.Text = sotien;
         }
         voncu = Int64.Parse(txtTienvon.Text);
     }
     catch (Exception ex)
     {
         //MessageBox.Show(ex.Message);
         return;
     }
 }
        //True is corporate finance
        //false is individual finance
        private Boolean check_loai_KH(int MaLoaiKH)
        {
            string          sqlStr = "SELECT [TenLoaiKH] FROM [LoaiKH] WHERE ";
            OleDbDataReader oleReader;

            sqlStr = sqlStr + "[MaLoaiKH] =" + MaLoaiKH;
            string tenloaiKH;

            try
            {
                oleReader = CusDb.genDataReader(sqlStr);
                if (oleReader == null)
                {
                    return(false);
                }
                if (oleReader.Read())
                {
                    tenloaiKH = oleReader.GetValue(0).ToString();
                    if (tenloaiKH == "Khach hang doanh nghiep")
                    {
                        return(true);
                    }
                    return(false);
                }
                return(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
        }
 public void init(string dbfile, string Wdir, Boolean edit)
 {
     string sqlStr;
     OleDbDataReader oleReader;
     lstMaKH = new ArrayList();
     dbname = dbfile;
     ContractDB = new db(dbfile);
     workingdir = Wdir;
     sqlStr = "SELECT [MaHD], [MaKH], FORMAT([NgayHD], 'dd/mm/yyyy') AS NgayHD, [Tongtien], [Real], [Hoanthanh], [NoQH], [Laisuat]/100 AS LaiSuat, [Desc] FROM [HOPDONG] ORDER BY [MaHD]";
     FillDG(sqlStr);
     dtGridContracts.AllowUserToAddRows = false;
     sqlStr = "SELECT [MaKH], [TenKH] FROM [KHACHHANG]";
     oleReader = ContractDB.genDataReader(sqlStr);
     if (oleReader == null)
     {
         MessageBox.Show("Loi ket noi den database");
         return;
     }
     while (oleReader.Read())
     {
         cbxCusName.Items.Add(oleReader["TenKH"]);
         lstMaKH.Add(oleReader["MaKH"]);
     }
     cbxCusName.Items.Add("All");
     cbxCusName.Text = "All";
     nhapdulieu = edit;
     if (nhapdulieu == false)
         cmdAdd.Enabled = false;
     else cmdAdd.Enabled = true;
     chk_Denhan();
     //ShowDialog()
 }
示例#6
0
        private void chk_Denhan()
        {
            string          today = DateTime.Today.ToShortDateString();
            OleDbDataReader oleReader;
            ArrayList       ListMaHD = new ArrayList();
            int             i, index;
            string          sqlStr = "SELECT DISTINCT [MaHD] FROM [TIENLAI] WHERE FORMAT([Ngaytra], 'dd/mm/yyyy') = '" + today + "' AND [Datra] = No";

            try
            {
                oleReader = ContractDB.genDataReader(sqlStr);
                while (oleReader.Read())
                {
                    ListMaHD.Add(oleReader[0].ToString());
                }
                for (i = 0; i < dtGridContracts.Rows.Count; i++)
                {
                    index = ListMaHD.IndexOf(dtGridContracts.Rows[i].Cells["MaHD"].Value.ToString());
                    if (index >= 0)
                    {
                        dtGridContracts.Rows[i].DefaultCellStyle.BackColor = Color.Red;
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
 /*
  * Init function using to create object db for Quanlykhachhang
  * And this function is using to import list custommer from database to form
  */
 public void init(string dbFile)
 {
     string sqlString;
     OleDbDataReader oleReader;
     string LoaiKH;
     int MaLoaiKH, i;
     DataGridViewButtonColumn dtGridBt = new DataGridViewButtonColumn();
     LoaiKHList = new ArrayList();
     QlkhDb = new db(dbFile);
     dbname = dbFile;
     sqlString = "SELECT [MaLoaiKH], [TenLoaiKH] FROM [LOAIKH]";
     dtGridKH.AllowUserToAddRows = true;
     try
     {
         oleReader = QlkhDb.genDataReader(sqlString);
         if (oleReader == null)
         {
             MessageBox.Show("Loi ket noi den database!");
             this.Close();
             return;
         }
         while(oleReader.Read())
         {
             MaLoaiKH = int.Parse(oleReader.GetValue(0).ToString());
             LoaiKH = oleReader.GetString(1);
             cbxLoaiKH.Items.Add(LoaiKH);
             LoaiKHList.Add(MaLoaiKH);
         }
         cbxLoaiKH.Items.Add("All");
         cbxLoaiKH.Text = cbxLoaiKH.Items[0].ToString();
         sqlString = "SELECT [MAKH], [TenKH], [TaikhoanNH], [TenNH], [DinhDanh],[SoDT], [Diachi] FROM [KHACHHANG]";
         QlkhDb.fillDtGridView(sqlString, dtGridKH);
         for (i =0; i < dtGridKH.Columns.Count; i++)
         {
             dtGridKH.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
         }
         for (i = 0; i < dtGridKH.Rows.Count; i++)
         {
             if (rowColor)
                 dtGridKH.Rows[i].DefaultCellStyle.BackColor = activeC;
             else dtGridKH.Rows[i].DefaultCellStyle.BackColor = NegativeC;
             rowColor = !rowColor;
         }
         dtGridBt.Text = "...";
         dtGridBt.Name = "Capnhat";
         dtGridBt.Width = 60;
         dtGridBt.HeaderText = "Cap nhat";
         dtGridBt.UseColumnTextForButtonValue = true;
         dtGridKH.Columns.Add(dtGridBt);
         dtGridKH.AllowUserToAddRows = false;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         QlkhDb.close();
         this.Close();
     }
 }
        private void Create_List_CT()
        {
            string          sqlStr;
            OleDbDataReader oleReader;

            sqlStr        = "SELECT [MaHD] FROM [HOPDONG]";
            oleReader     = contractDb.genDataReader(sqlStr);
            ListContracts = new ArrayList();
            if (oleReader == null)
            {
                this.Close();
                return;
            }
            while (oleReader.Read())
            {
                ListContracts.Add(oleReader[0].ToString());
            }
        }
 public void init(string dbname, string cusId)
 {
     string sqlStr;
     OleDbDataReader oleReader;
     string tenKH, dinhdanh, ngaycap, noicap, SoDT, Diachi, TKNH, TenNH, MaLoaiKH;
     CusDb = new db(dbname);
     txtCusCode.Text = cusId;
     txtCusCode.Enabled = false;
     sqlStr = "SELECT [TenKH], [DinhDanh], [Ngaycap], [Noicap], [SoDT], [Diachi], [TaikhoanNH], [TenNH], [MaLoaiKH]";
     sqlStr = sqlStr + "FROM [KHACHHANG] WHERE [MaKH] ='" + cusId + "'";
     oleReader = CusDb.genDataReader(sqlStr);
     if (oleReader == null)
         return;
     if (oleReader.Read())
     {
         tenKH = oleReader["TenKH"].ToString();
         dinhdanh = oleReader["DinhDanh"].ToString();
         ngaycap = oleReader["Ngaycap"].ToString();
         noicap = oleReader["Noicap"].ToString();
         SoDT = oleReader["SoDT"].ToString();
         Diachi = oleReader["Diachi"].ToString();
         TKNH = oleReader["TaikhoanNH"].ToString();
         TenNH = oleReader["TenNH"].ToString();
         MaLoaiKH = oleReader["MaLoaiKH"].ToString();
         if (tenKH.Length > 0)
             this.txtCusName.Text = tenKH;
         if (dinhdanh.Length > 0)
             txtIdentCardNum.Text = dinhdanh;
         if (ngaycap.Length > 0)
             txtIssDate.Text = ngaycap;
         if (noicap.Length > 0)
             txtIssPlace.Text = noicap;
         if (SoDT.Length > 0)
             txtPhoneNum.Text = SoDT;
         if (Diachi.Length > 0)
             txtAddress.Text = Diachi;
         if (TKNH.Length > 0)
             txtAccount.Text = TKNH;
         if (tenKH.Length > 0)
             txtBank.Text = TenNH;
         if (check_loai_KH(int.Parse(MaLoaiKH)))
         {
             chkPhanloai.Checked = false;                //Khach hang doanh nghiep
             lblIdenti.Text = "So DKKD";
         }
         else                //Khach hang ca nhan
         {
             chkPhanloai.Checked = true;
             lblIdenti.Text = "So CMT";
         }
         this.Text = "Chinh sua thong tin nguoi dung";
         newuser = false;
     }
 }
示例#10
0
        /*
         * Init function using to create object db for Quanlykhachhang
         * And this function is using to import list custommer from database to form
         */
        public void init(string dbFile, string dbuser, int dbport)
        {
            string          sqlString;
            OleDbDataReader oleReader;
            string          LoaiKH;
            int             MaLoaiKH, i;

            LoaiKHList = new ArrayList();
            QlkhDb     = new db(dbFile, dbuser, dbport);
            sqlString  = "SELECT [MaLoaiKH], [LoaiKH] FROM [LOAIKH]";

            try
            {
                oleReader = QlkhDb.genDataReader(sqlString);
                if (oleReader == null)
                {
                    MessageBox.Show("Loi ket noi den database!");
                    this.Close();
                }
                while (oleReader.Read())
                {
                    MaLoaiKH = int.Parse(oleReader.GetValue(0).ToString());
                    LoaiKH   = oleReader.GetString(1);
                    cbxLoaiKH.Items.Add(LoaiKH);
                    LoaiKHList.Add(MaLoaiKH);
                }
                cbxLoaiKH.Items.Add("All");
                cbxLoaiKH.Text = cbxLoaiKH.Items[0].ToString();
                sqlString      = "SELECT [MAKH], [TenKH], [DinhDanh],[SoDT], [Diachi] FROM [KHACHHANG]";
                QlkhDb.fillDtGridView(sqlString, dtGridKH);
                for (i = 0; i < dtGridKH.Rows.Count; i++)
                {
                    if (rowColor)
                    {
                        dtGridKH.Rows[i].DefaultCellStyle.BackColor = activeC;
                    }
                    else
                    {
                        dtGridKH.Rows[i].DefaultCellStyle.BackColor = NegativeC;
                    }
                    rowColor = !rowColor;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.Close();
            }
        }
 public void init(string dbfile)
 {
     string sqlString, user;
     OleDbDataReader oleReader;
     useridlist = new ArrayList();
     dbFileName = dbfile;
     roledb = new db(dbFileName);
     sqlString = "SELECT DISTINCT UserName FROM [UserRole] WHERE RoleID <> 8";
     oleReader = roledb.genDataReader(sqlString);
     while (oleReader.Read())
     {
         user = oleReader.GetString(0);
         cbxUserName.Items.Add(user);
     }
     oleReader.Close();
     cbxUserName.Text = cbxUserName.Items[0].ToString();
 }
示例#12
0
        public void init(string dbfile)
        {
            string          sqlString, user;
            OleDbDataReader oleReader;

            useridlist = new ArrayList();
            dbFileName = dbfile;
            roledb     = new db(dbFileName);
            sqlString  = "SELECT DISTINCT UserName FROM [UserRole] WHERE RoleID <> 8";
            oleReader  = roledb.genDataReader(sqlString);
            while (oleReader.Read())
            {
                user = oleReader.GetString(0);
                cbxUserName.Items.Add(user);
            }
            oleReader.Close();
            cbxUserName.Text = cbxUserName.Items[0].ToString();
        }
        /*
         * Init function using to create object db for Quanlykhachhang
         * And this function is using to import list custommer from database to form
         */
        public void init(string dbFile, string dbuser, int dbport)
        {
            string sqlString;
            OleDbDataReader oleReader;
            string LoaiKH;
            int MaLoaiKH, i;
            LoaiKHList = new ArrayList();
            QlkhDb = new db(dbFile, dbuser, dbport);
            sqlString = "SELECT [MaLoaiKH], [LoaiKH] FROM [LOAIKH]";

            try
            {
                oleReader = QlkhDb.genDataReader(sqlString);
                if (oleReader == null)
                {
                    MessageBox.Show("Loi ket noi den database!");
                    this.Close();
                }
                while(oleReader.Read())
                {
                    MaLoaiKH = int.Parse(oleReader.GetValue(0).ToString());
                    LoaiKH = oleReader.GetString(1);
                    cbxLoaiKH.Items.Add(LoaiKH);
                    LoaiKHList.Add(MaLoaiKH);
                }
                cbxLoaiKH.Items.Add("All");
                cbxLoaiKH.Text = cbxLoaiKH.Items[0].ToString();
                sqlString = "SELECT [MAKH], [TenKH], [DinhDanh],[SoDT], [Diachi] FROM [KHACHHANG]";
                QlkhDb.fillDtGridView(sqlString, dtGridKH);
                for (i = 0; i < dtGridKH.Rows.Count; i++)
                {
                    if (rowColor)
                        dtGridKH.Rows[i].DefaultCellStyle.BackColor = activeC;
                    else dtGridKH.Rows[i].DefaultCellStyle.BackColor = NegativeC;
                    rowColor = !rowColor;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.Close();
            }
        }
示例#14
0
        private void cmdLogin_Click(object sender, EventArgs e)
        {
            string          sqlString;
            string          frmPass, dbPass;
            OleDbDataReader userReader;

            sqlString = "SELECT Password FROM QUANLYUSER ";
            if (txtUserName.Text == "" || txtPass.Text == "")
            {
                MessageBox.Show("Ban phai nhap user name va password");
                return;
            }
            byte[] d = Encoding.Unicode.GetBytes(txtPass.Text);
            frmPass    = System.Convert.ToBase64String(d);
            sqlString  = sqlString + "WHERE UserName = '******' AND [Locked] = false";
            userReader = hdbhData.genDataReader(sqlString);
            if (userReader.Read())
            {
                dbPass = userReader.GetString(0);
                if (dbPass != frmPass)
                {
                    if (count < 3)
                    {
                        count++;
                        MessageBox.Show("Ten dang nhap hoac mat khau khong hop le");
                        return;
                    }
                    else
                    {
                        logined = false;
                        this.Close();
                    }
                }
                else
                {
                    user = txtUserName.Text;
                    this.Close();
                }
            }
            this.Close();
            logined = true;
        }
示例#15
0
        private Boolean checkoldpass(string oldpass)
        {
            string          sqlString;
            string          datapass;
            OleDbDataReader OleReader;

            byte[] d = Encoding.Unicode.GetBytes(oldpass);
            datapass  = System.Convert.ToBase64String(d);
            sqlString = "SELECT * FROM QUANLYUSER WHERE [Username] = '" + username + "' AND";
            sqlString = sqlString + " [password] = '" + datapass + "'";
            OleReader = pwddb.genDataReader(sqlString);
            if ((OleReader != null) && (OleReader.Read()))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void init(string dbName)
        {
            string          sqlStr;
            string          matien, sotien;
            OleDbDataReader oleReader;

            CashDB    = new db(dbName);
            sqlStr    = "SELECT [Matien], [SoLuong] FROM [Tien]";
            oleReader = CashDB.genDataReader(sqlStr);
            if (oleReader == null)
            {
                return;
            }
            try
            {
                while (oleReader.Read())
                {
                    matien = oleReader["Matien"].ToString();
                    sotien = oleReader["SoLuong"].ToString();
                    if (matien == "TienVon")
                    {
                        txtTienvon.Text = sotien;
                    }
                    else if (matien == "Tienlai")
                    {
                        txtLai.Text = sotien;
                    }
                    else
                    {
                        txtTienmat.Text = sotien;
                    }
                }
                voncu = Int64.Parse(txtTienvon.Text);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                return;
            }
        }
示例#17
0
        private void MainPoint_Load(object sender, EventArgs e)
        {
            string          sqlString;
            OleDbDataReader oleReader;

            config();
            userdb    = new db(dbFileName);
            sqlString = "SELECT * FROM QUANLYUSER WHERE [Username] = 'admin'";
            oleReader = userdb.genDataReader(sqlString);
            if (oleReader == null)
            {
                this.Close();
                Application.Exit();
                return;
            }
            if (!oleReader.Read())
            {
                CreateUser frmCreateUser = new CreateUser();
                frmCreateUser.Text = "Khoi tao user admin cho he thong";
                frmCreateUser.init(dbFileName, true);
                frmCreateUser.ShowDialog();
                if (frmCreateUser.created == false)
                {
                    this.Close();
                }
                return;
            }
            Login frmLogin = new Login();

            frmLogin.init(dbFileName);
            frmLogin.ShowDialog();
            if (frmLogin.logined == false)
            {
                this.Close();
            }
            username = frmLogin.user;
            check_role(username);
//            userdb.Batch_Process();
        }
示例#18
0
        public void init(string dbfile, string Wdir, Boolean edit)
        {
            string          sqlStr;
            OleDbDataReader oleReader;

            lstMaKH    = new ArrayList();
            dbname     = dbfile;
            ContractDB = new db(dbfile);
            workingdir = Wdir;
            sqlStr     = "SELECT [MaHD], [MaKH], FORMAT([NgayHD], 'dd/mm/yyyy') AS NgayHD, [Tongtien], [Real], [Hoanthanh], [NoQH], [Laisuat]/100 AS LaiSuat, [Desc] FROM [HOPDONG] ORDER BY [MaHD]";
            FillDG(sqlStr);
            dtGridContracts.AllowUserToAddRows = false;
            sqlStr    = "SELECT [MaKH], [TenKH] FROM [KHACHHANG]";
            oleReader = ContractDB.genDataReader(sqlStr);
            if (oleReader == null)
            {
                MessageBox.Show("Loi ket noi den database");
                return;
            }
            while (oleReader.Read())
            {
                cbxCusName.Items.Add(oleReader["TenKH"]);
                lstMaKH.Add(oleReader["MaKH"]);
            }
            cbxCusName.Items.Add("All");
            cbxCusName.Text = "All";
            nhapdulieu      = edit;
            if (nhapdulieu == false)
            {
                cmdAdd.Enabled = false;
            }
            else
            {
                cmdAdd.Enabled = true;
            }
            chk_Denhan();
            //ShowDialog()
        }
示例#19
0
        private void Tinhlailai()
        {
            string          sqlStr;
            Int64           ngaychiulai, laicu, laimoi;
            Int64           tienchiulai, sotienlai;
            OleDbDataReader oleReader;
            int             rows;

            sqlStr    = "SELECT [MaDT], [Sotienlai], Format([NgayTra], 'dd/mm/yyyy') AS Ngaytra, [Tienchiulai], [Laisuat] FROM [TIENLAI] WHERE";
            sqlStr    = sqlStr + "[MaHD] = '" + txtMaHD.Text + "' AND [Datra] = No AND [NoQH] = 0 AND[Laisuat] > -1";
            oleReader = CashDB.genDataReader(sqlStr);
            if (oleReader == null)
            {
                this.Close();
            }
            rows   = 0;
            laimoi = laisuat;
            while (oleReader.Read())
            {
                dtGridCF.Rows.Add();
                dtGridLaicu.Rows.Add();
                dtGridCF.Rows[rows].Cells["MaDongTien"].Value   = oleReader["MaDT"].ToString();
                dtGridCF.Rows[rows].Cells["Ngaytra"].Value      = oleReader["NgayTra"].ToString();
                dtGridLaicu.Rows[rows].Cells["MaDT"].Value      = oleReader["MaDT"].ToString();
                dtGridLaicu.Rows[rows].Cells["Ngaytrano"].Value = oleReader["NgayTra"].ToString();
                laicu       = Int64.Parse(oleReader["Laisuat"].ToString());
                tienchiulai = Int64.Parse(oleReader["Tienchiulai"].ToString());
                dtGridLaicu.Rows[rows].Cells["Dunogoc"].Value = tienchiulai.ToString();
                sotienlai = Int64.Parse(oleReader["Sotienlai"].ToString());
                dtGridLaicu.Rows[rows].Cells["Laicu"].Value = sotienlai.ToString();
                ngaychiulai = (int)Math.Round(((decimal)((sotienlai * 360 * 100 * 100))) / (tienchiulai * laicu));
                sotienlai   = (tienchiulai * laimoi * ngaychiulai) / (360 * 100 * 100);
                dtGridCF.Rows[rows].Cells["Duno"].Value    = tienchiulai;
                dtGridCF.Rows[rows].Cells["Tienlai"].Value = sotienlai;
                rows++;
            }
        }
 private void MainPoint_Load(object sender, EventArgs e)
 {
     string sqlString;
     OleDbDataReader oleReader;
     config();
     userdb = new db(dbFileName, dbuser, dbport);
     sqlString = "SELECT * FROM QUANLYUSER";
     oleReader = userdb.genDataReader(sqlString);
     if (oleReader == null)
     {
         this.Close();
         Application.Exit();
         return;
     }
     if (!oleReader.Read())
     {
         CreateUser frmCreateUser = new CreateUser();
         frmCreateUser.Text = "Khoi tao user admin cho he thong";
         frmCreateUser.init(dbFileName, dbuser, dbport, true);
         frmCreateUser.ShowDialog();
         if (frmCreateUser.created == false)
             this.Close();
         return;
     }
     Login frmLogin = new Login();
     frmLogin.init(dbFileName, dbuser, dbport);
     frmLogin.ShowDialog();
     if (frmLogin.logined == false)
         this.Close();
     username = frmLogin.user;
     check_role(username);
 }
        public void init(string dbname, string maHD, string workingdir)
        {
            string          sqlStr;
            OleDbDataReader oleReader;

            contractDb = new db(dbname);
            Int64 tongtien = 0;
            int   i;

            MaHD                     = maHD;
            edit                     = true;
            dbfile                   = dbname;
            txtMaHD.Text             = maHD;
            txtMaHD.Enabled          = false;
            cmdKytraShow.Enabled     = false;
            frmNhapTN                = new NhapKyTraNo(dbname);
            frmNhapTN.saved          = false;
            cmdViewContracts.Enabled = true;
            cmdViewContracts.Visible = true;
            dirWork                  = workingdir;
            if (contractDb == null)
            {
                MessageBox.Show("Loi ket noi den database");
                this.Close();
            }

            sqlStr    = "SELECT [MaKH] FROM [KHACHHANG] ORDER BY [MaKH]";
            oleReader = contractDb.genDataReader(sqlStr);
            while (oleReader.Read())
            {
                cbxMaKH.Items.Add(oleReader[0].ToString());
            }

            sqlStr = "SELECT [MaKH], [NgayHD], [Tongtien], [Real], [Kyhan], [DonVT], [Laisuat], [Desc] FROM [HOPDONG]";
            sqlStr = sqlStr + " WHERE [MaHD] = '" + maHD + "'";
            try
            {
                oleReader = contractDb.genDataReader(sqlStr);
                while (oleReader.Read())
                {
                    cbxMaKH.Text             = oleReader["MaKH"].ToString();
                    cbxMaKH.Enabled          = false;
                    tongtien                 = Int64.Parse(oleReader["Tongtien"].ToString());
                    cbxKyhan.Text            = oleReader["Kyhan"].ToString();
                    cbxKyhan.Enabled         = false;
                    cbxDonvitinh.Text        = oleReader["DonVT"].ToString();
                    cbxDonvitinh.Enabled     = false;
                    chkReal.Checked          = !(Boolean.Parse(oleReader["Real"].ToString()));
                    cbxDateContracts.Value   = DateTime.Parse(oleReader["NgayHD"].ToString());
                    cbxDateContracts.Enabled = false;
                    txtDesc.Text             = oleReader["Desc"].ToString();
                    laisuat         = int.Parse(oleReader["Laisuat"].ToString());
                    cbxLaisuat.Text = float.Parse(laisuat.ToString()) / 100 + "";
                    oldLS           = cbxLaisuat.Text;
//                    cbxLaisuat.Enabled = false;
                }
                if (chkReal.Checked == false)
                {
                    chkReal.Enabled = false;
                }
                if (tongtien > 0)
                {
                    cbxLoaiHD.Text   = cbxLoaiHD.Items[1].ToString();
                    txtTongtien.Text = tongtien.ToString();
                }
                else
                {
                    cbxLoaiHD.Text   = cbxLoaiHD.Items[0].ToString();
                    tongtien         = Math.Abs(tongtien);
                    txtTongtien.Text = tongtien.ToString();
                }
                txtTongtien.Enabled = false;
                cbxLoaiHD.Enabled   = false;
//                cbxMaKH.Text = cbxMaKH.Items[0].ToString();
                grBoxKytra.Enabled = false;
                sqlStr             = "SELECT [LaiSuat], [LoaiLS] FROM [LAISUAT]";
                oleReader          = contractDb.genDataReader(sqlStr);
                LSChovay           = new ArrayList();
                LSHuydong          = new ArrayList();
                while (oleReader.Read())
                {
                    if (oleReader["LoaiLS"].ToString() == "1")
                    {
                        LSChovay.Add(oleReader["LaiSuat"].ToString());
                        cbxLaisuat.Items.Add(oleReader["LaiSuat"].ToString());
                    }
                    else
                    {
                        LSHuydong.Add(oleReader["LaiSuat"].ToString());
                    }
                }
                Create_List_CT();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                contractDb.close();
                this.Close();
            }
        }
示例#22
0
        private Boolean FillDG()
        {
            string          sqlStrRG, sqlStrRL;
            string          sqlStrVL, sqlStrVG;
            ArrayList       tiengoc, tienlai;
            ArrayList       namtragoc, namtralai;
            int             i, j;
            OleDbDataReader oleReaderG, oleReaderL;
            Int64           tientragoc, tientralai;

            try
            {
                tiengoc   = new ArrayList();
                tienlai   = new ArrayList();
                namtragoc = new ArrayList();
                namtralai = new ArrayList();
                sqlStrVG  = "SELECT sum ([Sotien]) AS Tien, FORMAT([ngaytra], 'mm') AS Thang from [DONGTIEN] WHERE ([SOTIEN] > 0) AND (([NoQH] = 0) OR ([Datra] = Yes)) ";
                if (realdata)
                {
                    sqlStrVG = sqlStrVG + "AND (FORMAT([Ngaytra], 'yyyy') = '" + nam + "') AND ([Real] = Yes)GROUP BY FORMAT([Ngaytra], 'mm')";
                }
                else
                {
                    sqlStrVG = sqlStrVG + "AND (FORMAT([Ngaytra], 'yyyy') = '" + nam + "') GROUP BY FORMAT([Ngaytra], 'mm')";
                }
                sqlStrVL = "SELECT sum ([Sotienlai]) AS Tien, FORMAT([ngaytra], 'mm') AS Thang from [TIENLAI] WHERE [Sotienlai] > 0 AND (([NoQH] = 0) OR ([Datra] = Yes))";
                if (realdata)
                {
                    sqlStrVL = sqlStrVL + "  AND ((FORMAT([Ngaytra], 'yyyy') = '" + nam + "')) AND ([Real] = Yes) GROUP BY FORMAT([Ngaytra], 'mm')";
                }
                else
                {
                    sqlStrVL = sqlStrVL + "  AND ((FORMAT([Ngaytra], 'yyyy') = '" + nam + "')) GROUP BY FORMAT([Ngaytra], 'mm')";
                }
                oleReaderG = CashDB.genDataReader(sqlStrVG);
                oleReaderL = CashDB.genDataReader(sqlStrVL);
                if (oleReaderG == null || oleReaderL == null)
                {
                    return(false);
                }
                while (oleReaderG.Read())
                {
                    tiengoc.Add(oleReaderG["Tien"].ToString());
                    namtragoc.Add(oleReaderG["Thang"].ToString());
                }

                while (oleReaderL.Read())
                {
                    tienlai.Add(oleReaderL["Tien"].ToString());
                    namtralai.Add(oleReaderL["Thang"].ToString());
                }

                for (i = 0; i < tiengoc.Count; i++)
                {
                    tientragoc = Int64.Parse(tiengoc[i].ToString());
                    for (j = 0; j < tienlai.Count; j++)
                    {
                        if (namtralai[j].ToString() == namtragoc[i].ToString())
                        {
                            tientragoc = tientragoc + Int64.Parse(tienlai[j].ToString());
                        }
                    }
                    for (j = 0; j < dtGridCash.Rows.Count; j++)
                    {
                        if ((dtGridCash.Rows[j].Cells["Thang"].Value.ToString()) == namtragoc[i].ToString())
                        {
                            dtGridCash.Rows[j].Cells["Tienvao"].Value = tientragoc;
                        }
                    }
                }

                //Add to tienra column

                tiengoc   = new ArrayList();
                tienlai   = new ArrayList();
                namtragoc = new ArrayList();
                namtralai = new ArrayList();
                sqlStrRG  = "SELECT sum ([Sotien]) AS Tien, FORMAT([ngaytra], 'mm') AS Thang from [DONGTIEN] WHERE [SOTIEN] < 0 AND (([NoQH] = 0) OR ([Datra] = Yes))";
                if (realdata)
                {
                    sqlStrRG = sqlStrRG + " AND ((FORMAT([Ngaytra], 'yyyy') = '" + nam + "')) AND ([Real] = " + realdata.ToString() + ") GROUP BY FORMAT([Ngaytra], 'mm')";
                }
                else
                {
                    sqlStrRG = sqlStrRG + " AND ((FORMAT([Ngaytra], 'yyyy') = '" + nam + "')) GROUP BY FORMAT([Ngaytra], 'mm')";
                }
                sqlStrRL = "SELECT sum ([Sotienlai]) AS Tien, FORMAT([ngaytra], 'mm') AS Thang from [TIENLAI] WHERE [Sotienlai] < 0 AND (([NoQH] = 0) OR ([Datra] = Yes))";
                if (realdata)
                {
                    sqlStrRL = sqlStrRL + " AND ((FORMAT([Ngaytra], 'yyyy') = '" + nam + "')) AND ([Real] = " + realdata.ToString() + ")GROUP BY FORMAT([Ngaytra], 'mm')";
                }
                else
                {
                    sqlStrRL = sqlStrRL + " AND ((FORMAT([Ngaytra], 'yyyy') = '" + nam + "')) GROUP BY FORMAT([Ngaytra], 'mm')";
                }
                oleReaderG = CashDB.genDataReader(sqlStrRG);
                oleReaderL = CashDB.genDataReader(sqlStrRL);
                if (oleReaderG == null || oleReaderL == null)
                {
                    return(false);
                }
                while (oleReaderG.Read())
                {
                    tiengoc.Add(oleReaderG["Tien"].ToString());
                    namtragoc.Add(oleReaderG["Thang"].ToString());
                }

                while (oleReaderL.Read())
                {
                    tienlai.Add(oleReaderL["Tien"].ToString());
                    namtralai.Add(oleReaderL["Thang"].ToString());
                }

                for (i = 0; i < tiengoc.Count; i++)
                {
                    tientragoc = Int64.Parse(tiengoc[i].ToString());
                    for (j = 0; j < tienlai.Count; j++)
                    {
                        if (namtralai[j].ToString() == namtragoc[i].ToString())
                        {
                            tientragoc = tientragoc + Int64.Parse(tienlai[j].ToString());
                        }
                    }
                    for (j = 0; j < dtGridCash.Rows.Count; j++)
                    {
                        if ((dtGridCash.Rows[j].Cells["Thang"].Value.ToString()) == namtragoc[i].ToString())
                        {
                            dtGridCash.Rows[j].Cells["Tienra"].Value = Math.Abs(tientragoc);
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
示例#23
0
        /*
         * Init function using to create object db for Quanlykhachhang
         * And this function is using to import list custommer from database to form
         */
        public void init(string dbFile)
        {
            string                   sqlString;
            OleDbDataReader          oleReader;
            string                   LoaiKH;
            int                      MaLoaiKH, i;
            DataGridViewButtonColumn dtGridBt = new DataGridViewButtonColumn();

            LoaiKHList = new ArrayList();
            QlkhDb     = new db(dbFile);
            dbname     = dbFile;
            sqlString  = "SELECT [MaLoaiKH], [TenLoaiKH] FROM [LOAIKH]";
            dtGridKH.AllowUserToAddRows = true;
            try
            {
                oleReader = QlkhDb.genDataReader(sqlString);
                if (oleReader == null)
                {
                    MessageBox.Show("Loi ket noi den database!");
                    this.Close();
                    return;
                }
                while (oleReader.Read())
                {
                    MaLoaiKH = int.Parse(oleReader.GetValue(0).ToString());
                    LoaiKH   = oleReader.GetString(1);
                    cbxLoaiKH.Items.Add(LoaiKH);
                    LoaiKHList.Add(MaLoaiKH);
                }
                cbxLoaiKH.Items.Add("All");
                cbxLoaiKH.Text = cbxLoaiKH.Items[0].ToString();
                sqlString      = "SELECT [MAKH], [TenKH], [TaikhoanNH], [TenNH], [DinhDanh],[SoDT], [Diachi] FROM [KHACHHANG]";
                QlkhDb.fillDtGridView(sqlString, dtGridKH);
                for (i = 0; i < dtGridKH.Columns.Count; i++)
                {
                    dtGridKH.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                }
                for (i = 0; i < dtGridKH.Rows.Count; i++)
                {
                    if (rowColor)
                    {
                        dtGridKH.Rows[i].DefaultCellStyle.BackColor = activeC;
                    }
                    else
                    {
                        dtGridKH.Rows[i].DefaultCellStyle.BackColor = NegativeC;
                    }
                    rowColor = !rowColor;
                }
                dtGridBt.Text       = "...";
                dtGridBt.Name       = "Capnhat";
                dtGridBt.Width      = 60;
                dtGridBt.HeaderText = "Cap nhat";
                dtGridBt.UseColumnTextForButtonValue = true;
                dtGridKH.Columns.Add(dtGridBt);
                dtGridKH.AllowUserToAddRows = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                QlkhDb.close();
                this.Close();
            }
        }
        public void init(string dbname, string cusId)
        {
            string          sqlStr;
            OleDbDataReader oleReader;
            string          tenKH, dinhdanh, ngaycap, noicap, SoDT, Diachi, TKNH, TenNH, MaLoaiKH;

            CusDb              = new db(dbname);
            txtCusCode.Text    = cusId;
            txtCusCode.Enabled = false;
            sqlStr             = "SELECT [TenKH], [DinhDanh], [Ngaycap], [Noicap], [SoDT], [Diachi], [TaikhoanNH], [TenNH], [MaLoaiKH]";
            sqlStr             = sqlStr + "FROM [KHACHHANG] WHERE [MaKH] ='" + cusId + "'";
            oleReader          = CusDb.genDataReader(sqlStr);
            if (oleReader == null)
            {
                return;
            }
            if (oleReader.Read())
            {
                tenKH    = oleReader["TenKH"].ToString();
                dinhdanh = oleReader["DinhDanh"].ToString();
                ngaycap  = oleReader["Ngaycap"].ToString();
                noicap   = oleReader["Noicap"].ToString();
                SoDT     = oleReader["SoDT"].ToString();
                Diachi   = oleReader["Diachi"].ToString();
                TKNH     = oleReader["TaikhoanNH"].ToString();
                TenNH    = oleReader["TenNH"].ToString();
                MaLoaiKH = oleReader["MaLoaiKH"].ToString();
                if (tenKH.Length > 0)
                {
                    this.txtCusName.Text = tenKH;
                }
                if (dinhdanh.Length > 0)
                {
                    txtIdentCardNum.Text = dinhdanh;
                }
                if (ngaycap.Length > 0)
                {
                    txtIssDate.Text = ngaycap;
                }
                if (noicap.Length > 0)
                {
                    txtIssPlace.Text = noicap;
                }
                if (SoDT.Length > 0)
                {
                    txtPhoneNum.Text = SoDT;
                }
                if (Diachi.Length > 0)
                {
                    txtAddress.Text = Diachi;
                }
                if (TKNH.Length > 0)
                {
                    txtAccount.Text = TKNH;
                }
                if (tenKH.Length > 0)
                {
                    txtBank.Text = TenNH;
                }
                if (check_loai_KH(int.Parse(MaLoaiKH)))
                {
                    chkPhanloai.Checked = false;                //Khach hang doanh nghiep
                    lblIdenti.Text      = "So DKKD";
                }
                else                //Khach hang ca nhan
                {
                    chkPhanloai.Checked = true;
                    lblIdenti.Text      = "So CMT";
                }
                this.Text = "Chinh sua thong tin nguoi dung";
                newuser   = false;
            }
        }
示例#25
0
        private void check_role(string username)
        {
            string          sqlString;
            OleDbDataReader oleReader;
            Boolean         value;
            int             i;

            sqlString = "SELECT VALUE FROM UserRole WHERE [Username] = '" + username + "' AND";
            sqlString = sqlString + "[RoleID] = 8";
            oleReader = userdb.genDataReader(sqlString);
            if ((oleReader != null) && (oleReader.Read()))
            {
                value = oleReader.GetBoolean(0);
                if (value == true)
                {
                    this.nhapDuLieuToolStripMenuItem.Enabled      = true;
                    this.quanLyDongTienToolStripMenuItem.Enabled  = true;
                    this.quanLyHopDongToolStripMenuItem.Enabled   = true;
                    this.quanLyKhachHangToolStripMenuItem.Enabled = true;
                    this.quanLyVonToolStripMenuItem.Enabled       = true;
                    this.capthuHoiQuyenToolStripMenuItem.Enabled  = true;
                    this.quanLyNguoiDungToolStripMenuItem.Enabled = true;
                }
                else
                {
                    sqlString = "SELECT RoleID, Value FROM UserRole WHERE Username = '******' ORDER BY RoleID";
                    oleReader = userdb.genDataReader(sqlString);
                    this.capthuHoiQuyenToolStripMenuItem.Enabled = false;
                    if (oleReader == null)
                    {
                        this.Close();
                        Application.Exit();
                    }
                    while (oleReader.Read())
                    {
                        i     = oleReader.GetInt16(0);
                        value = oleReader.GetBoolean(1);
                        if (value == false)
                        {
                            if (i == 1)
                            {
                                //Khong duoc nhap thong tin hop dong va dong tien
                                this.nhapDuLieuToolStripMenuItem.Enabled = false;
                            }
                            else if (i == 3)
                            {
                                //Khong duoc them bot thong tin ve nguoi su dung he thong
                                this.quanLyNguoiDungToolStripMenuItem.Enabled = false;
                            }
                            else if (i == 4)
                            {
                                // Khong duoc xem thong tin khach hang va khong duoc sua doi thong tin khach hang
                                this.quanLyKhachHangToolStripMenuItem.Enabled = false;
                            }
                            else if (i == 5)
                            {
                                // Quan ly hop dong
                                this.quanLyHopDongToolStripMenuItem.Enabled = false;
                            }
                            else if (i == 6)
                            {
                                // Quan ly lai suat
                                this.quanLyVonToolStripMenuItem.Enabled = false;
                            }
                            else if (i == 7)
                            {
                                // Quan ly dong tien
                                this.quanLyDongTienToolStripMenuItem.Enabled = false;
                            }
                        }
                        else
                        {
                            if (i == 1)
                            {
                                //Duoc nhap thong tin hop dong va dong tien
                                this.nhapDuLieuToolStripMenuItem.Enabled = true;
                            }
                            else if (i == 3)
                            {
                                //Duoc them bot thong tin ve nguoi su dung he thong
                                this.quanLyNguoiDungToolStripMenuItem.Enabled = true;
                            }
                            else if (i == 4)
                            {
                                // Duoc xem thong tin khach hang va khong duoc sua doi thong tin khach hang
                                this.quanLyKhachHangToolStripMenuItem.Enabled = true;
                            }
                            else if (i == 5)
                            {
                                // Quan ly hop dong
                                this.quanLyHopDongToolStripMenuItem.Enabled = true;
                            }
                            else if (i == 6)
                            {
                                // Quan ly lai suat
                                this.quanLyVonToolStripMenuItem.Enabled = true;
                            }
                            else if (i == 7)
                            {
                                // Quan ly dong tien
                                this.quanLyDongTienToolStripMenuItem.Enabled = true;
                            }
                        }
                    }
                }
            }
            else
            {
                this.Close();
                Application.Exit();
            }
        }
        public void init(string dbname, string maHD, string workingdir)
        {
            string sqlStr;
            OleDbDataReader oleReader;
            contractDb = new db(dbname);
            Int64 tongtien = 0;
            int i;
            MaHD = maHD;
            edit = true;
            dbfile = dbname;
            txtMaHD.Text = maHD;
            txtMaHD.Enabled = false;
            cmdKytraShow.Enabled = false;
            frmNhapTN = new NhapKyTraNo(dbname);
            frmNhapTN.saved = false;
            cmdViewContracts.Enabled = true;
            cmdViewContracts.Visible = true;
            dirWork = workingdir;
            if (contractDb == null)
            {
                MessageBox.Show("Loi ket noi den database");
                this.Close();
            }

            sqlStr = "SELECT [MaKH] FROM [KHACHHANG] ORDER BY [MaKH]";
            oleReader = contractDb.genDataReader(sqlStr);
            while (oleReader.Read())
            {
                cbxMaKH.Items.Add(oleReader[0].ToString());
            }

            sqlStr = "SELECT [MaKH], [NgayHD], [Tongtien], [Real], [Kyhan], [DonVT], [Laisuat], [Desc] FROM [HOPDONG]";
            sqlStr = sqlStr + " WHERE [MaHD] = '" + maHD + "'";
            try
            {
                oleReader = contractDb.genDataReader(sqlStr);
                while (oleReader.Read())
                {
                    cbxMaKH.Text = oleReader["MaKH"].ToString();
                    cbxMaKH.Enabled = false;
                    tongtien = Int64.Parse(oleReader["Tongtien"].ToString());
                    cbxKyhan.Text = oleReader["Kyhan"].ToString();
                    cbxKyhan.Enabled = false;
                    cbxDonvitinh.Text = oleReader["DonVT"].ToString();
                    cbxDonvitinh.Enabled = false;
                    chkReal.Checked = !(Boolean.Parse(oleReader["Real"].ToString()));
                    cbxDateContracts.Value = DateTime.Parse(oleReader["NgayHD"].ToString());
                    cbxDateContracts.Enabled = false;
                    txtDesc.Text = oleReader["Desc"].ToString();
                    laisuat = int.Parse(oleReader["Laisuat"].ToString());
                    cbxLaisuat.Text = float.Parse(laisuat.ToString()) / 100 + "";
                    oldLS = cbxLaisuat.Text;
            //                    cbxLaisuat.Enabled = false;
                }
                if (chkReal.Checked == false)
                    chkReal.Enabled = false;
                if (tongtien > 0)
                {
                    cbxLoaiHD.Text = cbxLoaiHD.Items[1].ToString();
                    txtTongtien.Text = tongtien.ToString();
                }
                else
                {
                    cbxLoaiHD.Text = cbxLoaiHD.Items[0].ToString();
                    tongtien = Math.Abs(tongtien);
                    txtTongtien.Text = tongtien.ToString();
                }
                txtTongtien.Enabled = false;
                cbxLoaiHD.Enabled = false;
            //                cbxMaKH.Text = cbxMaKH.Items[0].ToString();
                grBoxKytra.Enabled = false;
                sqlStr = "SELECT [LaiSuat], [LoaiLS] FROM [LAISUAT]";
                oleReader = contractDb.genDataReader(sqlStr);
                LSChovay = new ArrayList();
                LSHuydong = new ArrayList();
                while (oleReader.Read())
                {
                    if (oleReader["LoaiLS"].ToString() == "1")
                    {
                        LSChovay.Add(oleReader["LaiSuat"].ToString());
                        cbxLaisuat.Items.Add(oleReader["LaiSuat"].ToString());
                    }
                    else LSHuydong.Add(oleReader["LaiSuat"].ToString());
                }
                Create_List_CT();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                contractDb.close();
                this.Close();
            }
        }
        public void init(string mahd, string dbname)
        {
            string sqlStrG, sqlStrL, sqlStr;
            string matien;
            OleDbDataReader oleReader;
            Mahd = mahd;
            int i;
            try
            {
                CashDB = new db(dbname);
                DatraG = new ArrayList();
                DatraL = new ArrayList();
                KytraG = new ArrayList();
                KytraL = new ArrayList();
                txtMaHD.Text = mahd;
                sqlStr = "SELECT [SoLuong], [MaTien] FROM [TIEN]";
                oleReader = CashDB.genDataReader(sqlStr);
                if (oleReader == null)
                    return;
                while (oleReader.Read())
                {
                    matien = oleReader["Matien"].ToString();
                    if (matien == "TongTien")
                        tienmat = Int64.Parse(oleReader["SoLuong"].ToString());
                    if (matien == "Tienlai") tienlai = Int64.Parse(oleReader["SoLuong"].ToString());
                }
                sqlStrG = "SELECT [MaDT], [Sotien], FORMAT([NgayTra], 'dd/mm/yyyy') AS Ngaytratien, [NoQH], [Datra], [Real] FROM [DONGTIEN] WHERE [MaHD] ='" + mahd + "'";
                sqlStrL = "SELECT [MaDT], [Sotienlai], FORMAT([NgayTra], 'dd/mm/yyyy') AS Ngaytratien, [NoQH], [Datra], [Real] FROM [TIENLAI] WHERE [MaHD] ='" + mahd + "'";
                FillDG(sqlStrG, ref dtGridCFG);
                FillDG(sqlStrL, ref dtGridCFL);

                if (dtGridCFL.Rows.Count == 0)
                    return;
                if (dtGridCFG.Rows.Count == 0)
                    return;
                dtGridCFL.Columns["MaDT"].ReadOnly = true;
                dtGridCFL.Columns["Sotienlai"].ReadOnly = true;
                dtGridCFL.Columns["Real"].ReadOnly = true;
                dtGridCFL.Columns["Ngaytratien"].ReadOnly = true;
                dtGridCFL.Columns["NoQH"].ReadOnly = true;

                dtGridCFG.Columns["MaDT"].ReadOnly = true;
                dtGridCFG.Columns["Sotien"].ReadOnly = true;
                dtGridCFG.Columns["Real"].ReadOnly = true;
                dtGridCFG.Columns["Ngaytratien"].ReadOnly = true;
                dtGridCFG.Columns["NoQH"].ReadOnly = true;

                for (i = 0; i < dtGridCFL.Rows.Count; i++)
                {
                    DateTime ngaytralai = DateTime.Parse(dtGridCFL.Rows[i].Cells["Ngaytratien"].Value.ToString());
                    TimeSpan difDay = ngaytralai.Subtract(DateTime.Today);
                    if ((dtGridCFL.Rows[i].Cells["Datra"].Value.ToString() == "True") || (difDay.Days > 0))
                    {
                        KytraL.Add("False");
                    }
                    else KytraL.Add("True");

                    if (dtGridCFL.Rows[i].Cells["Datra"].Value.ToString() == "True")
                        DatraL.Add("True");
                    else DatraL.Add("False");

                }

                for (i = 0; i < dtGridCFG.Rows.Count; i++)
                {
                    DateTime ngaytralai = DateTime.Parse(dtGridCFG.Rows[i].Cells["Ngaytratien"].Value.ToString());
                    TimeSpan difDay = ngaytralai.Subtract(DateTime.Today);
                    if ((dtGridCFG.Rows[i].Cells["Datra"].Value.ToString() == "True") || (difDay.Days > 0))
                    {
                        KytraG.Add("False");
                    }
                    else
                    {
                        KytraG.Add("True");
                    }

                    if (dtGridCFG.Rows[i].Cells["Datra"].Value.ToString() == "True")
                    {
                        DatraG.Add("True");
                    }
                    else DatraG.Add("False");
                }
                this.ShowDialog();
            }
            catch (Exception ex)
            {
                return;
            }
        }
示例#28
0
        public void init(string mahd, string dbname)
        {
            string          sqlStrG, sqlStrL, sqlStr;
            string          matien;
            OleDbDataReader oleReader;

            Mahd = mahd;
            int i;

            try
            {
                CashDB       = new db(dbname);
                DatraG       = new ArrayList();
                DatraL       = new ArrayList();
                KytraG       = new ArrayList();
                KytraL       = new ArrayList();
                txtMaHD.Text = mahd;
                sqlStr       = "SELECT [SoLuong], [MaTien] FROM [TIEN]";
                oleReader    = CashDB.genDataReader(sqlStr);
                if (oleReader == null)
                {
                    return;
                }
                while (oleReader.Read())
                {
                    matien = oleReader["Matien"].ToString();
                    if (matien == "TongTien")
                    {
                        tienmat = Int64.Parse(oleReader["SoLuong"].ToString());
                    }
                    if (matien == "Tienlai")
                    {
                        tienlai = Int64.Parse(oleReader["SoLuong"].ToString());
                    }
                }
                sqlStrG = "SELECT [MaDT], [Sotien], FORMAT([NgayTra], 'dd/mm/yyyy') AS Ngaytratien, [NoQH], [Datra], [Real] FROM [DONGTIEN] WHERE [MaHD] ='" + mahd + "'";
                sqlStrL = "SELECT [MaDT], [Sotienlai], FORMAT([NgayTra], 'dd/mm/yyyy') AS Ngaytratien, [NoQH], [Datra], [Real] FROM [TIENLAI] WHERE [MaHD] ='" + mahd + "'";
                FillDG(sqlStrG, ref dtGridCFG);
                FillDG(sqlStrL, ref dtGridCFL);

                if (dtGridCFL.Rows.Count == 0)
                {
                    return;
                }
                if (dtGridCFG.Rows.Count == 0)
                {
                    return;
                }
                dtGridCFL.Columns["MaDT"].ReadOnly        = true;
                dtGridCFL.Columns["Sotienlai"].ReadOnly   = true;
                dtGridCFL.Columns["Real"].ReadOnly        = true;
                dtGridCFL.Columns["Ngaytratien"].ReadOnly = true;
                dtGridCFL.Columns["NoQH"].ReadOnly        = true;

                dtGridCFG.Columns["MaDT"].ReadOnly        = true;
                dtGridCFG.Columns["Sotien"].ReadOnly      = true;
                dtGridCFG.Columns["Real"].ReadOnly        = true;
                dtGridCFG.Columns["Ngaytratien"].ReadOnly = true;
                dtGridCFG.Columns["NoQH"].ReadOnly        = true;

                for (i = 0; i < dtGridCFL.Rows.Count; i++)
                {
                    DateTime ngaytralai = DateTime.Parse(dtGridCFL.Rows[i].Cells["Ngaytratien"].Value.ToString());
                    TimeSpan difDay     = ngaytralai.Subtract(DateTime.Today);
                    if ((dtGridCFL.Rows[i].Cells["Datra"].Value.ToString() == "True") || (difDay.Days > 0))
                    {
                        KytraL.Add("False");
                    }
                    else
                    {
                        KytraL.Add("True");
                    }

                    if (dtGridCFL.Rows[i].Cells["Datra"].Value.ToString() == "True")
                    {
                        DatraL.Add("True");
                    }
                    else
                    {
                        DatraL.Add("False");
                    }
                }

                for (i = 0; i < dtGridCFG.Rows.Count; i++)
                {
                    DateTime ngaytralai = DateTime.Parse(dtGridCFG.Rows[i].Cells["Ngaytratien"].Value.ToString());
                    TimeSpan difDay     = ngaytralai.Subtract(DateTime.Today);
                    if ((dtGridCFG.Rows[i].Cells["Datra"].Value.ToString() == "True") || (difDay.Days > 0))
                    {
                        KytraG.Add("False");
                    }
                    else
                    {
                        KytraG.Add("True");
                    }

                    if (dtGridCFG.Rows[i].Cells["Datra"].Value.ToString() == "True")
                    {
                        DatraG.Add("True");
                    }
                    else
                    {
                        DatraG.Add("False");
                    }
                }
                this.ShowDialog();
            }
            catch (Exception ex)
            {
                return;
            }
        }