예제 #1
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);
            }
        }
예제 #2
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;
            }
        }