Пример #1
0
        public int DeleteTraining(ImportTraining obj)
        {
            //1: can't find obj
            Vlu_ChuongTrinhDT objTraining = ObjectContext.Vlu_ChuongTrinhDT.FirstOrDefault(c => c.ID == obj.ID);

            if (objTraining != null)
            {
                ObjectContext.DeleteObject(objTraining);
                ObjectContext.SaveChanges();
            }
            else
            {
                return(1);
            }
            return(0);
        }
Пример #2
0
 public override void Cleanup()
 {
     if (_modelTrain != null)
     {
         _modelTrain.GetListAuthenticationFormComplete -= new EventHandler<ComplexResultsArgs<Authentication>>(_model_GetListAuthenticationFormComplete);
         _modelTrain.GetListTrainingComplete -= new EventHandler<ComplexResultsArgs<ImportTraining>>(_modelTrain_GetListTrainingComplete);
         _modelTrain.DeleteTrainingComplete -= new EventHandler<InvokeOperationEventArgs>(_modelTrain_DeleteTrainingComplete);
         _modelTrain = null;
     }
     _listType = null;
     _listData = null;
     _selectedItem = null;
     if (DialogSended != null)
         DialogSended = null;
     base.Cleanup();
 }
Пример #3
0
        private bool CheckInputData(ImportTraining obj)
        {
            try
            {
                if (obj.MaMonHoc.Trim() == string.Empty)
                    return false;
                if (obj.MaLop.Trim() == string.Empty)
                    return false;
                if (obj.MaKhoa.Trim() == string.Empty)
                    return false;
                if (obj.TenNamHoc.Trim() == string.Empty)
                    return false;
                if (obj.TenHocKy.Trim() == string.Empty)
                    return false;
                try
                {
                    obj.NamHoc = Convert.ToInt32(obj.TenNamHoc);
                    obj.HocKy = Convert.ToInt32(obj.TenHocKy);
                }
                catch
                {
                    return false;
                }

                Vlu_Khoa objKhoa = _listKhoa.FirstOrDefault(c => c.MaKhoa == obj.MaKhoa);
                if (objKhoa != null)
                {
                    obj.KhoaID = objKhoa.KhoaID;
                    obj.TenKhoa = objKhoa.TenKhoa;
                }
                else
                    return false;

                Vlu_LopHoc objLop = _listLop.FirstOrDefault(c => c.MaLop == obj.MaLop);
                if (objLop != null)
                {
                    obj.LopID = objLop.LopID;
                    obj.TenLop = objLop.TenLop;
                }
                else
                    return false;

                Vlu_MonHoc objMonHoc = _listMonHoc.FirstOrDefault(c => c.MaMonHoc == obj.MaMonHoc);
                if (objMonHoc != null)
                {
                    obj.MonHocID = objMonHoc.MonHocID;
                    obj.TenMonHoc = objMonHoc.TenMonHoc;
                    obj.ThuocNhom = objMonHoc.ThuocNhom;
                }
                else
                    return false;

                return true;
            }
            catch
            {
                return false;
            }
        }
Пример #4
0
        public void OnGetFileClickComplete(FileInfo fileOpen)
        {
            try
            {
                Stream s = fileOpen.OpenRead();
                StreamReader reader = new StreamReader(s);
                var xml = reader.ReadToEnd();
                s.Close();
                var doc = XDocument.Parse(xml);
                List<string> listColName = doc.Descendants().Where(c => c.Name.LocalName == "Row").First().Descendants().
                    Where(c => c.Name.LocalName == "Data").Select(c => c.Value).ToList();
                List<ImportTraining> lst = new List<ImportTraining>();
                if (CheckColumns(listColName))
                {
                    int indexRow = 0;
                    string strError = string.Empty;
                    foreach (var row in doc.Descendants().Where(c => c.Name.LocalName == "Row"))
                    {
                        if (indexRow > 0)
                        {
                            if (indexRow == 26)
                            {

                            }
                            List<string> lstData = row.Descendants().Where(c => c.Name.LocalName == "Data").Select(c => c.Value).ToList();
                            if (lstData.Count > 0)
                            {
                                ImportTraining obj = new ImportTraining
                                {
                                    MaLop = (lstData.Count > listColName.IndexOf("MaLop")) ? lstData[listColName.IndexOf("MaLop")].Trim() : string.Empty,
                                    MaKhoa = (lstData.Count > listColName.IndexOf("MaKhoa")) ? lstData[listColName.IndexOf("MaKhoa")].Trim() : string.Empty,
                                    MaMonHoc = (lstData.Count > listColName.IndexOf("MaMonHoc")) ? lstData[listColName.IndexOf("MaMonHoc")].Trim() : string.Empty,
                                    TenNamHoc = (lstData.Count > listColName.IndexOf("NamHoc")) ? lstData[listColName.IndexOf("NamHoc")].Trim() : string.Empty,
                                    TenHocKy = (lstData.Count > listColName.IndexOf("HocKy")) ? lstData[listColName.IndexOf("HocKy")].Trim() : string.Empty
                                };
                                if (CheckInputData(obj))
                                {
                                    if (lst.FirstOrDefault(c => c.KhoaID == obj.KhoaID && c.LopID == obj.LopID && 
                                        c.MonHocID == obj.MonHocID && c.NamHoc == obj.NamHoc && c.HocKy == obj.HocKy) == null)
                                        lst.Add(obj);
                                }
                                else
                                    strError += (indexRow + 1).ToString() + ", ";
                            }
                        }
                        indexRow++;
                    }
                    if (strError == string.Empty)
                    {
                        ListData = lst;
                        TotalRecord = "Tổng: " + lst.Count.ToString();
                    }
                    else
                        MessageCustomize.Show("Kiểm tra dòng " + strError.Substring(0, strError.Length - 2));
                }
            }
            catch (Exception ex)
            {
                MessageCustomize.Show(ex.Message);
            }
        }
Пример #5
0
 public void DeleteTrainingAsync(ImportTraining obj)
 {
     ModelBusiness.DeleteTraining(obj, c =>
         {
             if (DeleteTrainingComplete != null)
                 DeleteTrainingComplete(null, new InvokeOperationEventArgs(c));
         }, null);
 }