コード例 #1
0
        //static AddPhieuNhap()
        //{
        //    if (signleton == null)
        //    {
        //        signleton = new AddPhieuNhap();

        //    }
        //}

        public AddPhieuNhap(string dhid)
        {
            this.dhId = dhid;


            InitializeComponent();
            ViewModel d = new ViewModel();

            dgKho.ItemsSource = Common.KhoDataTable;
            QLVTDataSet.CTDatHangDataTable dhs = new QLVTDataSet.CTDatHangDataTable();
            DataTable tb = Common.CTDatHangDataTable.Select("DatHangId = " + dhId).CopyToDataTable();

            if (tb.Rows.Count > 0)
            {
                dhs.Merge(tb);
            }
            dgCTDH.ItemsSource = dhs;

            dgCTPN.ItemsSource = ctpn = new QLVTDataSet.CTPhieuNhapDataTable();
            d.Kho            = dgKho.SelectedValue;
            this.DataContext = d;
            //ctpn.ColumnChanging += (e, v) => {
            //    if (v.Row.RowState == DataRowState.Detached)
            //        return;
            //    id = v.Row["MatHangId"];
            //    old= v.Row["SoLuong"];
            //};
            bool change = false;

            ctpn.ColumnChanged += (e, v) => {
                if (v.Row.RowState == DataRowState.Detached || change)
                {
                    return;
                }
                Object current, id;
                id      = v.Row["MatHangId"];
                current = v.Row["SoLuong"];
                DataRow[] dataRows = ((QLVTDataSet.CTDatHangDataTable)dgCTDH.ItemsSource).Select("MatHangId = '" + id + "'");
                if (dataRows.Length > 0)
                {
                    int sl = (int)dataRows[0]["SoLuong"];
                    if (sl < ((int)current))
                    {
                        change           = true;
                        v.Row["SoLuong"] = dataRows[0]["SoLuong"];
                        MessageBox.Show("Số lượng mặt hàng đang chọn không thể lớn hơn " + sl);
                    }
                }
                change = false;
            };
            //EventHandler eventHandler = (o, i) => { signleton = new AddPhieuNhap(); };
            //this.Closed += eventHandler;
        }
コード例 #2
0
 private void txbVT_KeyUp(object sender, KeyEventArgs e)
 {
     QLVTDataSet.CTDatHangDataTable matHangs = new QLVTDataSet.CTDatHangDataTable();
     try
     {
         DataTable table;
         int       rs;
         if (int.TryParse(txbVT.Text, out rs))
         {
             table = Common.CTDatHangDataTable.Select("MatHangId = " + rs).CopyToDataTable();
             matHangs.Merge(table);
             dgCTDH.ItemsSource = matHangs;
         }
     }
     catch (Exception ex)
     {
     }
 }
コード例 #3
0
        //private void btnEdit_Click(object sender, RoutedEventArgs e)
        //{

        //    if (dgContent.CurrentItem != null)
        //    {
        //        //tableLog.SetRowChange(((DataRowView)dgContent.CurrentItem).Row);
        //        AddKho addKho = new AddKho(((DataRowView)dgContent.CurrentItem).Row);
        //        addKho.dataGrid = this.dgContent;
        //        addKho.Show();
        //    }
        //    else
        //    {
        //        MessageBox.Show("Không có hàng nào được chọn!");
        //    }
        //}

        private void btnRemove_Click(object sender, RoutedEventArgs e)
        {
            if (dgContent.CurrentItem != null)
            {
                DataRow row = ((DataRowView)dgContent.CurrentItem).Row;
                string  ms  = "Đơn đặt hàng sau khi xóa sẻ không thể khôi phục. Bạn chắn chắn muốn xóa " + row["DatHangId"] + " ?";
                System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show(ms, "Xóa đơn đặt hàng", System.Windows.Forms.MessageBoxButtons.YesNo);
                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    try
                    {
                        QLVTDataSet.CTDatHangDataTable ctdh = new QLVTDataSet.CTDatHangDataTable();
                        DataTable dataTable = ((DataRow[])dgCTContent.ItemsSource).CopyToDataTable();
                        ctdh.Merge(dataTable);
                        foreach (var r in ctdh)
                        {
                            r.Delete();
                        }
                        Common.CTDatHangTableAdapter.Connection = Common.connection;
                        Common.CTDatHangTableAdapter.Update(ctdh);

                        ((DataRowView)dgContent.CurrentItem).Delete();
                        Common.DatHangTableAdapter.Connection = Common.connection;
                        Common.DatHangTableAdapter.Update((QLVTDataSet.DatHangDataTable)dgContent.ItemsSource);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else if (result == System.Windows.Forms.DialogResult.No)
                {
                    //no...
                }
            }
            else
            {
                MessageBox.Show("Không có hàng nào được chọn!");
            }
        }