Exemplo n.º 1
0
 private void submitLogin()
 {
     using (snEntities db = DBX.DataSet())
     {
         users user = db.users.Where(u => u.username.Trim() == this.txtUser.Text.Trim() && u.userpassword.Trim() == this.txtPassword.Text.Trim()).FirstOrDefault();
         if (user != null)
         {
             if (user.level == (int)USER_LEVEL.ADMIN)
             {
                 this.loged_in_user = user;
                 this.DialogResult  = DialogResult.OK;
                 this.Close();
             }
             else
             {
                 mac_allowed mac = db.mac_allowed.Where(m => m.mac_address.Trim() == this.main_form.my_mac.Trim()).FirstOrDefault();
                 if (mac != null)
                 {
                     this.loged_in_user = user;
                     this.DialogResult  = DialogResult.OK;
                     this.Close();
                 }
                 else
                 {
                     MessageAlert.Show("เครื่องของท่านไม่ได้รับอนุญาตให้เข้าระบบ", "Error", MessageAlertButtons.OK, MessageAlertIcons.STOP);
                     return;
                 }
             }
         }
         else
         {
             MessageAlert.Show("รหัสผู้ใช้/รหัสผ่าน ไม่ถูกต้อง", "Error", MessageAlertButtons.OK, MessageAlertIcons.STOP);
         }
     }
 }
Exemplo n.º 2
0
        public static options GetOptions(this OPTIONS options_key, SccompDbf selected_comp)
        {
            try
            {
                using (LocalDbEntities db = DBX.DataSet(selected_comp))
                {
                    options opt = db.options.Where(o => o.key == options_key.ToString()).FirstOrDefault();

                    if (opt != null)
                    {
                        return(opt);
                    }
                    else
                    {
                        options o = new options {
                            key = options_key.ToString()
                        };
                        db.options.Add(o);
                        db.SaveChanges();
                        return(o);
                    }
                }
            }
            catch (Exception ex)
            {
                XMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, XMessageBoxIcon.Error);
                return(null);
            }
        }
Exemplo n.º 3
0
        public static int SaveOptions(this options options_to_save, SccompDbf selected_comp)
        {
            try
            {
                using (LocalDbEntities db = DBX.DataSet(selected_comp))
                {
                    options option = db.options.Where(o => o.key == options_to_save.key).FirstOrDefault();
                    if (option != null) // update
                    {
                        option.value_datetime = options_to_save.value_datetime;
                        option.value_num      = options_to_save.value_num;
                        option.value_str      = options_to_save.value_str;

                        return(db.SaveChanges());
                    }
                    else // add new
                    {
                        db.options.Add(options_to_save);
                        return(db.SaveChanges());
                    }
                }
            }
            catch (Exception ex)
            {
                XMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, XMessageBoxIcon.Error);
                return(0);
            }
        }
Exemplo n.º 4
0
        private void GetBojData()
        {
            this.isinfo = DbfTable.GetIsinfo(this.main_form.selected_comp);
            using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp))
            {
                this.boj5_header = db.boj5_header.FirstOrDefault();
                if (this.boj5_header == null)
                {
                    db.boj5_header.Add(new boj5_header
                    {
                        accSource          = ACC_SOURCE.B.ToString(),
                        foreignShareholder = 0,
                        headerStatus       = "A",
                        meetingNo          = "",
                        meetingType        = MEETING_TYPE.B.ToString(),
                        parValue           = 0,
                        sourceDate         = null,
                        thaiShareholder    = 0,
                        totalCapital       = 0,
                        totalForeignShare  = 0,
                        totalShare         = 0,
                        totalThaiShare     = 0,
                        userId             = "",
                        yearEnd            = null
                    });
                    db.SaveChanges();

                    this.boj5_header = db.boj5_header.First();
                }

                this.boj5_detail = db.boj5_detail.Include("boj5_person").OrderBy(d => d.itemNo).ToList();
            }
        }
Exemplo n.º 5
0
 private void LoadPersonToDatagrid()
 {
     using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp))
     {
         this.person_list = new BindingList <boj5_person_VM>(db.boj5_person.OrderBy(p => p.itemSeq).ToList().ToViewModel());
         this.person_list.ToList().ForEach(i =>
         {
             if (i.boj5_person.id == this.boj5_detail.boj5_person_id)
             {
                 i.selected = true;
             }
         });
         this.dgvPerson.DataSource = this.person_list;
     }
 }
