Example #1
0
        private void menuItemResetUsers_Click(object sender, EventArgs e)
        {
            FGSyncService   client = new FGSyncService();
            DBClass         db     = new DBClass();
            List <UserInfo> users  = new List <UserInfo>();

            try
            {
                panelWait.Visible = true;
                DialogResult dialogRes = MessageBox.Show("Do you want to reset User Records on this device?", "Reset Users [" + AppVariables.DeviceName + "]", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                if (dialogRes == DialogResult.Yes)
                {
                    List <UserData> data = client.GetUserData().ToList();
                    foreach (UserData oneRec in data)
                    {
                        users.Add(new UserInfo()
                        {
                            UserName = oneRec.UserName, Password = oneRec.Password, Role = oneRec.UserType
                        });
                    }
                    client.Dispose();
                    db.InsertBulkUsers(users);

                    MessageBox.Show("Bulk user have been reset successfully.", "Reset Users [" + AppVariables.DeviceName + "]", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
            finally
            {
                panelWait.Visible = false;
            }
        }
Example #2
0
        private void menuItemTestServce_Click(object sender, EventArgs e)
        {
            try
            {
                panelSuccess.Visible = false;
                panelFail.Visible    = false;

                FGSyncService client = new FGSyncService();
                string        strMsg = client.GetPing();
                SystemSounds.Beep.Play();
                MessageBox.Show(strMsg, "Testing Webservice");
            }
            catch (WebException exp)
            {
                string msg = string.Empty;
                if (exp.Status == WebExceptionStatus.ConnectFailure)
                {
                    msg = "Unable to connect to Dynamics AX. Please contact Network administrator.";
                }
                else
                {
                    msg = exp.Message;
                }

                MessageBox.Show(msg, "Connect Failure [" + AppVariables.DeviceName + "]", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }
Example #3
0
        private void menuItemUploadData_Click(object sender, EventArgs e)
        {
            FGSyncService client = new FGSyncService();
            DBClass       db = new DBClass();
            long          lastSyncId = 0, dataLen = 0;
            int           counted = 0, size = 50;
            bool          result = false;

            panelSuccess.Visible = false;
            panelFail.Visible    = false;

            try
            {
                long topSyncId = 0;//long.Parse("0" + db.GetOptions(Option.LastSyncId));
                List <WebRefFGSync.PalletEntity> data = db.GetFGData(topSyncId);
                List <WebRefFGSync.PalletEntity> dataChunks;
                dataLen = data.Count;

                while (dataLen > 0)
                {
                    dataChunks = data.Skip(counted).Take(size).ToList();
                    client.UpdateFGDesktop(dataChunks.ToArray(), out lastSyncId, out result);
                    dataLen -= size;
                    counted += size;
                }
                if (counted == 0)
                {
                    MessageBox.Show("All data has already been uploaded. No more new data to upload.", "Syncing Data", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                }
                if (result)
                {
                    db.SaveOptions(Option.LastSyncId, lastSyncId.ToString());
                    MessageBox.Show("Data has been uploaded to server successfully", "Syncing Data", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                }
            }
            catch (WebException exp)
            {
                string msg = string.Empty;
                if (exp.Status == WebExceptionStatus.ConnectFailure)
                {
                    msg = "Unable to connect to Dynamics AX. Please contact Network administrator.";
                }
                else
                {
                    msg = exp.Message;
                }

                MessageBox.Show(msg, "Connect Failure [" + AppVariables.DeviceName + "]", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }
Example #4
0
        void timeSync_Tick(object sender, EventArgs e)
        {
            TimeSpan tsStart  = new TimeSpan(12, 30, 0);
            TimeSpan tsEnd    = new TimeSpan(13, 45, 0);
            TimeSpan tsStart2 = new TimeSpan(16, 30, 0);
            TimeSpan tsEnd2   = new TimeSpan(17, 0, 0);

            if ((DateTime.Now.TimeOfDay >= tsStart && DateTime.Now.TimeOfDay <= tsEnd) ||
                (DateTime.Now.TimeOfDay >= tsStart2 && DateTime.Now.TimeOfDay <= tsEnd2))
            {
                //Checks and Uploads the data to server after an interval automatically.
                try
                {
                    int     size      = 50; //Chunk Size
                    DBClass db        = new DBClass();
                    long    topSyncId = long.Parse("0" + db.GetOptions(Option.LastSyncId));
                    List <WebRefFGSync.PalletEntity> data = db.GetFGData(topSyncId);
                    if (data.Count > 0)
                    {
                        List <WebRefFGSync.PalletEntity> dataChunks;
                        FGSyncService client = new FGSyncService();
                        if (data.Count < size)
                        {
                            size = data.Count;
                        }
                        dataChunks = data.Take(size).ToList();

                        client.BeginUpdateFGDesktop(dataChunks.ToArray(), new AsyncCallback(FGInventory), client);
                    }
                }
                catch (WebException exp)
                {
                    string msg = string.Empty;
                    if (exp.Status == WebExceptionStatus.ConnectFailure)
                    {
                        msg = "Unable to connect to Dynamics AX. Please contact Network administrator.";
                    }
                    else
                    {
                        msg = exp.Message;
                    }

                    //MessageBox.Show(msg, "Connect Failure [" + AppVariables.DeviceName + "]", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                }
                catch (Exception exp)
                {
                    //MessageBox.Show(exp.Message, "Dynamics AX [" + AppVariables.DeviceName + "]", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                }
            }
        }
Example #5
0
        static void FGInventory(IAsyncResult result)
        {
            try
            {
                FGSyncService client = (FGSyncService)result.AsyncState;
                if (result.IsCompleted)
                {
                    long lastSyncId   = 0;
                    bool returnResult = false;
                    client.EndUpdateFGDesktop(result, out lastSyncId, out returnResult);
                    if (returnResult)
                    {
                        DBClass db = new DBClass();
                        db.SaveOptions(Option.LastSyncId, lastSyncId.ToString());
                    }
                }
            }
            catch (WebException exp)
            {
                string msg = string.Empty;
                if (exp.Status == WebExceptionStatus.ConnectFailure)
                {
                    msg = "Unable to connect to Dynamics AX. Please contact Network administrator.";
                }
                else
                {
                    msg = exp.Message;
                }

                //MessageBox.Show(msg, "Connect Failure [" + AppVariables.DeviceName + "]", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
            catch (Exception exp)
            {
                string msg = exp.Message;
            }
        }
Example #6
0
        private void menuItemResetData_Click(object sender, EventArgs e)
        {
            string msg = string.Empty;

            this.Refresh();
            this.SuspendLayout();
            panelWait.Visible = true;
            this.ResumeLayout();

            try
            {
                DialogResult dialogRes = MessageBox.Show("Do you want to reset the Data on this device?", "Reset Data [" + AppVariables.DeviceName + "]", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                if (dialogRes == DialogResult.Yes)
                {
                    DateTime dtStart = DateTime.Now;

                    bool          isResume = true;
                    int           iCount   = 0;
                    FGSyncService client   = new FGSyncService();
                    DBClass       db       = new DBClass();

                    //List<WebRefFGSync.PalletEntity> data = client.ResetData().ToList();
                    //int total = db.ResetDataAll(data);
                    //delete all data from mobile device
                    db.ResetDataAll();
                    //now add data into device.
                    do
                    {
                        List <InventAvailContract> data = client.GetFGYearInventory(iCount, true).ToList();
                        if (data.Count.Equals(0))
                        {
                            isResume = false;
                        }
                        else
                        {
                            iCount = db.InsertDataAll(data);
                            iCount++;
                        }
                    }while (isResume);
                    client.Dispose();
                    DateTime dtEnd    = DateTime.Now;
                    var      dateDiff = (dtEnd - dtStart).TotalMinutes;
                    MessageBox.Show("Data has been reset. Total number of rows Imported: " + iCount.ToString() + "\nTime taken (Minutes): " + dateDiff.ToString(), "Reset Data", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                }
            }
            catch (WebException exp)
            {
                if (exp.Status == WebExceptionStatus.ConnectFailure)
                {
                    msg = "Unable to connect to Dynamics AX. Please contact Network administrator.";
                }
                else
                {
                    msg = exp.Message;
                }

                MessageBox.Show(msg, "Connect Failure [" + AppVariables.DeviceName + "]", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
            finally
            {
                panelWait.Visible = false;
            }
        }