Exemplo n.º 1
0
        int doDowunload()
        {
            try
            {
                //    SplashScreenManager.ShowForm(this, typeof(WaitForm1), true, true, false);

                System.Data.DataSet dsonline = new System.Data.DataSet();

                using (SqlConnection connect = new SqlConnection(Logic.ConnectionString))
                {
                    connect.Open();

                    command = new SqlCommand("doGetStationInfo", connect)
                    {
                        CommandType = CommandType.StoredProcedure, CommandTimeout = 0
                    };

                    using (System.Data.DataSet ds = new System.Data.DataSet())
                    {
                        adp = new SqlDataAdapter(command);

                        adp.SelectCommand.CommandTimeout = 0;

                        adp.Fill(ds);

                        Dts = ds.Tables[0];

                        connect.Close();

                        if (ds.Tables[0].Rows.Count < 1)
                        {
                            label7.Text = "Not Configured for this station";
                            return(0);
                        }
                        else
                        {
                            label5.Text = string.Format("Receipt Data Download [ {0} ]", ds.Tables[0].Rows[0]["StationName"]);

                            switch (Program.intCode)
                            {
                            case 13:    //Akwa Ibom state
                                using (var receiptAka = new AkwaIbomReceiptServices.ReceiptService())
                                {
                                    dataSet = receiptAka.DownloadData(ds, Program.stateCode);
                                }

                                if (dataSet.Tables.Count == 0)
                                {
                                    timer1.Stop(); timer1.Enabled = false;
                                    //btnStop.Visible = false; btnStart.Visible = true;
                                    return(0);
                                }
                                if (dataSet.Tables[0].Rows.Count < 1)
                                {
                                    label7.Text = String.Format("No More Records for the Station {0}", Program.stationName);
                                    timer1.Stop(); timer1.Enabled = false;
                                    //btnStop.Visible = false; btnStart.Visible = true;
                                    return(0);
                                }
                                else
                                {
                                    dataSet2 = InsertData(dataSet);
                                }

                                if (dataSet2.Tables[0].Rows[0]["returnCode"].ToString() == "-1")
                                {
                                    timer1.Stop();
                                    Common.setMessageBox(string.Format("{0}...Error Occur During Data Insert After download.... Insert Download", dataSet2.Tables[0].Rows[0]["returnMessage"]), Program.ApplicationName, 3);
                                    timer1.Stop();
                                    timer1.Enabled = false;
                                    return(0);
                                }
                                else
                                {
                                    dataSet3.Clear();
                                    using (var receiptAka = new AkwaIbomReceiptServices.ReceiptService())
                                    {
                                        dataSet3 = receiptAka.DownloadDataUpdate(dataSet2, Program.stationCode);
                                    }
                                }
                                break;

                            case 20:    //Delta State
                                using (var receiptDelta = new DeltaBir.ReceiptService())
                                {
                                    System.Data.DataSet dsnew = new System.Data.DataSet();
                                    //dsnew = Logic.GetMacAddress();
                                    //gridControl1.DataSource = dsnew.Tables[0];
                                    //gridControl1.DataSource = Logic.GetMacAddress();
                                    dataSet = receiptDelta.DownloadData(Logic.GetMacAddress(), Program.stationCode);
                                }

                                if (dataSet.Tables.Count == 0)
                                {
                                    timer1.Stop(); timer1.Enabled = false;
                                    //btnStop.Visible = false; btnStart.Visible = true;
                                    return(0);
                                }

                                if (dataSet.Tables[0].Rows[0]["returnCode"].ToString() == "-1")
                                {
                                    timer1.Stop();
                                    Common.setMessageBox(string.Format("{0}...Status Messages", dataSet.Tables[0].Rows[0]["returnMessage"]), Program.ApplicationName, 3);
                                    btnStart.Visible = true;
                                    timer1.Enabled   = false;
                                    return(0);
                                }
                                if (dataSet.Tables[1] != null && dataSet.Tables[1].Rows.Count < 1)
                                {
                                    label7.Text = String.Format("No More Records for the Station {0}", Program.stationName);
                                    timer1.Stop(); timer1.Enabled = false;
                                    btnStop.Visible = false; btnStart.Visible = true; btnStart.Enabled = true;
                                    return(0);
                                }
                                else
                                {
                                    dataSet2 = InsertData(dataSet);

                                    if (dataSet2.Tables[0].Rows[0]["returnCode"].ToString() == "-1")
                                    {
                                        Common.setMessageBox(string.Format("{0}...Error Occur During Data Insert After download.... Insert Download", dataSet2.Tables[0].Rows[0]["returnMessage"]), Program.ApplicationName, 3);
                                        timer1.Stop();
                                        timer1.Enabled = false;
                                        return(0);
                                    }
                                    else
                                    {
                                        dataSet3.Clear();

                                        //dsonline = dataSet2.Tables[1];

                                        DataTable dtt = new DataTable();
                                        dtt = dataSet2.Tables[1].Copy();

                                        //dtsoff = ds.Tables[2].DataSet;
                                        dsonline.Tables.Add(dtt);

                                        using (var receiptDelta = new DeltaBir.ReceiptService())
                                        {
                                            dataSet3 = receiptDelta.DownloadDataUpdate(dsonline, Program.stationCode);
                                        }
                                    }
                                }

                                break;

                            case 32:    //kogi state
                                break;

                            case 37:    //ogun state

                                using (var receiptsserv = new ReceiptService())
                                {
                                    System.Data.DataSet dsnew = new System.Data.DataSet();
                                    //dsnew = Logic.GetMacAddress();
                                    //gridControl1.DataSource = dsnew.Tables[0];
                                    dataSet = receiptsserv.DownloadData(Logic.GetMacAddress(), Program.stationCode);
                                }

                                if (dataSet.Tables[0].Rows[0]["returnCode"].ToString() == "-1")
                                {
                                    timer1.Stop();
                                    Common.setMessageBox(string.Format("{0}...Status Messages", dataSet.Tables[0].Rows[0]["returnMessage"]), Program.ApplicationName, 3);
                                    btnStart.Visible = true;
                                    timer1.Enabled   = false;
                                    return(0);
                                }

                                if (dataSet.Tables.Count == 0)
                                {
                                    timer1.Stop(); timer1.Enabled = false;
                                    //btnStop.Visible = false; btnStart.Visible = true;
                                    return(0);
                                }

                                if (dataSet.Tables[1] != null && dataSet.Tables[1].Rows.Count < 1)
                                {
                                    label7.Text = String.Format("No More Records for the Station {0}", Program.stationName);
                                    timer1.Stop(); timer1.Enabled = false;
                                    btnStop.Visible = false; btnStart.Visible = true; btnStart.Enabled = true;
                                    return(0);
                                }
                                else
                                {
                                    dataSet2 = InsertData(dataSet);

                                    if (dataSet2.Tables[0].Rows[0]["returnCode"].ToString() == "-1")
                                    {
                                        Common.setMessageBox(string.Format("{0}...Error Occur During Data Insert After download.... Insert Download", dataSet2.Tables[0].Rows[0]["returnMessage"]), Program.ApplicationName, 3);
                                        timer1.Stop();
                                        timer1.Enabled = false;
                                        return(0);
                                    }
                                    else
                                    {
                                        dataSet3.Clear();

                                        using (var receiptsserv = new ReceiptService())
                                        {
                                            dataSet3 = receiptsserv.DownloadDataUpdate(dataSet2, Program.stationCode);
                                        }
                                    }
                                }
                                break;

                            case 40:    //oyo state

                                using (var receiptsServices = new OyoReceiptServices.ReceiptService())
                                {
                                    System.Data.DataSet dsnew = new System.Data.DataSet();
                                    dsnew = Logic.GetMacAddress();
                                    gridControl1.DataSource = dsnew.Tables[0];
                                    dataSet = receiptsServices.DownloadData(Logic.GetMacAddress(), Program.stationCode);
                                }

                                if (dataSet.Tables[0].Rows[0]["returnCode"].ToString() == "-1")
                                {
                                    timer1.Stop();
                                    Common.setMessageBox(string.Format("{0}...Status Messages", dataSet.Tables[0].Rows[0]["returnMessage"]), Program.ApplicationName, 3);
                                    btnStart.Visible = true;
                                    timer1.Enabled   = false;
                                    return(0);
                                }

                                if (dataSet.Tables.Count == 0)
                                {
                                    timer1.Stop(); timer1.Enabled = false;
                                    //btnStop.Visible = false; btnStart.Visible = true;
                                    return(0);
                                }

                                if (dataSet.Tables[1] != null && dataSet.Tables[1].Rows.Count < 1)
                                {
                                    label7.Text = String.Format("No More Records for the Station {0}", Program.stationName);
                                    timer1.Stop(); timer1.Enabled = false;
                                    btnStop.Visible = false; btnStart.Visible = true; btnStart.Enabled = true;
                                    return(0);
                                }
                                else
                                {
                                    dataSet2 = InsertData(dataSet);

                                    if (dataSet2.Tables[0].Rows[0]["returnCode"].ToString() == "-1")
                                    {
                                        Common.setMessageBox(string.Format("{0}...Error Occur During Data Insert After download.... Insert Download", dataSet2.Tables[0].Rows[0]["returnMessage"]), Program.ApplicationName, 3);
                                        timer1.Stop();
                                        timer1.Enabled = false;
                                        return(0);
                                    }
                                    else
                                    {
                                        dataSet3.Clear();

                                        using (var receiptsServices = new OyoReceiptServices.ReceiptService())
                                        {
                                            dataSet3 = receiptsServices.DownloadDataUpdate(dataSet2, Program.stationCode);
                                        }
                                    }
                                }
                                break;

                            default:
                                break;
                            }
                            if (dataSet3.Tables[0].Rows[0]["returnCode"].ToString() == "00")
                            {
                                lblAll.Text = dataSet3.Tables[1].Rows[0]["ALLRecords"].ToString();

                                lblDownload.Text = dataSet3.Tables[2].Rows[0]["DownloadedRecords"].ToString();

                                lblRemain.Text = dataSet3.Tables[3].Rows[0]["RemainRecords"].ToString();

                                lblError.Text = dataSet3.Tables[4].Rows[0]["ErrorRecords"].ToString();

                                return(1);
                            }
                            else
                            {
                                timer1.Stop();
                                Common.setMessageBox(string.Format("{0}...Download Data to Local Station...", dataSet3.Tables[0].Rows[0]["returnMessage"]), Program.ApplicationName, 3);
                                timer1.Enabled = false;
                                //btnStop.Visible = false;
                                //btnStart.Visible = true;
                                return(0);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                timer1.Stop();
                Common.setMessageBox(String.Format("{0}----{1}...Do Download to Station,doDowunload", ex.Message, ex.StackTrace), Program.ApplicationName, 3); timer1.Stop(); timer1.Enabled = false;
                return(0);
            }
            finally
            {
                //SplashScreenManager.CloseForm(false);
            }
        }