Esempio n. 1
0
        private void ImportData()
        {
            try
            {
                using (DataClasses1DataContext db = new DataClasses1DataContext())
                {
                    foreach (DataRow rd in dt.Rows)
                    {
                        if (!rd["GroupCode"].ToString().Equals(""))
                        {
                            var x = (from ix in db.tb_GroupTypes where ix.GroupCode.ToLower().Trim() == rd["GroupCode"].ToString().ToLower().Trim() select ix).FirstOrDefault();

                            if (x == null)
                            {
                                tb_GroupType ts = new tb_GroupType();
                                ts.GroupCode   = Convert.ToString(rd["GroupCode"].ToString());
                                ts.GroupName   = Convert.ToString(rd["GroupName"].ToString());
                                ts.GroupActive = Convert.ToBoolean(rd["GroupActive"].ToString());
                                db.tb_GroupTypes.InsertOnSubmit(ts);
                                db.SubmitChanges();
                            }
                            else
                            {
                                x.GroupName   = Convert.ToString(rd["GroupName"].ToString());
                                x.GroupActive = Convert.ToBoolean(rd["GroupActive"].ToString());
                                db.SubmitChanges();
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message);
                                   dbClss.AddError("InportData", ex.Message, this.Name); }
        }
Esempio 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["GroupCode"].Value).Equals(""))
                        {
                            if (Convert.ToString(g.Cells["dgvC"].Value).Equals("T"))
                            {
                                if (Convert.ToString(g.Cells["dgvCodeTemp"].Value).Equals(""))
                                {
                                    // MessageBox.Show("11");


                                    tb_GroupType gy = new tb_GroupType();
                                    gy.GroupCode   = Convert.ToString(g.Cells["GroupCode"].Value);
                                    gy.GroupActive = Convert.ToBoolean(g.Cells["GroupActive"].Value);
                                    gy.GroupName   = Convert.ToString(g.Cells["GroupName"].Value);
                                    gy.Running     = Convert.ToString(g.Cells["Running"].Value);
                                    db.tb_GroupTypes.InsertOnSubmit(gy);
                                    db.SubmitChanges();
                                    C += 1;
                                    dbClss.AddHistory(this.Name, "เพิ่มประเภทกลุ่ม", "Insert Group Code [" + gy.GroupName + "]", "");
                                }
                                else
                                {
                                    var unit1 = (from ix in db.tb_GroupTypes
                                                 where ix.GroupCode == Convert.ToString(g.Cells["dgvCodeTemp"].Value)
                                                 select ix).First();
                                    unit1.GroupName   = Convert.ToString(g.Cells["GroupName"].Value);
                                    unit1.GroupActive = Convert.ToBoolean(g.Cells["GroupActive"].Value);
                                    unit1.Running     = Convert.ToString(g.Cells["Running"].Value);

                                    C += 1;

                                    db.SubmitChanges();
                                    dbClss.AddHistory(this.Name, "แก้ไข", "Update Group Code [" + unit1.GroupName + "]", "");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message);
                                   dbClss.AddError("เพิ่มปรเภทกลุ่ม", ex.Message, this.Name); }

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

            return(ck);
        }