예제 #1
0
파일: Form1.cs 프로젝트: CoKhanh/GitHub
        private void sbtnSave_Click(object sender, EventArgs e)
        {
            if (!txtMaThanhPho.Text.Trim().Equals(""))
            {
                if (add)
                {
                    try
                    {
                        DataClasses1DataContext qlBH = new DataClasses1DataContext();
                        ThanhPho tp = new ThanhPho();
                        tp.ThanhPho1   = txtMaThanhPho.Text;
                        tp.TenThanhPho = txtTenThanhPho.Text;

                        qlBH.ThanhPhos.InsertOnSubmit(tp);
                        qlBH.ThanhPhos.Context.SubmitChanges();

                        LoadData();
                        XtraMessageBox.Show("Done");
                    }
                    catch
                    {
                        XtraMessageBox.Show("ErrorSave");
                    }
                }
                else
                {
                    try
                    {
                        int r = dataGridViewThanhPho.CurrentCell.RowIndex;

                        string strThanhpho = dataGridViewThanhPho.Rows[r].Cells[0].Value.ToString();

                        //SQL
                        DataClasses1DataContext qlBH = new DataClasses1DataContext();
                        var tpQuery = (from tp in qlBH.ThanhPhos where tp.ThanhPho1 == strThanhpho select tp).SingleOrDefault();
                        if (tpQuery != null)
                        {
                            tpQuery.TenThanhPho = txtTenThanhPho.Text;
                            qlBH.SubmitChanges();
                            LoadData();
                        }

                        LoadData();
                        XtraMessageBox.Show("Edit DONE");
                    }
                    catch
                    {
                        XtraMessageBox.Show("Edit error");
                    }
                }
            }
            else
            {
                XtraMessageBox.Show("Invalid ThanhPho");
                txtMaThanhPho.Focus();
            }
        }
예제 #2
0
 partial void UpdateThanhPho(ThanhPho instance);
예제 #3
0
 partial void DeleteThanhPho(ThanhPho instance);
예제 #4
0
 partial void InsertThanhPho(ThanhPho instance);