コード例 #1
0
        private void LayDuLieuKhuyenMai_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            GridControl grid = sender as GridControl;
            ColumnView  view = grid.FocusedView as ColumnView;
            GridHitInfo hi   = view.CalcHitInfo(e.Location) as GridHitInfo;

            if (hi.HitTest == GridHitTest.RowCell)
            {
                string    spid = gvSP.GetFocusedRowCellValue("DTSPID").ToString();
                DsSanPham frm  = new DsSanPham(!gvDH.Editable);
                frm.source.DataSource = GetDataSource(spid);
                frm.StartPosition     = FormStartPosition.CenterScreen;
                var result = frm.ShowDialog();
            }
            return;
        }
コード例 #2
0
        private void KhuyenMaiNhieuSP_CloseUp(object sender, DevExpress.XtraEditors.Controls.CloseUpEventArgs e)
        {
            if (e.Value != null)
            {
                string  spid    = gvSP.GetFocusedRowCellValue("DTSPID").ToString();
                string  nhieuSp = gvSP.GetFocusedRowCellValue("NhieuSP").ToString();
                DataSet dsData  = _data.BsMain.DataSource as DataSet;
                drCurrent = (_data.BsMain.Current as DataRowView).Row;
                var listTable = dsData.Tables;


                DsSanPham frm = new DsSanPham();
                frm.source.DataSource = GetDataSource(spid);
                frm.StartPosition     = FormStartPosition.CenterScreen;
                var result = frm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    if (listTable.Contains("mDTKMNhieuSP"))
                    {
                        var dt = (DataTable)frm.source.DataSource;

                        if (drCurrent.RowState == DataRowState.Added)
                        {
                            var dataRows = dsData.Tables["mDTKMNhieuSP"].Select("DTSPID = " + spid);
                            foreach (var row in dataRows)
                            {
                                dsData.Tables["mDTKMNhieuSP"].Rows.Remove(row);
                            }
                        }

                        foreach (DataRow row in dt.Rows)
                        {
                            if (row.RowState == DataRowState.Added)
                            {
                                DataRow dr = dsData.Tables["mDTKMNhieuSP"].NewRow();
                                if (row["SLTang"] != DBNull.Value && row["MaSPTang"] != DBNull.Value)
                                {
                                    dr["DTSPID"]   = spid;
                                    dr["MaSPTang"] = row["MaSPTang"].ToString();
                                    dr["SLTang"]   = row["SLTang"].ToString();
                                    dsData.Tables["mDTKMNhieuSP"].Rows.Add(dr);
                                }
                            }
                            else if (row.RowState == DataRowState.Modified)
                            {
                                string rowid  = row["DTKMNSPID", DataRowVersion.Original].ToString();
                                var    curRow = dsData.Tables["mDTKMNhieuSP"].Select(string.Format("DTKMNSPID = {0}", rowid));
                                if (curRow.Length > 0)
                                {
                                    curRow[0]["MaSPTang"] = row["MaSPTang"].ToString();
                                    curRow[0]["SLTang"]   = row["SLTang"].ToString();
                                }
                            }
                            else if (row.RowState == DataRowState.Deleted)
                            {
                                string rowid  = row["DTKMNSPID", DataRowVersion.Original].ToString();
                                var    curRow = dsData.Tables["mDTKMNhieuSP"].Select(string.Format("DTKMNSPID = {0}", rowid));
                                if (curRow.Length > 0)
                                {
                                    curRow[0].Delete();
                                }
                            }
                        }

                        var tb = dsData.Tables["mDTKMNhieuSP"];
                    }
                    else
                    {
                        var dt = (DataTable)frm.source.DataSource;
                        foreach (DataRow row in dt.Rows)
                        {
                            if (row.RowState != DataRowState.Deleted)
                            {
                                row["DTSPID"] = spid;
                            }
                        }

                        dt.TableName = "mDTKMNhieuSP";
                        dsData.Tables.Add(dt);
                    }
                }
            }
            else
            {
                DataSet dsData    = _data.BsMain.DataSource as DataSet;
                var     listTable = dsData.Tables;
                string  spid      = gvSP.GetFocusedRowCellValue("DTSPID").ToString();
                if (listTable.Contains("mDTKMNhieuSP"))
                {
                    var dataRows = dsData.Tables["mDTKMNhieuSP"].Select("DTSPID = " + spid);
                    foreach (var row in dataRows)
                    {
                        row.Delete();
                    }
                }
            }
        }