Exemplo n.º 6
0
        private void btnDown_Click(object sender, EventArgs e)
        {
            if (this.dgvPerson.CurrentCell.RowIndex == this.dgvPerson.Rows.Count - 1 || this.dgvPerson.Rows.Count <= 1)
            {
                return;
            }

            using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp))
            {
                if (db.boj5_person.Count() <= 1)
                {
                    return;
                }

                var curr_person = db.boj5_person.Find(((boj5_person)(this.dgvPerson).Rows[this.dgvPerson.CurrentCell.RowIndex].Cells[this.col_boj5_person.Name].Value).id);
                if (curr_person == null)
                {
                    XMessageBox.Show("ค้นหารายการที่ต้องการแก้ไขไม่พบ", "", MessageBoxButtons.OK, XMessageBoxIcon.Stop);
                    return;
                }

                var next_person = db.boj5_person.Where(p => p.itemSeq > curr_person.itemSeq).OrderBy(p => p.itemSeq).FirstOrDefault();
                if (next_person == null)
                {
                    XMessageBox.Show("รายการนี้อยู่ในลำดับสุดท้ายแล้ว ไม่สามารถเลื่อนลงได้อีก", "", MessageBoxButtons.OK, XMessageBoxIcon.Stop);
                    return;
                }

                long?curr_seq = curr_person.itemSeq;
                long?next_seq = next_person.itemSeq;
                curr_person.itemSeq = next_seq;
                next_person.itemSeq = curr_seq;
                db.SaveChanges();

                long?seq = 0;
                db.boj5_detail.Include("boj5_person").OrderBy(d => d.boj5_person.itemSeq).ToList().ForEach(d => d.itemNo = ++seq);
                db.SaveChanges();

                this.LoadPersonToDatagrid();

                var selected_row = this.dgvPerson.Rows.Cast <DataGridViewRow>().Where(r => ((boj5_person)r.Cells[this.col_boj5_person.Name].Value).id == curr_person.id).FirstOrDefault();
                if (selected_row != null)
                {
                    selected_row.Cells[selected_row.DataGridView.FirstDisplayedScrollingColumnIndex].Selected = true;
                }
            }
        }
Exemplo n.º 7
0
        private void btnDeleteItem_Click(object sender, EventArgs e)
        {
            if (this.dgv.CurrentCell == null)
            {
                return;
            }

            this.dgv.Rows[this.dgv.CurrentCell.RowIndex].DrawDeletingRowOverlay();
            if (XMessageBox.Show("ลบรายการที่เลือก, ทำต่อหรือไม่?", "", MessageBoxButtons.OKCancel, XMessageBoxIcon.Question) != DialogResult.OK)
            {
                this.dgv.Rows[this.dgv.CurrentCell.RowIndex].ClearDeletingRowOverlay();
                return;
            }

            var deleting_id = ((boj5_detail)this.dgv.Rows[this.dgv.CurrentCell.RowIndex].Cells[this.col_boj5_detail.Name].Value).id;

            try
            {
                using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp))
                {
                    var deleting_data = db.boj5_detail.Find(deleting_id);
                    if (deleting_data != null)
                    {
                        db.boj5_detail.Remove(deleting_data);
                        db.SaveChanges();

                        long?seq = 0;
                        db.boj5_detail.Include("boj5_person").OrderBy(d => d.boj5_person.itemSeq).ToList().ForEach(d => d.itemNo = ++seq);
                        db.SaveChanges();

                        this.GetBojData();
                        this.FillForm(this.boj5_header, this.boj5_detail);
                    }
                    else
                    {
                        XMessageBox.Show("ค้นหารายการที่ต้องการลบไม่พบ", "", MessageBoxButtons.OK, XMessageBoxIcon.Stop);
                    }
                }
            }
            catch (Exception ex)
            {
                XMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, XMessageBoxIcon.Error);
            }
        }
