Ejemplo n.º 1
0
        private void ImportData()
        {
            try
            {
                using (DataClasses1DataContext db = new DataClasses1DataContext())
                {
                    foreach (DataRow rd in dt.Rows)
                    {
                        if (!rd["YYYY"].ToString().Equals("0") && !rd["MMM"].ToString().Equals("0"))
                        {
                            int     yyyy = 0;
                            int     mmm  = 0;
                            decimal wk   = 0;
                            int.TryParse(Convert.ToString(rd["YYYY"].ToString()), out yyyy);
                            int.TryParse(Convert.ToString(rd["MMM"].ToString()), out mmm);
                            decimal.TryParse(Convert.ToString(rd["WorkDays"].ToString()), out wk);

                            var x = (from ix in db.tb_WorkDays where ix.YYYY == yyyy && ix.MMM == mmm select ix).FirstOrDefault();
                            if (yyyy > 0 && mmm > 0 && wk > 0)
                            {
                                if (x == null)
                                {
                                    tb_WorkDay ts = new tb_WorkDay();
                                    ts.YYYY     = yyyy;
                                    ts.MMM      = mmm;
                                    ts.WorkDays = wk;
                                    db.tb_WorkDays.InsertOnSubmit(ts);
                                    db.SubmitChanges();
                                }
                                else
                                {
                                    x.WorkDays = wk;

                                    db.SubmitChanges();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message);
                                   dbClss.AddError("InportData", ex.Message, this.Name); }
        }
Ejemplo n.º 2
0
        private bool AddUnit()
        {
            bool ck = false;
            int  C  = 0;

            try
            {
                radGridView1.EndEdit();
                using (DataClasses1DataContext db = new DataClasses1DataContext())
                {
                    foreach (var g in radGridView1.Rows)
                    {
                        if (!Convert.ToString(g.Cells["YYYY"].Value).Equals("") &&
                            !Convert.ToString(g.Cells["MMM"].Value).Equals(""))
                        {
                            if (Convert.ToString(g.Cells["dgvC"].Value).Equals("T"))
                            {
                                int     yyyy = 0;
                                int     mmm  = 0;
                                decimal wk   = 0;
                                int.TryParse(Convert.ToString(g.Cells["YYYY"].Value), out yyyy);
                                int.TryParse(Convert.ToString(g.Cells["MMM"].Value), out mmm);
                                decimal.TryParse(Convert.ToString(g.Cells["WorkDays"].Value), out wk);
                                if (Convert.ToString(g.Cells["dgvCodeTemp"].Value).Equals(""))
                                {
                                    // MessageBox.Show("11");
                                    if (yyyy > 0 && mmm > 0 && wk > 0)
                                    {
                                        tb_WorkDay u = new tb_WorkDay();

                                        u.YYYY     = yyyy;
                                        u.MMM      = mmm;
                                        u.WorkDays = wk;
                                        db.tb_WorkDays.InsertOnSubmit(u);
                                        db.SubmitChanges();
                                        C += 1;
                                        dbClss.AddHistory(this.Name, "เพิ่ม", "Working Days [" + u.YYYY + "," + u.MMM + "]", "");
                                    }
                                }
                                else
                                {
                                    var unit1 = (from ix in db.tb_WorkDays
                                                 where ix.YYYY == Convert.ToInt32(g.Cells["dgvCodeTemp"].Value) &&
                                                 ix.MMM == Convert.ToInt32(g.Cells["dgvCodeTemp2"].Value)
                                                 select ix).First();
                                    unit1.WorkDays = wk;

                                    C += 1;

                                    db.SubmitChanges();
                                    dbClss.AddHistory(this.Name, "แก้ไข", "Update Working Days[" + unit1.YYYY + ", " + unit1.MMM + "]", "");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message);
                                   dbClss.AddError("AddUnit", ex.Message, this.Name); }

            if (C > 0)
            {
                MessageBox.Show("บันทึกสำเร็จ!");
            }

            return(ck);
        }