Ejemplo n.º 1
0
        public Home()
        {
            //init for client info
            username = MainForm.username;
            loginTime = MainForm.loginTime.ToShortTimeString();
            deviceCount = "0";

            try
            {
                UserInfoTableAdapter userInfoTA = new UserInfoTableAdapter();
                int? userCount_ = userInfoTA.GetCount();
                if (userCount_ == null)
                {
                    userCount_ = 0;
                }
                userCount = userCount_.Value.ToString();

                int? fingerPrintCount_ = (int?)userInfoTA.GetUsingFingerPrintCout();
                if (fingerPrintCount_ == null)
                {
                    fingerPrintCount_ = 0;
                }
                fingerPrintCount = fingerPrintCount_.Value.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Có lỗi khi tải dữu liệu.");
                Log.ErrorLog(ex.Message);
            }

            transactionCount = "0";
            transactionToServerCount = "0";

            InitializeComponent();

            ReloadClientInfo();

            afis = new AfisEngine();
            afis.Threshold = 25;

            fingerPrintDB = null;
            lastUpdatedFingerPrintDB = null;

            bwLoadFingerPrints = new BackgroundWorker();
            bwLoadFingerPrints.DoWork += new DoWorkEventHandler(bwLoadFingerPrints_DoWork);
            bwLoadFingerPrints.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bwLoadFingerPrints_RunWorkerCompleted);

            //invisible the HorizontalScroll
            this.flpnlDevices.HorizontalScroll.Maximum = 0;
            this.flpnlDevices.AutoScroll = false;
            this.flpnlDevices.VerticalScroll.Visible = false;
            this.flpnlDevices.AutoScroll = true;

            devices = new List<DeviceModel>();
            pnlDeviceList = new List<Panel>();
            usingMealSetList = new List<KeyValuePair<int, string>>();

            usingMealSetList.Add(new KeyValuePair<int, string>(0, "<<Không có>>"));
        }