Exemplo n.º 8
0
        private void IstabListDialog_Load(object sender, EventArgs e)
        {
            this.SetBounds(this.point_to_screen.X, this.point_to_screen.Y, this.Width, this.Height);
            this.bs             = new BindingSource();
            this.bs.DataSource  = this.istabs;
            this.dgv.DataSource = this.bs;

            using (snEntities db = DBX.DataSet())
            {
                this.istabs = db.istab.Where(i => i.tabtyp == this.tabtyp).ToList().ToViewModel();
                this.bs.ResetBindings(true);
                this.bs.DataSource = this.istabs;
            }

            istabVM istab = this.istabs.Where(i => i.typcod == this.initial_typcod).FirstOrDefault();

            if (istab != null)
            {
                this.dgv.Rows.Cast <DataGridViewRow>().Where(r => (string)r.Cells["col_typcod"].Value == this.initial_typcod).First().Cells["col_typcod"].Selected = true;
            }
        }
Exemplo n.º 9
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.tmp_boj5_header == null)
            {
                return;
            }
            try
            {
                using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp))
                {
                    var header_to_update = db.boj5_header.Find(1);
                    header_to_update.accSource          = this.tmp_boj5_header.accSource;
                    header_to_update.foreignShareholder = this.tmp_boj5_header.foreignShareholder;
                    header_to_update.headerStatus       = this.tmp_boj5_header.headerStatus;
                    header_to_update.meetingNo          = this.tmp_boj5_header.meetingNo;
                    header_to_update.meetingType        = this.tmp_boj5_header.meetingType;
                    header_to_update.parValue           = this.tmp_boj5_header.parValue;
                    header_to_update.sourceDate         = this.tmp_boj5_header.sourceDate;
                    header_to_update.thaiShareholder    = this.tmp_boj5_header.thaiShareholder;
                    header_to_update.totalCapital       = this.tmp_boj5_header.totalCapital;
                    header_to_update.totalForeignShare  = this.tmp_boj5_header.totalForeignShare;
                    header_to_update.totalShare         = this.tmp_boj5_header.totalShare;
                    header_to_update.totalThaiShare     = this.tmp_boj5_header.totalThaiShare;
                    header_to_update.userId             = this.tmp_boj5_header.userId;
                    header_to_update.yearEnd            = this.tmp_boj5_header.yearEnd;

                    db.SaveChanges();
                }

                this.tmp_boj5_header = null;
                this.ResetFormState(FORM_MODE.READ);
                this.GetBojData();
                this.FillForm(this.boj5_header, this.boj5_detail);
            }
            catch (Exception ex)
            {
                XMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, XMessageBoxIcon.Error);
            }
        }
Exemplo n.º 10
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp))
            {
                this.tmp_boj5_header = db.boj5_header.First();
                this.FillForm(this.tmp_boj5_header, this.boj5_detail);
            }

            this.ResetFormState(FORM_MODE.EDIT);
            this.cAccSource.Focus();

            //using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp))
            //{
            //    db.glacc_match.Add(new glacc_match { accnum = "1234-56", depcod = "ขาย 2", taxodesc = "TAXO 1", taxodesc2 = "TAXO 2" });
            //    db.boj5_person.Add(new boj5_person { holderName = "วีรวัฒน์ ตรุเจตนารมย์", addrFull = "kanasiri" });
            //    db.boj5_person.Add(new boj5_person { holderName = "รฐา ตรุเจตนารมย์", addrFull = "kanasiri" });
            //    db.SaveChanges();
            //    var a = db.glacc_match.ToList();
            //    var b = db.boj5_detail.ToList();
            //    var c = db.boj5_header.ToList();
            //    var d = db.boj5_person.ToList();
            //    Console.WriteLine(" ==> ok");
            //}
        }
