Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
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);
                }
            }
        }