using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SCAN
{
    public partial class Form_OutboundMsgOKCancel : Form
    {
        private List<lib.db.HT_OB> outboundItems;
        private int currentItem; //
        private lib.LogWriter logger = lib.LogWriter.getInstance();

        public Form_OutboundMsgOKCancel(string message, Color color, List<lib.db.HT_OB> outboundItems, int selectedIndex)
        {
            InitializeComponent();

            lblMessage.Text = message;
            lblMessage.ForeColor = color;
            this.outboundItems = outboundItems;
            this.currentItem = selectedIndex;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            //this.Close();
            //Form frm_edit = new Form_EditQtyOutboundSimple(outboundItems, currentItem);
            //frm_edit.ShowDialog();
            try
            {     
                    string item_id = outboundItems.ElementAt(currentItem).__COLUMNS["item_id"];
                    string customer_id = outboundItems.ElementAt(currentItem).__COLUMNS["customer_id"];
                    string product_date = outboundItems.ElementAt(currentItem).__COLUMNS["product_date"];
                    string create_date = outboundItems.ElementAt(currentItem).__COLUMNS["create_date"];
                    string act_type = outboundItems.ElementAt(currentItem).__COLUMNS["act_type"];

                    //MessageBox.Show(packing_size.ToString());
                    /*
                     * string sql = @"UPDATE HT_OB 
                            SET status=''
                                , update_date='{0}'
                                , update_time='{1}'
                                , update_by='{2}' 
                            WHERE item_id='{3}' AND customer_id='{4}' AND product_date='{5}' AND create_date='{6}' AND act_type='{7}' AND status='Confirm' AND sync=0 ";
                    List<string[]> rows = (new lib.DbTable()).executeQuery(String.Format(sql
                        , DateTime.Now.ToString("yyMMdd")
                        , DateTime.Now.ToString("HHmmss")
                        , Form_Login._Form_LoginInstance.userName
                        , item_id
                        , customer_id
                        , product_date
                        , create_date
                        , act_type
                        ));
                     * */


                    (new lib.db.HT_OB()).remove(String.Format("product_date='{0}' AND item_id='{1}' AND customer_id='{2}' AND status='{3}'  AND sync='{4}' AND create_date='{5}' AND act_type='{6}'"
                                                 , product_date
                                                 , item_id
                                                 , customer_id
                                                 , "Confirm"
                                                 , "0"
                                                 , create_date
                                                 , act_type
                                                 ));


                    lib.db.HT_OB ob = outboundItems.ElementAt(currentItem);
                    ob.__COLUMNS["status"] = "";
                    // update item back to buffer list
                    outboundItems[currentItem] = ob;
                    Form_OutboundSimple.outboundItems = outboundItems;
                    this.Close();
                    return;
            }
            catch (Exception ex)
            {
                logger.Log(ex.Message);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
            return;
        }
    }
}