protected void btnInsert_Click(object sender, EventArgs e)
    {
        bool isValidOperation = true;
        string insertQuery = "";
        SqlDataReader listDaySession;
        if (txtComCode.Text != "" && ddlTutor.SelectedValue != "")
        {
            string DaySession;
            DBCon myCon2 = new DBCon();
            string query = "select DaySession from tblCourseTeacherMap where ComCod = '" + ddlCourseTitle.SelectedValue + "' and TeacherID = '" + ddlTutor.SelectedValue + "'";
            if (ddlOperation.SelectedValue == "Insert")
            {
                myCon.ConOpen();
                listDaySession = myCon.ExecuteReader(query);
                while (listDaySession.Read() && isValidOperation)
                {
                    DaySession = listDaySession.GetString(0);
                    string checkQuery = "select count(*) from tblStudentCourseMap where DaySession = '" + DaySession + "'";
                    int Occurence = myCon2.ExecuteScalarInt(checkQuery);
                    if (Occurence > 0)
                    {
                        Response.Write("<script LANGUAGE='JavaScript' >alert('" + DaySession + " has another entry, aborting operation. Please remove entry and try again.');</script>");
                        isValidOperation = false;
                        break;
                    }
                }
                myCon.ConClose();
            }

            myCon.ConOpen();
            query = "select DaySession from tblCourseTeacherMap where ComCod = '" + ddlCourseTitle.SelectedValue + "' and TeacherID = '" + ddlTutor.SelectedValue + "'";
            listDaySession = myCon.ExecuteReader(query);
            while (listDaySession.Read() && isValidOperation)
            {
                DaySession = listDaySession.GetString(0);
                if (ddlOperation.SelectedValue == "Insert")
                {
                    insertQuery = "insert into tblStudentCourseMap(StudentID,ComCod,DaySession,TeacherID) values ('" + Current_User_ID + "','" + txtComCode.Text + "','" + DaySession + "','" + ddlTutor.SelectedValue + "')";
                }
                else
                {
                    if (ddlOperation.SelectedValue == "Remove")
                    {
                        insertQuery = "Delete from tblStudentCourseMap where StudentID = '" + Current_User_ID + "' and ComCod = '" + txtComCode.Text + "' and DaySession = '" + DaySession + "' and TeacherID = '" + ddlTutor.SelectedValue + "'";
                    }
                }
                myCon2.ExecuteNonQuery(insertQuery);
            }
            myCon.ConClose();
            if (isValidOperation)
            {
                Make_Dirty_Approval_Status();
                Response.Redirect(Request.RawUrl);
            }
        }
    }
Esempio n. 2
0
        private void deleteImagesThreadMethod()
        {
            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_DELETING_GRABBED_IMAGES, STR_DELETING_IMAGES, _gcList.Count, 0, true))
            {
                try
                {
                    int    block = 0;
                    string fnp   = System.IO.Path.Combine(PluginSettings.Instance.ActiveDataPath, IMG_SUBFOLDER);
                    for (int i = 0; i < _gcList.Count; i++)
                    {
                        DbDataReader dr = _dbcon.ExecuteReader(string.Format("select local_file from images where gccode='{0}'", _gcList[i].Code.Replace("'", "''")));
                        while (dr.Read())
                        {
                            string fn = System.IO.Path.Combine(fnp, dr.GetString(0));
                            try
                            {
                                if (System.IO.File.Exists(fn))
                                {
                                    System.IO.File.Delete(fn);
                                }
                            }
                            catch
                            {
                            }
                        }
                        _dbcon.ExecuteNonQuery(string.Format("delete from images where gccode='{0}'", _gcList[i].Code.Replace("'", "''")));

                        block++;
                        if (block > 10)
                        {
                            block = 0;
                            if (!progress.UpdateProgress(STR_DELETING_GRABBED_IMAGES, STR_DELETING_IMAGES, _gcList.Count, i))
                            {
                                break;
                            }
                        }
                    }
                }
                catch
                {
                }
            }
        }
