Ejemplo n.º 1
0
        private void btadd_Click(object sender, EventArgs e)
        {
            int oritotalrow = gvunit.Rows.Count;

            var form = new ManageUnit();

            form.userdata = userdata;
            form.ShowDialog();
            LoadData();

            int newtotalrow = gvunit.Rows.Count;

            if (oritotalrow != newtotalrow)
            {
                var newUnit = new UnitColumns();
                newUnit = unitRepository.GetByAny(1);
                int newId = newUnit.unitid;

                foreach (DataGridViewRow row in gvunit.Rows)
                {
                    if (((int)row.Cells["id"].Value) == newId)
                    {
                        gvunit.Rows[row.Index].Selected = true;
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void btsave_Click(object sender, EventArgs e)
        {
            ListUnit = unitRepo.GetAll();
            int samename = 0;
            int samecode = 0;


            if (Editmode)
            {
                foreach (var existingdetails in ListUnit)
                {
                    if (existingdetails.name == tbunitname.Text && existingdetails.unitid != UnitData.unitid)
                    {
                        samename += 1;
                        break;
                    }
                    else if (existingdetails.unitcode == tbunitcode.Text && existingdetails.unitid != UnitData.unitid)
                    {
                        samecode += 1;
                        break;
                    }
                }


                if (tbunitcode.Text == "" || tbunitname.Text == "")
                {
                    MessageBox.Show("Yang bertanda Bintang tidak boleh kosong");
                }
                else if (samename > 0)
                {
                    MessageBox.Show("Nama yang anda masukkan sudah terdaftar");
                    samename = 0;
                }
                else if (samecode > 0)
                {
                    MessageBox.Show("Kode yang anda masukkan sudah terdaftar");
                    samecode = 0;
                }
                else
                {
                    var DataBefore = new UnitColumns();
                    DataBefore.name     = UnitData.name;
                    DataBefore.remark   = UnitData.remark;
                    DataBefore.unitcode = UnitData.unitcode;

                    UnitData.name       = tbunitname.Text;
                    UnitData.remark     = tbremark.Text;
                    UnitData.updated_by = userdata.username;
                    UnitData.unitcode   = tbunitcode.Text;

                    bool havechanges = false;

                    if (DataBefore.name == UnitData.name && DataBefore.remark == UnitData.remark && DataBefore.unitcode == UnitData.unitcode)
                    {
                        havechanges = true;
                    }


                    if (havechanges)
                    {
                        MessageBox.Show("Tidak ada data yang anda ubah");
                        UnitData.name     = DataBefore.name;
                        UnitData.remark   = DataBefore.remark;
                        UnitData.unitcode = DataBefore.unitcode;
                    }
                    else if (unitRepo.Update(UnitData))
                    {
                        MessageBox.Show("Data telah berhasil di ubah");
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("Data gagal di ubah");
                        UnitData.name     = DataBefore.name;
                        UnitData.remark   = DataBefore.remark;
                        UnitData.unitcode = DataBefore.unitcode;
                    }
                }
            }
            else
            {
                foreach (var existingdetails in ListUnit)
                {
                    if (existingdetails.name == tbunitname.Text)
                    {
                        samename += 1;
                        break;
                    }
                    else if (existingdetails.unitcode == tbunitcode.Text)
                    {
                        samecode += 1;
                    }
                }

                if (tbunitcode.Text == "" || tbunitname.Text == "")
                {
                    MessageBox.Show(" Yang bertanda Bintang tidak boleh kosong");
                }
                else if (samename > 0)
                {
                    MessageBox.Show("Nama yang anda masukkan sudah terdaftar");
                    samename = 0;
                }
                else if (samecode > 0)
                {
                    MessageBox.Show("Kemasan yang anda masukkan sudah terdaftar");
                    samecode = 0;
                }
                else
                {
                    var NewUnit = new UnitColumns();

                    NewUnit.name       = tbunitname.Text;
                    NewUnit.remark     = tbremark.Text;
                    NewUnit.created_by = userdata.username;
                    NewUnit.unitcode   = tbunitcode.Text;


                    if (unitRepo.Add(NewUnit))
                    {
                        MessageBox.Show("Data baru telah berhasil di tambahkan");
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("Data baru gagal ditambahkan");
                    }
                }
            }
        }