Exemplo n.º 11
0
        private void btnDeleteHolder_Click(object sender, EventArgs e)
        {
            if (this.dgvPerson.CurrentCell == null)
            {
                return;
            }

            this.dgvPerson.Rows[this.dgvPerson.CurrentCell.RowIndex].DrawDeletingRowOverlay();

            try
            {
                using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp))
                {
                    var         deleting_id = ((boj5_person)this.dgvPerson.Rows[this.dgvPerson.CurrentCell.RowIndex].Cells[this.col_boj5_person.Name].Value).id;
                    boj5_person person_to_delete;

                    if (db.boj5_detail.Where(d => d.boj5_person_id == deleting_id).Count() > 0)
                    {
                        if (XMessageBox.Show("มีรายการใบหุ้นของผู้ถือหุ้นรายนี้อยู่\n - เลือก \"ตกลง\" เพื่อให้ลบทั้งรายการใบหุ้น และ ชื่อผู้ถือหุ้นรายนี้\n - เลือก \"ยกเลิก\" เพื่อยกเลิกการทำงานนี้", "", MessageBoxButtons.OKCancel, XMessageBoxIcon.Question) == DialogResult.OK)
                        {
                            person_to_delete = db.boj5_person.Find(deleting_id);
                            if (person_to_delete != null)
                            {
                                db.boj5_detail.RemoveRange(db.boj5_detail.Where(d => d.boj5_person_id == deleting_id));
                                db.boj5_person.Remove(db.boj5_person.Find(deleting_id));
                                db.SaveChanges();

                                long?seq = 0;
                                db.boj5_person.ToList().ForEach(p => p.itemSeq = ++seq);
                                db.SaveChanges();

                                this.LoadPersonToDatagrid();
                            }
                            else
                            {
                                XMessageBox.Show("ค้นหารายการที่ต้องการลบไม่พบ", "", MessageBoxButtons.OK, XMessageBoxIcon.Stop);
                                this.LoadPersonToDatagrid();
                            }
                        }
                        else
                        {
                            this.dgvPerson.Rows[this.dgvPerson.CurrentCell.RowIndex].ClearDeletingRowOverlay();
                        }
                        return;
                    }
                    else
                    {
                        if (XMessageBox.Show("ลบรายการที่เลือก, ทำต่อหรือไม่?", "", MessageBoxButtons.OKCancel, XMessageBoxIcon.Question) != DialogResult.OK)
                        {
                            this.dgvPerson.Rows[this.dgvPerson.CurrentCell.RowIndex].ClearDeletingRowOverlay();
                        }

                        person_to_delete = db.boj5_person.Find(deleting_id);
                        if (person_to_delete != null)
                        {
                            db.boj5_person.Remove(person_to_delete);
                            db.SaveChanges();

                            long?seq = 0;
                            db.boj5_person.ToList().ForEach(p => p.itemSeq = ++seq);
                            db.SaveChanges();
                            this.LoadPersonToDatagrid();
                        }
                        else
                        {
                            XMessageBox.Show("ค้นหารายการที่ต้องการลบไม่พบ", "", MessageBoxButtons.OK, XMessageBoxIcon.Stop);
                            this.LoadPersonToDatagrid();
                        }
                    }

                    long?itemno = 0;
                    db.boj5_detail.Include("boj5_person").OrderBy(d => d.boj5_person.itemSeq).ToList().ForEach(d => d.itemNo = ++itemno);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                XMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, XMessageBoxIcon.Error);
            }
        }
