Beispiel #1
0
        private void menuItem1_Click(object sender, EventArgs e)
        {
            if (GrdDailyLoss.DataSource == null)
            {
                MessageBox.Show("There is no record to register!");
            }
            else
            {
                Cursor.Current = Cursors.WaitCursor;

                try
                {
                    decimal countotal = 0;
                    bool    flagtemp  = false;
                    string  itemtemp;
                    string  locationtemp;
                    string  bincodetemp;


                    ItemJournalDailyLossQH.ItemJournalDailyLossQH_Service dlservice = new QHMobile.ItemJournalDailyLossQH.ItemJournalDailyLossQH_Service();
                    dlservice.Url         = WebServiceInstants.GetURL(ServiceType.ItemJournalDailyLossQH);
                    dlservice.Credentials = nc;

                    for (int i = 0; i < array_daily.Count; i++)
                    {
                        if (array_daily[i].lineNum.Equals("") || array_daily[i].lineNum == 0)
                        {
                            ItemJournalDailyLossQH.ItemJournalDailyLossQH dl = new QHMobile.ItemJournalDailyLossQH.ItemJournalDailyLossQH();

                            dlservice.Create("DOA", ref dl);     // Actual value should be DOA

                            ItemJournalDailyLossQH.ItemJournalDailyLossQH dlupdate = new QHMobile.ItemJournalDailyLossQH.ItemJournalDailyLossQH();
                            dlupdate = dlservice.Read("DOA", dl.Line_No);

                            //added by Hsu 23 april 2013//
                            array_daily[i].lineNum = dl.Line_No;

                            // added by Hsu 23 april 2013 //
                            dlupdate.Posting_Date          = Convert.ToDateTime(array_daily[i].postingDate);
                            dlupdate.Posting_DateSpecified = true;
                            dlupdate.Entry_Type            = ItemJournalDailyLossQH.Entry_Type.Negative_Adjmt;
                            dlupdate.Entry_TypeSpecified   = true;
                            dlupdate.Item_No = array_daily[i].itemno;

                            st = DateTime.Now.ToString("ddMMyyyy");
                            dlupdate.Document_No = st;

                            //dlservice.Update("DOA", ref dlupdate);

                            dlupdate.Quantity             = Convert.ToInt32(array_daily[i].quantity);
                            dlupdate.Location_Code        = array_daily[i].location;
                            dlupdate.Staff_Dimension_Code = staffdim;
                            dlupdate.Bin_Code             = array_daily[i].bincode;

                            dlservice.Update("DOA", ref dlupdate);
                            //array_daily.RemoveAt(i);
                        }

                        CompactSQL comsql = new CompactSQL();
                        comsql.DeleteOneRecord(array_daily[i].sqlLineNum, "DailyLoss");
                    }
                    //// to adjust ////

                    ArrayList tnk = new ArrayList();
                    for (int i = 0; i < array_daily.Count; i++)
                    {
                        if (i == 0)
                        {
                            tnk.Add(array_daily[i].bincode);
                        }
                        else
                        {
                            if (!tnk.Contains(array_daily[i].bincode))
                            {
                                tnk.Add(array_daily[i].bincode);
                            }
                        }
                    }

                    for (int j = 0; j < tnk.Count; j++)
                    {
                        countotal    = 0;
                        flagtemp     = false;
                        itemtemp     = "";
                        locationtemp = "";
                        bincodetemp  = "";

                        for (int k = 0; k < array_daily.Count; k++)
                        {
                            if (tnk[j].ToString().Equals(array_daily[k].bincode))
                            {
                                itemtemp     = array_daily[k].itemno;
                                countotal    = countotal + Convert.ToDecimal(array_daily[k].quantity);
                                locationtemp = array_daily[k].location;
                                bincodetemp  = array_daily[k].bincode;

                                if (array_daily[k].emptyTank == true)
                                {
                                    flagtemp = true;
                                }
                            }
                        }

                        if (flagtemp == true)     //qhbincon[0].Quantity_Base < countotal ||
                        {
                            QHEmptyTank.QHEmptyTank_Service qhempty = new QHMobile.QHEmptyTank.QHEmptyTank_Service();
                            qhempty.Url         = WebServiceInstants.GetURL(ServiceType.QHEmptyTank);
                            qhempty.Credentials = nc;

                            QHEmptyTank.QHEmptyTank qhcheck = qhempty.Read(bincodetemp);
                            if (qhcheck == null)
                            {
                                QHEmptyTank.QHEmptyTank qhtnk = new QHMobile.QHEmptyTank.QHEmptyTank();
                                qhtnk.Bin_Code = bincodetemp;

                                qhempty.Create(ref qhtnk);


                                qhtnk.Batch_Name    = "DOA";
                                qhtnk.Item_No       = itemtemp;
                                qhtnk.Location_Code = locationtemp;
                                qhempty.Update(ref qhtnk);
                            }
                        }
                    }

                    //// to adjsut ////

                    //CompactSQL comsql = new CompactSQL();
                    //comsql.deleteRecord("DailyLoss");

                    MessageBox.Show("Submitted.");
                    Cursor.Current          = Cursors.Default;
                    GrdDailyLoss.DataSource = null;
                    this.Close();
                    DailyLoss dlf = new DailyLoss(username, staffdim, userlevel);
                    dlf.Show();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error:" + ex);
                    Cursor.Current = Cursors.Default;
                }
            }
        }