Esempio n. 3
0
        private bool InitDatabase()
        {
            CloseDatabase();
            bool result = false;

            try
            {
                _dbcon = new DBConComSqlite(DatabaseFilename);
                object o = _dbcon.ExecuteScalar("SELECT name FROM sqlite_master WHERE type='table' AND name='images'");
                if (o == null || o.GetType() == typeof(DBNull))
                {
                    _dbcon.ExecuteNonQuery("create table 'images' (org_url text, gccode text, local_file text)");
                    _dbcon.ExecuteNonQuery("create index idx_images on images (org_url)");
                }
                result = true;
            }
            catch
            {
            }
            return(result);
        }
        public void ExecuteNonQuery(string 프로시저명)
        {
            int i = 0;

            SqlParameter[] sqlParam = null;

            DBCon dbCon = null;

            DataSet 라미터 = this.GetDS();

            try
            {
                dbCon = new DBCon(DB연결문자());

                sqlParam = new SqlParameter[라미터.Tables[0].Rows.Count];
                //sqlParam = new SqlParameter[파라미터.Tables[0].Rows.Count - 2];
                //sqlParam = new SqlParameter[파라미터.Tables[0].Rows.Count - 1];

                foreach (DataRow dr in  라미터.Tables[0].Rows)
                {
                    sqlParam[i] = new SqlParameter();
                    sqlParam[i].ParameterName = dr["컬럼명"].ToString();
                    sqlParam[i].SqlDbType     = DataType(dr["타입"].ToString());
                    sqlParam[i].Size          = Convert.ToInt32(dr["사이즈"].ToString());

                    if (dr["값"].ToString().ToUpper() == "NULL")
                    {
                        sqlParam[i].Value = DBNull.Value;
                    }
                    else
                    {
                        sqlParam[i].Value = dr["값"].ToString();
                    }

                    i++;
                }

                dbCon.ExecuteNonQuery(프로시저명, sqlParam, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 5
0
        public async Task DownloadImagesAsync(List <Core.Data.Geocache> gcList, bool updateExisting)
        {
            await Task.Run(async() =>
            {
                bool cancel = false;
                ConcurrentQueue <Core.Data.Geocache> cq = new ConcurrentQueue <Core.Data.Geocache>();
                foreach (var gc in gcList)
                {
                    cq.Enqueue(gc);
                }

                using (Utils.ProgressBlock prog = new ProgressBlock("DownloadingImages", "DownloadingImages", gcList.Count, 0, true))
                {
                    Action actionUpdateProgress = () =>
                    {
                        DateTime updateAt = DateTime.MinValue;
                        int cnt           = cq.Count;
                        while (cnt > 0)
                        {
                            if (DateTime.Now >= updateAt)
                            {
                                if (!prog.Update("DownloadingImages", gcList.Count, gcList.Count - cnt))
                                {
                                    cancel = true;
                                    break;
                                }
                                updateAt = DateTime.Now.AddSeconds(1);
                            }
                            System.Threading.Thread.Sleep(200);
                            cnt = cq.Count;
                        }
                        ;
                    };

                    Action actionDownload = () =>
                    {
                        Core.Data.Geocache gc;
                        using (System.Net.WebClient wc = new System.Net.WebClient())
                        {
                            while (!cancel && cq.TryDequeue(out gc))
                            {
                                string fnp       = System.IO.Path.Combine(_imageFolder, IMG_SUBFOLDER);
                                bool grabOnlyNew = !updateExisting;
                                try
                                {
                                    List <string> linkList;
                                    lock (_lockObject)
                                    {
                                        linkList = DataAccess.GetImagesOfGeocache(gc.Database, gc.Code);
                                    }

                                    foreach (string link in linkList)
                                    {
                                        string fn       = string.Format("{0}.jpg", Guid.NewGuid().ToString("N"));
                                        bool skipInsert = false;
                                        //if it fails, just ignore this image
                                        try
                                        {
                                            //check if link already is in database
                                            //if so, use this filename
                                            lock (_lockObject)
                                            {
                                                object o = _dbcon.ExecuteScalar(string.Format("select local_file from images where gccode='{0}' and org_url='{1}'", gc.Code.Replace("'", "''"), link.Replace("'", "''")));
                                                if (o != null && o.GetType() != typeof(DBNull))
                                                {
                                                    fn         = (string)o;
                                                    skipInsert = true;
                                                }
                                            }
                                            if (grabOnlyNew && skipInsert)
                                            {
                                                if (System.IO.File.Exists(System.IO.Path.Combine(fnp, fn)))
                                                {
                                                    continue;
                                                }
                                            }
                                            using (System.IO.TemporaryFile tmp = new System.IO.TemporaryFile(true))
                                            {
                                                wc.DownloadFile(link, tmp.Path);
                                                if (new FileInfo(tmp.Path).Length < 10 * 1024 * 1024)
                                                {
                                                    using (System.Drawing.Image img = System.Drawing.Image.FromFile(tmp.Path))
                                                    {
                                                        img.Save(System.IO.Path.Combine(fnp, fn), System.Drawing.Imaging.ImageFormat.Jpeg);
                                                        if (!skipInsert)
                                                        {
                                                            lock (_lockObject)
                                                            {
                                                                _dbcon.ExecuteNonQuery(string.Format("insert into images (gccode, org_url, local_file) values ('{0}', '{1}', '{2}')", gc.Code.Replace("'", "''"), link.Replace("'", "''"), fn));
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        catch //(Exception e)
                                        {
                                            //Core.ApplicationData.Instance.Logger.AddLog(this, e);
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    Core.ApplicationData.Instance.Logger.AddLog(this, e);
                                    //skip and go to next one
                                }
                            }
                        };
                    };

                    List <Task> tasks = new List <Task>();
                    tasks.Add(Task.Factory.StartNew(actionUpdateProgress));
                    for (int i = 0; i < 4 && i < gcList.Count; i++)
                    {
                        tasks.Add(Task.Factory.StartNew(actionDownload));
                    }
                    await Task.WhenAll(tasks.ToArray());
                }
            });
        }