예제 #1
0
        private void grdConfirm_OnOk(object sender, RoutedEventArgs e)
        {
            try
            {
                if (Keyboard.FocusedElement.GetType().Equals(typeof(TextBoxAutoComplete)))
                {
                    AutoCompleteTextBox txt = (Keyboard.FocusedElement as TextBoxAutoComplete).ParentControl;
                    if (!txt.CheckLostFocus())
                    {
                        return;
                    }
                }
                if (CheckValid())
                {
                    SysObj.SetSysvar("M_ngay_ct1", txtNgay_ct1.dValue);
                    SysObj.SetSysvar("M_ngay_ct2", txtNgay_ct2.dValue);
                    bool IsshowView = false;

                    GridSearch._GenerateSQLString();
                    GridSearch.GrdSearch.ExecuteCommand(DataPresenterCommands.EndEditModeAndAcceptChanges);

                    StartUp.TransFilterCmd.Parameters["@PhFilter"].Value = GetPhFilterExpr(); // "ngay_ct between '20100101' and '20100131'";
                    StartUp.TransFilterCmd.Parameters["@CtFilter"].Value = GetCtFilterExpr();

                    StartUp.TransFilterCmd.Parameters["@Sl_ct"].Value = 0;

                    DataSet newDs = DataProvider.FillCommand(StartUp.SysObj, StartUp.TransFilterCmd);

                    // xuất thông báo tìm kiếm
                    int     n = 0;
                    Decimal a = (from p
                                 in newDs.Tables[0].AsEnumerable()
                                 select p.Field <Decimal?>("t_tt")).Sum().Value;

                    string  tongPsVND = a.ToString(SysObj.GetOption("M_IP_TIEN").ToString());
                    Decimal tongPsNT  = (from p
                                         in newDs.Tables[0].AsEnumerable()
                                         select p.Field <Decimal?>("t_tt_nt")).Sum().Value;
                    string _tongPsNT = tongPsNT.ToString(SysObj.GetOption("M_IP_TIEN_NT").ToString());
                    n = newDs.Tables[0].Rows.Count;
                    //a = StartUp.DsTrans.Tables[0].AsEnumerable().Sum("t_tt").Value.ToString();
                    if (n > 0)
                    {
                        IsshowView = true;
                        Sm.Windows.Controls.ExMessageBox.Show(410, StartUp.SysObj, "Có " + "[" + n + "]" + " chứng từ. Tổng phát sinh " + "[" + _tongPsNT + "]" + " / " + "[" + tongPsVND + "]", "", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        Sm.Windows.Controls.ExMessageBox.Show(415, StartUp.SysObj, "Không có chứng từ nào như vậy!", "", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    if (IsshowView == true)
                    {
                        // show form View
                        //string stringBrowse1 = "ngay_ct:100:h=Ngày c.từ:FL:D;so_ct:70:h=Số c.từ:FL;so_seri:70:h=Số seri;" +
                        //     "ma_kh:100:h=Mã khách;ten_kh:180:h=Tên khách;dien_giai:225:h=Diễn giải;" +
                        //     "ma_bp:100:h=NVBH;t_tien_nt2:130:h=Tiền hàng nt:N1:S;t_thue_nt:130:h=Tiền thuế nt:N1:S;" +
                        //     "t_tt_nt:130:h=Tổng tt nt:N1:S;ma_nx:80:h=Mã nx;thue_suat:80:h=Thuế suất:F=2;tk_thue_co:80:h=Tk thuế;" +
                        //     "t_tien2:130:h=Tiền hàng:N0:S;t_thue:130:h=Tiền thuế:N0:S;t_tt:130:h=Tổng tt:N0:S;ma_nt:100:h=Mã nt;" +
                        //     "ty_gia:130:h=Tỷ giá:R;date:105:h=Ngày cập nhật:D;time:100:h=Giờ cập nhật;" +
                        //     "user_id:100:h=Số hiệu NSD:N;user_name:100:h=Tên NSD";

                        //string stringBrowse2 = "ma_vt:100:h=Mã vật tư:FL;ten_vt:270:h=Tên vật tư:FL;dvt1:50:h=Ðvt;" +
                        //    "ma_kho_i:70:h=Mã kho;so_luong:130:h=Số lượng:Q:S;gia_nt2:130:h=Giá bán nt:P1;tien_nt2:130:h=Thành tiền nt:N1:S;" +
                        //    "tk_dt:80:h=Tk dt;gia_nt:130:h=Giá vốn nt:P1;tien_nt:130:h=Tiền vốn nt:N1:S;tk_vt:80:h=Tk kho;" +
                        //    "tk_gv:80:h=Tk gv;gia2:130:h=Giá bán:P0;tien2:130:h=Thành tiền:N0:S;" +
                        //    "gia:130:h=Giá vốn:N1;tien:130:h=Tiền vốn:N0:S";

                        SmVoucherLib.FormView _frmView = new SmVoucherLib.FormView(SysObj, newDs.Tables[0].DefaultView, newDs.Tables[1].DefaultView, StartUp.stringBrowse1, StartUp.stringBrowse2, "stt_rec");
                        _frmView.ListFieldSum  = "t_tt_nt;t_tt";
                        _frmView.TongCongLabel = "Tổng thanh toán";
                        if (StartUp.M_LAN.Equals("V"))
                        {
                            _frmView.frmBrw.Title = StartUp.M_Tilte + ". Ky " + txtNgay_ct1.Text + " - " + txtNgay_ct2.Text;
                        }
                        else
                        {
                            _frmView.frmBrw.Title = StartUp.M_Tilte + ". Period " + txtNgay_ct1.Text + " - " + txtNgay_ct2.Text;
                        }
                        //Them cac truong tu do
                        SmVoucherLib.FreeCodeFieldLib.InitFreeCodeField(StartUp.SysObj, _frmView.frmBrw.oBrowseCt, StartUp.Ma_ct, 1);
                        _frmView.frmBrw.LanguageID = "TT_SOCTHDA_HDDT_8";
                        _frmView.ShowDialog();

                        StartUp.DataFilter(StartUp.DsTrans.Tables[0].Rows[0]["stt_rec"].ToString());

                        int Count1 = StartUp.DsTrans.Tables[0].Rows.Count;
                        int Count2 = StartUp.DsTrans.Tables[1].Rows.Count;


                        for (int i = Count1 - 1; i >= 1; i--)
                        {
                            StartUp.DsTrans.Tables[0].Rows.RemoveAt(i);
                        }

                        for (int i = 0; i < Count2; i++)
                        {
                            StartUp.DsTrans.Tables[1].Rows.RemoveAt(0);
                        }



                        int Count = 0;
                        Count = newDs.Tables[0].Rows.Count;
                        for (int i = 0; i < Count; i++)
                        {
                            StartUp.DsTrans.Tables[0].Rows.Add(newDs.Tables[0].Rows[i].ItemArray);
                        }

                        Count = newDs.Tables[1].Rows.Count;
                        for (int i = 0; i < Count; i++)
                        {
                            StartUp.DsTrans.Tables[1].Rows.Add(newDs.Tables[1].Rows[i].ItemArray);
                        }


                        // ko xoá dòng thứ 0 của table[0] vì dòng đó là dòng tạm.

                        if (newDs.Tables[0].Rows.Count > 0)
                        {
                            //Xét lại irow
                            if (FrmTT_SOCTHDA_HDDT.iRow > newDs.Tables[0].Rows.Count - 1)
                            {
                                FrmTT_SOCTHDA_HDDT.iRow = newDs.Tables[0].Rows.Count - 1;
                            }

                            StartUp.DataFilter(StartUp.DsTrans.Tables[0].Rows[FrmTT_SOCTHDA_HDDT.iRow]["stt_rec"].ToString());
                        }

                        // Set lai irow va rowfilter ...
                        if (_frmView.DataGrid.ActiveRecord != null)
                        {
                            int select_irow = (_frmView.DataGrid.ActiveRecord as DataRecord).Index;
                            if (select_irow >= 0)
                            {
                                string selected_stt_rec = (_frmView.DataGrid.DataSource as DataView)[select_irow]["stt_rec"].ToString();
                                FrmTT_SOCTHDA_HDDT.iRow = select_irow + 1;
                                //refresh lại rowfilter
                                StartUp.DataFilter(selected_stt_rec);
                            }
                        }

                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                SmErrorLib.ErrorLog.CatchMessage(ex);
            }
        }