Ejemplo n.º 2
0
        private static void Sync(string xmlPath)
        {
            XDocument xDoc;
            XElement newDataSetEl;
            DateTime lastSync;
            try
            {
                xDoc = XDocument.Load(xmlPath);
                newDataSetEl = xDoc.Element("NewDataSet");

                DateTime? lastSync_ = GetLastSync();
                if (lastSync_ == null)
                {
                    lastSync = new DateTime();
                }
                else
                {
                    lastSync = lastSync_.Value;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            UserTypeTableAdapter userTypeTA = new UserTypeTableAdapter();
            UserInfoTableAdapter userInfoTA = new UserInfoTableAdapter();
            MealSetTableAdapter mealSetTA = new MealSetTableAdapter();
            ServingTimeTableAdapter servingTimeTA = new ServingTimeTableAdapter();
            ScheduleTableAdapter scheduleTA = new ScheduleTableAdapter();
            ScheduleMealSetDetailTableAdapter scheduleMealSetDetailTA = new ScheduleMealSetDetailTableAdapter();
            TransactionTypeTableAdapter transactionTypeTA = new TransactionTypeTableAdapter();
            TransactionHistoryTableAdapter transactionHistoryTA = new TransactionHistoryTableAdapter();

            userTypeTA.Connection.Open();
            userInfoTA.Connection = userTypeTA.Connection;
            mealSetTA.Connection = userTypeTA.Connection;
            servingTimeTA.Connection = userTypeTA.Connection;
            scheduleTA.Connection = userTypeTA.Connection;
            scheduleMealSetDetailTA.Connection = userTypeTA.Connection;
            transactionTypeTA.Connection = userTypeTA.Connection;
            transactionHistoryTA.Connection = userTypeTA.Connection;

            using (SqlTransaction transaction = userTypeTA.Connection.BeginTransaction())
            {
                userTypeTA.AttachTransaction(transaction);
                userInfoTA.AttachTransaction(transaction);
                mealSetTA.AttachTransaction(transaction);
                servingTimeTA.AttachTransaction(transaction);
                scheduleTA.AttachTransaction(transaction);
                scheduleMealSetDetailTA.AttachTransaction(transaction);
                transactionTypeTA.AttachTransaction(transaction);
                transactionHistoryTA.AttachTransaction(transaction);

                try
                {
                    // sync usertype table
                    // NOTE: table UserType in subDB only get value from db in web app.
                    // so in the desktop app we only insert and update
                    IList<XElement> ElList = newDataSetEl.Descendants("UserType").ToList();

                    foreach (XElement userTypeEl in ElList)
                    {
                        // not null value parse
                        string typeShortName = userTypeEl.Element("TypeShortName").Value;
                        string typeName = userTypeEl.Element("TypeName").Value;
                        int mealValue = int.Parse(userTypeEl.Element("MealValue").Value);
                        bool canEatMore = bool.Parse(userTypeEl.Element("CanEatMore").Value);
                        DateTime insertedDate = DateTime.Parse(userTypeEl.Element("InsertedDate").Value);
                        DateTime lastUpdated = DateTime.Parse(userTypeEl.Element("LastUpdated").Value);
                        bool canDebt = bool.Parse(userTypeEl.Element("CanDebt").Value);

                        // nullable value parse
                        int? moreMealValue;
                        if (userTypeEl.Element("MoreMealValue") == null)
                        {
                            moreMealValue = null;
                        }
                        else
                        {
                            moreMealValue = int.Parse(userTypeEl.Element("MoreMealValue").Value.ToString());
                        }

                        string description;
                        if (userTypeEl.Element("Description") == null)
                        {
                            description = null;
                        }
                        else
                        {
                            description = userTypeEl.Element("Description").Value;
                        }

                        string updatedBy;
                        if (userTypeEl.Element("UpdatedBy") == null)
                        {
                            updatedBy = null;
                        }
                        else
                        {
                            updatedBy = userTypeEl.Element("UpdatedBy").Value;
                        }

                        if (insertedDate > lastSync)
                        {
                            if ((int)userTypeTA.CheckDuplicateKey(typeShortName) == 0)
                            {
                                userTypeTA.Insert(typeShortName, typeName, mealValue, moreMealValue, description, canDebt, canEatMore, insertedDate, updatedBy, lastUpdated);
                                continue;
                            }
                        }

                        userTypeTA.Update(typeName, mealValue, moreMealValue, description, canDebt, canEatMore, insertedDate, updatedBy, lastUpdated, typeShortName);
                    }

                    // sync userinfo table
                    ElList = newDataSetEl.Descendants("UserInfo").ToList();

                    foreach (XElement userInfoEl in ElList)
                    {
                        // not null value parse
                        string username = userInfoEl.Element("Username").Value;
                        int amountOfMoney = int.Parse(userInfoEl.Element("AmountOfMoney").Value);
                        DateTime lastUpdatedMoney = DateTime.Parse(userInfoEl.Element("LastUpdatedMoney").Value);
                        bool isCafeteriaStaff = bool.Parse(userInfoEl.Element("IsCafeteriaStaff").Value);
                        bool isActive = bool.Parse(userInfoEl.Element("IsActive").Value);
                        DateTime insertedDate = DateTime.Parse(userInfoEl.Element("InsertedDate").Value);
                        DateTime lastUpdated = DateTime.Parse(userInfoEl.Element("LastUpdated").Value);

                        // nullable value parse
                        string name = userInfoEl.TryGetElementValue("Name");
                        string typeShortName = userInfoEl.TryGetElementValue("TypeShortName");
                        string updatedBy = userInfoEl.TryGetElementValue("UpdatedBy");

                        byte[] fingerPrintIMG;
                        if (userInfoEl.Element("FingerPrintIMG") == null)
                        {
                            fingerPrintIMG = null;
                        }
                        else
                        {
                            fingerPrintIMG = Convert.FromBase64String(userInfoEl.Element("FingerPrintIMG").Value);
                        }

                        DateTime? lastUpdatedFingerPrint;
                        if (userInfoEl.Element("LastUpdatedFingerPrint") == null)
                        {
                            lastUpdatedFingerPrint = null;
                        }
                        else
                        {
                            lastUpdatedFingerPrint = DateTime.Parse(userInfoEl.Element("LastUpdatedFingerPrint").Value);
                        }

                        int? fingerPosition;
                        if (userInfoEl.Element("FingerPosition") == null)
                        {
                            fingerPosition = null;
                        }
                        else
                        {
                            fingerPosition = int.Parse(userInfoEl.Element("FingerPosition").Value);
                        }

                        if (insertedDate > lastSync)
                        {
                            if ((int)userInfoTA.CheckDuplicateKey(username) == 0)
                            {
                                userInfoTA.Insert(username, name, typeShortName, amountOfMoney, lastUpdatedMoney, fingerPrintIMG
                                    , lastUpdatedFingerPrint, fingerPosition, isCafeteriaStaff, isActive, insertedDate
                                    , updatedBy, lastUpdated);
                                continue;
                            }
                        }

                        DataTable userInfoDT = userInfoTA.GetUserInfo(username);
                        if (userInfoDT.Rows.Count != 1)
                        {
                            throw new Exception("Comflic while Sync. The updated row doesn't exist.");
                        }
                        DataRow userInfoRow = userInfoDT.Rows[0];
                        DateTime oriLastUpdatedMoney = (DateTime)userInfoRow["LastUpdatedMoney"];
                        DateTime? oriLastUpdateFingerPrint = userInfoRow.Field<DateTime?>("LastUpdatedFingerPrint");

                        userInfoTA.UpdateGeneric(name, typeShortName, isCafeteriaStaff, isActive, insertedDate, updatedBy, lastUpdated, username);
                        if (oriLastUpdatedMoney > lastSync)
                        {
                            userInfoTA.UpdateMoney(amountOfMoney, lastUpdatedMoney, username);
                        }

                        if (oriLastUpdateFingerPrint == null || oriLastUpdateFingerPrint.Value > lastSync)
                        {
                            userInfoTA.UpdateFingerPrint(fingerPrintIMG, lastUpdatedFingerPrint, fingerPosition, username);
                        }
                    }

                    //sync mealset table
                    // NOTE: table MealSet in subDB only get value from db in web app.
                    // so in the desktop app we only insert and update
                    ElList = newDataSetEl.Descendants("MealSet").ToList();

                    foreach (XElement mealSetEl in ElList)
                    {
                        // not null value parse
                        int mealSetID = int.Parse(mealSetEl.Element("MealSetID").Value);
                        string name = mealSetEl.Element("Name").Value;
                        bool canEatMore = bool.Parse(mealSetEl.Element("CanEatMore").Value);
                        DateTime insertedDate = DateTime.Parse(mealSetEl.Element("InsertedDate").Value);
                        DateTime lastUpdated = DateTime.Parse(mealSetEl.Element("LastUpdated").Value);

                        // nullable value parse
                        string updatedBy = mealSetEl.TryGetElementValue("UpdatedBy");

                        if (insertedDate > lastSync)
                        {
                            mealSetTA.InsertWithID(mealSetID, name, canEatMore, insertedDate, updatedBy, lastUpdated);
                            continue;
                        }

                        mealSetTA.Update(name, canEatMore, insertedDate, updatedBy, lastUpdated, mealSetID);
                    }

                    // sync serving time table
                    // NOTE: table serving time in subDB only get value from db in web app.
                    // so in the desktop app we only insert and update
                    ElList = newDataSetEl.Descendants("ServingTime").ToList();

                    foreach (XElement servingTimeEl in ElList)
                    {
                        // not null value parse
                        int servingTimeID = int.Parse(servingTimeEl.Element("ServingTimeID").Value);
                        string name = servingTimeEl.Element("Name").Value;
                        string a = servingTimeEl.Element("StartTime").Value;
                        TimeSpan startTime = XmlConvert.ToTimeSpan(servingTimeEl.Element("StartTime").Value);
                        TimeSpan endTime = XmlConvert.ToTimeSpan(servingTimeEl.Element("EndTime").Value);
                        DateTime insertedDate = DateTime.Parse(servingTimeEl.Element("InsertedDate").Value);
                        DateTime lastUpdated = DateTime.Parse(servingTimeEl.Element("LastUpdated").Value);

                        // nullable value parse
                        if (insertedDate > lastSync)
                        {
                            servingTimeTA.InsertWithID(servingTimeID, name, startTime, endTime, insertedDate, lastUpdated);
                            continue;
                        }

                        servingTimeTA.Update(name, startTime, endTime, insertedDate, lastUpdated, servingTimeID);
                    }

                    // sync schedule table
                    ElList = newDataSetEl.Descendants("Schedule").ToList();

                    foreach (XElement scheduleEl in ElList)
                    {
                        // not null value parse
                        int scheduleID = int.Parse(scheduleEl.Element("ScheduleID").Value);
                        DateTime date = DateTime.Parse(scheduleEl.Element("Date").Value);
                        int servingTimeID = int.Parse(scheduleEl.Element("ServingTimeID").Value);
                        bool isDayOn = bool.Parse(scheduleEl.Element("IsDayOn").Value);
                        DateTime insertedDate = DateTime.Parse(scheduleEl.Element("InsertedDate").Value);
                        DateTime lastUpdated = DateTime.Parse(scheduleEl.Element("LastUpdated").Value);

                        // nullable value parse
                        string updatedBy = scheduleEl.TryGetElementValue("UpdatedBy");

                        if (insertedDate > lastSync)
                        {
                            scheduleTA.InsertWithID(scheduleID, servingTimeID, date, isDayOn, insertedDate, updatedBy, lastUpdated);
                            continue;
                        }

                        scheduleTA.Update(date, servingTimeID, isDayOn, insertedDate, updatedBy, lastUpdated, scheduleID);
                    }

                    // sync schedule meal set detail table
                    ElList = newDataSetEl.Descendants("ScheduleMealSetDetail").ToList();

                    foreach (XElement scheduleMealSetDetailEl in ElList)
                    {
                        // not null value parse
                        int scheduleMealSetDetailID = int.Parse(scheduleMealSetDetailEl.Element("ScheduleMealSetDetailID").Value);
                        int mealSetID = int.Parse(scheduleMealSetDetailEl.Element("MealSetID").Value);
                        int scheduleID = int.Parse(scheduleMealSetDetailEl.Element("ScheduleID").Value);
                        DateTime insertedDate = DateTime.Parse(scheduleMealSetDetailEl.Element("InsertedDate").Value);
                        DateTime lastUpdated = DateTime.Parse(scheduleMealSetDetailEl.Element("LastUpdated").Value);

                        if (insertedDate > lastSync)
                        {
                            scheduleMealSetDetailTA.InsertWithID(scheduleMealSetDetailID, mealSetID, scheduleID, insertedDate, lastUpdated);
                            continue;
                        }

                        scheduleMealSetDetailTA.Update(mealSetID, scheduleID, insertedDate, lastUpdated, scheduleMealSetDetailID);
                    }

                    // sync transaction type table
                    ElList = newDataSetEl.Descendants("TransactionType").ToList();

                    foreach (XElement transactionTypeEl in ElList)
                    {
                        // not null value parse
                        int transactionTypeID = int.Parse(transactionTypeEl.Element("TransactionTypeID").Value);
                        string name = transactionTypeEl.Element("Name").Value;
                        DateTime insertedDate = DateTime.Parse(transactionTypeEl.Element("InsertedDate").Value);
                        DateTime lastUpdated = DateTime.Parse(transactionTypeEl.Element("LastUpdated").Value);

                        if (insertedDate > lastSync)
                        {
                            transactionTypeTA.InsertWithID(transactionTypeID, name, insertedDate, lastUpdated);
                            continue;
                        }

                        transactionTypeTA.Update(name, insertedDate, lastUpdated, transactionTypeID);
                    }

                    // sync transaction history table
                    ElList = newDataSetEl.Descendants("TransactionHistory").ToList();

                    foreach (XElement transactionHistoryEl in ElList)
                    {
                        // not null value parse
                        int transactionHistoryID = int.Parse(transactionHistoryEl.Element("TransactionHistoryID").Value);
                        string username = transactionHistoryEl.Element("Username").Value;
                        int transactionTypeID = int.Parse(transactionHistoryEl.Element("TransactionTypeID").Value);
                        int value = int.Parse(transactionHistoryEl.Element("Value").Value);
                        string transactionContent = transactionHistoryEl.Element("TransactionContent").Value;
                        bool isAuto = bool.Parse(transactionHistoryEl.Element("IsAuto").Value);
                        DateTime insertedDate = DateTime.Parse(transactionHistoryEl.Element("InsertedDate").Value);
                        DateTime lastUpdated = DateTime.Parse(transactionHistoryEl.Element("LastUpdated").Value);

                        // nullable value parse
                        int? scheduleMealSetDetailID;
                        if (transactionHistoryEl.Element("ScheduleMealSetDetailID") == null)
                        {
                            scheduleMealSetDetailID = null;
                        }
                        else
                        {
                            scheduleMealSetDetailID = int.Parse(transactionHistoryEl.Element("ScheduleMealSetDetailID").Value);
                        }

                        string updatedBy = transactionHistoryEl.TryGetElementValue("UpdatedBy");

                        if (insertedDate > lastSync)
                        {
                            transactionHistoryTA.Insert(username, transactionTypeID, value, transactionContent
                                , scheduleMealSetDetailID, isAuto, insertedDate, updatedBy, lastUpdated);
                            continue;
                        }

                        transactionHistoryTA.Update(username, transactionTypeID, value, transactionContent, scheduleMealSetDetailID
                            , isAuto, insertedDate, updatedBy, lastUpdated, transactionHistoryID);
                    }

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
            }
        }
Ejemplo n.º 3
0
        internal static Bill PayForFood(Customer customer, bool eatMoreFlag, int? scheduleMealSetDetailID, string mealSetName)
        {
            UserInfoTableAdapter userInfoTA = new UserInfoTableAdapter();

            DataTable userInfo = userInfoTA.GetUserInfoWithoutFingerPrint(customer.Username);
            if (userInfo.Rows.Count != 1)
            {
                throw new Exception("Can't get User Info.");
            }

            DateTime lastUpdatedMoney = userInfo.Rows[0].Field<DateTime>("LastUpdatedMoney");
            int amountOfMoney = userInfo.Rows[0].Field<int>("AmountOfMoney");

            TransactionHistoryTableAdapter transactionHistoryTA = new TransactionHistoryTableAdapter();

            int? sumOfMoney = transactionHistoryTA.GetCurrentMoney(customer.Username, lastUpdatedMoney);

            if (sumOfMoney == null)
            {
                sumOfMoney = 0;
            }

            int curMoney = sumOfMoney.Value + amountOfMoney;

            int payMoney = customer.MealValue;
            bool isEatMore = false;
            if (customer.CanEatMore && eatMoreFlag && customer.MoreMealValue != null)
            {
                payMoney += customer.MoreMealValue.Value;
                isEatMore = true;
            }

            int remainMoney = curMoney - payMoney;
            if (remainMoney < 0)
            {
                if (!customer.CanDebt)
                {
                    return new Bill()
                    {
                        alert = "TK da het tien",
                        isSuccess = false
                    };
                }
            }

            DateTime insertedDate = DateTime.Now;
            string transactionContent = isEatMore ? "Ăn thêm + " + customer.MoreMealValue.Value : "Ăn";

            string TransactionHistoryIDStr = transactionHistoryTA.InsertScalar(customer.Username, 1, (-1) * payMoney, transactionContent
                , scheduleMealSetDetailID, true, insertedDate, CTMF_Desktop_App.Forms.MainForm.username, insertedDate).ToString();

            int TransactionHistoryID = int.Parse(TransactionHistoryIDStr);
            XmlSync.SaveTransactionHistoryXml(TransactionHistoryID, customer.Username, 1, (-1) * payMoney, transactionContent
                , scheduleMealSetDetailID, true, insertedDate, CTMF_Desktop_App.Forms.MainForm.username, insertedDate);

            return new Bill()
            {
                username = customer.Username,
                transactionContent = transactionContent,
                mealSetName = mealSetName,
                insertedDate = insertedDate,
                isSuccess = true,
                alert = "Con lai:" + remainMoney
            };
        }
Ejemplo n.º 4
0
        internal static string NewSync()
        {
            Log.ActivityLog("-----------------------New sync transaction-----------------------");
            Log.ActivityLog("Clear all table.");

            MealSetTableAdapter mealSetTA = new MealSetTableAdapter();
            ScheduleTableAdapter scheduleTA = new ScheduleTableAdapter();
            ScheduleMealSetDetailTableAdapter scheduleMealSetDetailTA = new ScheduleMealSetDetailTableAdapter();
            ServingTimeTableAdapter servingTimeTA = new ServingTimeTableAdapter();
            TransactionHistoryTableAdapter transactionHistoryTA = new TransactionHistoryTableAdapter();
            TransactionTypeTableAdapter transactionTypeTA = new TransactionTypeTableAdapter();
            UserInfoTableAdapter userInfoTA = new UserInfoTableAdapter();
            UserTypeTableAdapter userTypeTA = new UserTypeTableAdapter();

            userTypeTA.Connection.Open();
            userInfoTA.Connection = userTypeTA.Connection;
            mealSetTA.Connection = userTypeTA.Connection;
            servingTimeTA.Connection = userTypeTA.Connection;
            scheduleTA.Connection = userTypeTA.Connection;
            scheduleMealSetDetailTA.Connection = userTypeTA.Connection;
            transactionTypeTA.Connection = userTypeTA.Connection;
            transactionHistoryTA.Connection = userTypeTA.Connection;

            using (SqlTransaction transaction = userTypeTA.Connection.BeginTransaction())
            {
                userTypeTA.AttachTransaction(transaction);
                userInfoTA.AttachTransaction(transaction);
                mealSetTA.AttachTransaction(transaction);
                servingTimeTA.AttachTransaction(transaction);
                scheduleTA.AttachTransaction(transaction);
                scheduleMealSetDetailTA.AttachTransaction(transaction);
                transactionTypeTA.AttachTransaction(transaction);
                transactionHistoryTA.AttachTransaction(transaction);

                try
                {
                    transactionHistoryTA.ClearTable();
                    transactionTypeTA.ClearTable();
                    scheduleMealSetDetailTA.ClearTable();
                    scheduleTA.ClearTable();
                    servingTimeTA.ClearTable();
                    mealSetTA.ClearTable();
                    userInfoTA.ClearTable();
                    userTypeTA.ClearTable();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }

                transaction.Commit();
            }

            Log.ActivityLog("Clear all completed.");
            Log.ActivityLog("Register sync to server.");

            ServiceReference.WebServiceSoapClient soapClient = new ServiceReference.WebServiceSoapClient();

            DateTime syncDate = DateTime.Now;
            string oldSyncID = XmlSync.GetSyncID();
            string newSyncID = soapClient.NewSyncData(WebServiceAuth.AuthSoapHeader(), syncDate, oldSyncID);
            XmlSync.SaveNewSync(newSyncID);

            Log.ActivityLog("Register completed.");
            Log.ActivityLog("Geting xml data.");

            string fileNameList = XmlSync.RequestXmlFileName(newSyncID, true);
            IList<string> xmlPathList = XmlSync.SaveXmlFile(fileNameList);

            Log.ActivityLog("Save xml data completed.");
            Log.ActivityLog("Start sync.");

            XmlSync.Sync(xmlPathList);

            Log.ActivityLog("Sync completed.");
            Log.ActivityLog("Update last sync date.");

            XmlSync.SetLastSync(syncDate);
            soapClient.SetLastSyncAndInactiveFile(WebServiceAuth.AuthSoapHeader(), syncDate, fileNameList,newSyncID);
            Log.ActivityLog("-----------------------Sync transaction done-----------------------");
            return newSyncID;
        }
Ejemplo n.º 5
0
        private void btnUpdateFingerPrint_Click(object sender, EventArgs e)
        {
            if (dataGridView.SelectedRows.Count != 1)
            {
                MessageBox.Show("Xin hãy chọn người dùng trước.");
                return;
            }

            if (bwSend.IsBusy)
            {
                MessageBox.Show("Xin hãy đợi hệ thống hoàn thành việc gửi ảnh.");
                return;
            }

            if (_scannerPortNumber < 0)
            {
                using (var form = new SelectScanner())
                {
                    var result = form.ShowDialog();
                    _scannerPortNumber = form.scannerPort;
                    _scannerAddr = form.scannerAddr;
                }

                if (_scannerPortNumber < 0 || _scannerAddr == 0)
                {
                    MessageBox.Show("Không thể kết nối tới máy quét.");
                    return;
                }

                btnStopDevice.Enabled = true;
            }

            string username = dataGridView.SelectedRows[0].Cells["Username"].Value.ToString();
            string imageFile;
            int? fingerPosition;
            DateTime? lastUpdatedFingerPrint;

            using (var form = new UpdateFingerPrint(_scannerAddr, username))
            {
                var result = form.ShowDialog();
                imageFile = form.fingerImageFile;
                fingerPosition = form.fingerPostition;
            }

            if (imageFile != null)
            {
                Image savedImage = Image.FromFile(imageFile);
                ImageConverter converter = new ImageConverter();
                byte[] fingerImage = (byte[])converter.ConvertTo(savedImage, typeof(byte[]));

                lastUpdatedFingerPrint = DateTime.Now;

                DataRow userInfoRow = null;
                foreach (DataRow row in customerDT.Rows)
                {
                    if (row["Username"].ToString() == username)
                    {
                        row["FingerPrintIMG"] = fingerImage;
                        row["FingerPosition"] = fingerPosition;
                        row["LastUpdatedFingerPrint"] = lastUpdatedFingerPrint;
                        row["IsActive"] = true;

                        userInfoRow = row;
                        break;
                    }
                }

                dataGridView.DataSource = customerDT;

                UserInfoTableAdapter userInfoTA = new UserInfoTableAdapter();
                userInfoTA.UpdateFingerPrint(fingerImage, lastUpdatedFingerPrint, fingerPosition, username);

                if (cbSendToServer.Checked)
                {
                    lblSendReport.Text = "Đang gửi hình ảnh lên server.";

                    string paramUsername = username;
                    byte[] paramFingerImage = fingerImage;
                    int? paramFingerPosition = fingerPosition;
                    DateTime paramLastUpdatedFingerPrint = lastUpdatedFingerPrint.Value;
                    DataRow paramUserInfoRow = userInfoRow;

                    object[] parameters = new object[] { paramUsername, paramFingerImage, paramFingerPosition
                        , paramLastUpdatedFingerPrint, paramUserInfoRow};

                    bwSend.RunWorkerAsync(parameters);
                }
                else
                {
                    XmlSync.SaveUserInfoXml(userInfoRow.Field<string>("Username"), userInfoRow.Field<string>("Name"), userInfoRow.Field<string>("TypeShortName")
                    , userInfoRow.Field<int>("AmountOfMoney"), userInfoRow.Field<DateTime>("LastUpdatedMoney"), fingerImage, lastUpdatedFingerPrint
                    , fingerPosition, userInfoRow.Field<bool>("IsCafeteriaStaff"), userInfoRow.Field<bool>("IsActive"), userInfoRow.Field<DateTime>("InsertedDate")
                    , userInfoRow.Field<string>("UpdatedBy"), userInfoRow.Field<DateTime>("LastUpdated"));
                }

                Home.LoadCustomerData();

                int? fingerPrintCount_ = (int?)(new UserInfoTableAdapter().GetUsingFingerPrintCout());
                if (fingerPrintCount_ == null)
                {
                    fingerPrintCount_ = 0;
                }
                Home.fingerPrintCount = fingerPrintCount_.ToString();
                MainForm.homeForm.ReloadClientInfo();
            }
        }