Exemplo n.º 12
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this.boj5_detail.shareDocId.Trim().Length == 0)
            {
                XMessageBox.Show("กรุณาระบุหมายเลขใบหุ้น", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning);
                this.cShareDocId.Focus();
                return;
            }

            if (this.boj5_detail.boj5_person_id == -1)
            {
                XMessageBox.Show("กรุณาระบุผู้ถือหุ้น", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning);
                //this.cHolderId.Focus();
                this.dgvPerson.Focus();
                return;
            }

            if (this.boj5_detail.shareNumber == 0)
            {
                XMessageBox.Show("กรุณาระบุจำนวนหุ้น", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning);
                this.cShareNumber.Focus();
                return;
            }

            if (!this.boj5_detail.shareDocDate.HasValue)
            {
                XMessageBox.Show("กรุณาระบุวันที่ออกเลขที่ใบหุ้น", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning);
                this.cShareDocDate.Focus();
                return;
            }

            if (!this.boj5_detail.shareRegExist.HasValue)
            {
                XMessageBox.Show("กรุณาระบุวันที่ลงทะเบียนผู้ถือหุ้น", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning);
                this.cShareRegExist.Focus();
                return;
            }

            try
            {
                using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp))
                {
                    if (this.boj5_detail.id > 0) // edit
                    {
                        var data_to_update = db.boj5_detail.Find(this.boj5_detail.id);
                        if (data_to_update == null)
                        {
                            db.boj5_detail.Add(this.boj5_detail);
                        }
                        else
                        {
                            data_to_update.asPaidAmount   = this.boj5_detail.asPaidAmount;
                            data_to_update.boj5_person_id = this.boj5_detail.boj5_person_id;
                            data_to_update.paidAmount     = this.boj5_detail.paidAmount;
                            data_to_update.shareDocDate   = this.boj5_detail.shareDocDate;
                            data_to_update.shareDocId     = this.boj5_detail.shareDocId;
                            data_to_update.shareNumber    = this.boj5_detail.shareNumber;
                            data_to_update.shareRegExist  = this.boj5_detail.shareRegExist;
                            data_to_update.shareRegOmit   = this.boj5_detail.shareRegOmit;
                            data_to_update.shareType      = this.boj5_detail.shareType;
                        }
                    }
                    else // add
                    {
                        db.boj5_detail.Add(this.boj5_detail);
                    }

                    db.SaveChanges();

                    long?seq = 0;
                    db.boj5_detail.Include("boj5_person").OrderBy(d => d.boj5_person.itemSeq).ToList().ForEach(d => d.itemNo = ++seq);
                    db.SaveChanges();

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                XMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, XMessageBoxIcon.Error);
            }
        }
Exemplo n.º 13
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this.boj5_person.shType.Trim().Length == 0)
            {
                XMessageBox.Show("กรุณาระบุประเภทของผู้ถือหุ้น", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning);
                this.cShType.Focus();
                return;
            }

            if (this.boj5_person.holderName.Trim().Length == 0)
            {
                XMessageBox.Show("กรุณาระบุชื่อผู้ถือหุ้น", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning);
                this.cHolderName.Focus();
                return;
            }

            if (this.boj5_person.nationality.Trim().Length == 0)
            {
                XMessageBox.Show("กรุณาระบุสัญชาติของผู้ถือหุ้น", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning);
                this.cNationality.Focus();
                return;
            }

            if (this.boj5_person.shId.Trim().Length == 0)
            {
                XMessageBox.Show("กรุณาระบุเลขนิติบุคคล/บัตรประชาชน", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning);
                this.cShId.Focus();
                return;
            }
            try
            {
                using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp))
                {
                    if (this.boj5_person.id > 0) // edit
                    {
                        var data_to_update = db.boj5_person.Find(this.boj5_person.id);
                        if (data_to_update == null)
                        {
                            db.boj5_person.Add(this.boj5_person);
                        }
                        else
                        {
                            data_to_update.addrForeign = this.boj5_person.addrForeign;
                            data_to_update.addrFull    = this.boj5_person.addrFull;
                            data_to_update.addrNo      = this.boj5_person.addrNo;
                            data_to_update.amphur      = this.boj5_person.amphur;
                            data_to_update.holderName  = this.boj5_person.holderName;
                            data_to_update.itemSeq     = this.boj5_person.itemSeq;
                            data_to_update.moo         = this.boj5_person.moo;
                            data_to_update.nationality = this.boj5_person.nationality;
                            data_to_update.occupation  = this.boj5_person.occupation;
                            data_to_update.province    = this.boj5_person.province;
                            data_to_update.road        = this.boj5_person.road;
                            data_to_update.shId        = this.boj5_person.shId;
                            data_to_update.shType      = this.boj5_person.shType;
                            data_to_update.soi         = this.boj5_person.soi;
                            data_to_update.surname     = this.boj5_person.surname;
                            data_to_update.title       = this.boj5_person.title;
                            data_to_update.tumbol      = this.boj5_person.tumbol;
                        }
                    }
                    else // add
                    {
                        db.boj5_person.Add(this.boj5_person);
                    }
                    db.SaveChanges();

                    long?seq = 0;
                    db.boj5_person.ToList().ForEach(p => p.itemSeq = ++seq);
                    db.SaveChanges();

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                XMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, XMessageBoxIcon.Error);
            }
        }