Ejemplo n.º 1
0
        public bool SearchCollections(ref List <Web_Collections_Model> lstResult, string Ma, string Name)
        {
            bool result = false;

            try
            {
                string condition = string.Empty;
                if (Ma != string.Empty)
                {
                    condition += "(`id` like '%" + Ma.Replace("\'", "\\\'") + "' ";
                    condition += " or `id` like '" + Ma.Replace("\'", "\\\'") + "%' ";
                    condition += " or `id` like '%" + Ma.Replace("\'", "\\\'") + "%') ";
                }
                if (Name != string.Empty)
                {
                    if (condition != string.Empty)
                    {
                        condition += "and (`name` like '%" + Name.Replace("\'", "\\\'") + "' ";
                        condition += " or `name` like '" + Name.Replace("\'", "\\\'") + "%' ";
                        condition += " or `name` like '%" + Name.Replace("\'", "\\\'") + "%') ";
                    }
                    else
                    {
                        condition += "(`name` like '%" + Name.Replace("\'", "\\\'") + "' ";
                        condition += " or `name` like '" + Name.Replace("\'", "\\\'") + "%' ";
                        condition += " or `name` like '%" + Name.Replace("\'", "\\\'") + "%') ";
                    }
                }
                DataTable dt;
                if ((dt = DBHandler.selectDataBase(ref conn,
                                                   "`web_collections`",
                                                   "*",
                                                   condition)) != null)
                {
                    lstResult = new List <Web_Collections_Model>();
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        Web_Collections_Model item = new Web_Collections_Model()
                        {
                            id           = (long)dt.Rows[i]["id"],
                            name         = (string)dt.Rows[i]["name"],
                            featureimage = (string)dt.Rows[i]["featureimage"],
                            title        = (string)dt.Rows[i]["title"],
                            description  = (string)dt.Rows[i]["description"],
                            content      = (string)dt.Rows[i]["content"],
                            relatedmenu  = (int)dt.Rows[i]["relatedmenu"],
                            createdDate  = (DateTime)dt.Rows[i]["createdDate"],
                            isdraft      = (bool)dt.Rows[i]["isdraft"],
                        };
                        lstResult.Add(item);
                    }
                    result = true;
                }
            }
            catch (Exception ex)
            {
                LogFile.writeLog(LogFile.DIR, "Exception" + LogFile.getTimeStringNow() + ".txt", LogFile.Filemode.GHIDE, ex.Message);
            }
            return(result);
        }
Ejemplo n.º 2
0
        public bool Update(Web_Collections_Model Obj)
        {
            bool result = false;

            try
            {
                if (DBHandler.updateDataBase(ref conn, "`web_collections`",
                                             "`name` = '" + Obj.name +
                                             "', `title` = '" + Obj.title.Replace("'", "\'") +
                                             "', `featureimage` = '" + Obj.featureimage.Replace("'", "\'") +
                                             "', `description` = '" + Obj.description.Replace("'", "\'").Replace("\n", "<br/>") +
                                             "', `relatedmenu` = '" + Obj.relatedmenu +
                                             "', `content` = '" + Obj.content.Replace("'", "\'").Replace("\n", "<br/>") +
                                             "', `isdraft` = " + ((Obj.isdraft) ? 1: 0), "`id` = '" + Obj.id + "'"))
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                LogFile.writeLog(LogFile.DIR, "Exception" + LogFile.getTimeStringNow() + ".txt", LogFile.Filemode.GHIDE, ex.Message);
            }

            return(result);
        }
Ejemplo n.º 3
0
        public bool Save(Web_Collections_Model Obj, ref long id)
        {
            bool result = false;

            try
            {
                // if Obj.id == -1. It doest't add. Add and save.
                if (Obj.id == -1)
                {
                    Add(Obj);
                    id = -1;
                    Web_Collections_Model rs = null;
                    if (GetCollectionbyName(ref rs, Obj.name))
                    {
                        id = rs.id;
                    }
                }
                else
                {
                    Update(Obj);
                    id = Obj.id;
                }
                result = true;
            }
            catch (Exception ex)
            {
                LogFile.writeLog(LogFile.DIR, "Exception" + LogFile.getTimeStringNow() + ".txt", LogFile.Filemode.GHIDE, ex.Message);
            }
            return(result);
        }
Ejemplo n.º 4
0
 private void Dv_SelectionChanged(object sender, EventArgs e)
 {
     if (dv.SelectedRows.Count == 1)
     {
         long id = (long)dv.SelectedRows[0].Cells["MC"].Value;
         selectedItem = result.Where(s => s.id == id).FirstOrDefault();
     }
 }
Ejemplo n.º 5
0
        public void DeleteFileCollection(Web_Collections_Model Obj)
        {
            List <string> lstImage = FTPAction.getListFiles(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword, FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + Obj.id, string.Empty);

            foreach (var item in lstImage)
            {
                FTPAction.deleteFile(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword, FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + Obj.id, item);
            }
            FTPAction.deleteDirectory(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword, FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + Obj.id);
        }
Ejemplo n.º 6
0
 private void Dv_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
 {
     if (e.RowIndex >= 0)
     {
         try
         {
             long id = (long)dv.Rows[e.RowIndex].Cells["MC"].Value;
             selectedItem = result.Where(s => s.id == id).FirstOrDefault();
         }
         catch { }
     }
 }
Ejemplo n.º 7
0
 private void ItemAdd_Click(object sender, EventArgs e)
 {
     using (CollectionsActionView view = new CollectionsActionView(Resources.EnumClass.CollectionsAction.Add,
                                                                   ref controller,
                                                                   null))
     {
         if (view.ShowDialog() == DialogResult.OK)
         {
             Btn_Search_Click(null, null);
             selectedItem = null;
         }
     }
 }
Ejemplo n.º 8
0
 private void ItemDelete_Click(object sender, EventArgs e)
 {
     if (selectedItem != null)
     {
         if (controller.Delete(selectedItem))
         {
             Common.Functions.ShowMessgeInfo("Delete Success");
             Btn_Search_Click(null, null);
             selectedItem = null;
         }
         else
         {
             Common.Functions.ShowMessgeInfo("Delete Fail");
         }
     }
 }
Ejemplo n.º 9
0
 private void Btn_Search_Click(object sender, EventArgs e)
 {
     result = null;
     if (controller.SearchCollections(ref result, tb_MaSP.Text, tb_TenSP.Text))
     {
         dv.Rows.Clear();
         dp.setObjCount(result.Count, 10);
         if (result.Count == 0)
         {
             Functions.ShowMessgeInfo("Không có dữ liệu nào phù hợp");
         }
         Functions.ShowMaiQuynhAnh();
     }
     else
     {
         Functions.ShowMessgeInfo("Search thất bại");
     }
     selectedItem = null;
 }
        private bool SendImage(ref Web_Collections_Model obj, ref List <ImageAttachModel> lstImage, ref List <ImageAttachModel> DeleteImageList)
        {
            bool result = true;

            if (FeatureImage.IsLocal)
            {
                if (!FTPAction.sendFile(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword,
                                        FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + obj.id, obj.name + Common.Functions.GetExtension(FeatureImage.Link),
                                        Common.Functions.GetPathFileName(FeatureImage.Link), Common.Functions.GetSafeFileName(FeatureImage.Link)))
                {
                    return(false);
                }
                FeatureImage.IsLocal = false;
                FeatureImage.Link    = AppConfig.WebUrl + "/" + Common.AppConfig.PathImageCollections + "/" + obj.id + "/" + obj.name + Common.Functions.GetExtension(FeatureImage.Link);
            }
            obj.featureimage = obj.name + Common.Functions.GetExtension(FeatureImage.Link);

            foreach (var item in lstImage)
            {
                if (item.IsLocal)
                {
                    if (!FTPAction.sendFile(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword,
                                            FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + obj.id, Common.Functions.GetSafeFileName(item.Link),
                                            Common.Functions.GetPathFileName(item.Link), Common.Functions.GetSafeFileName(item.Link)))
                    {
                        return(false);
                    }
                    item.IsLocal = false;
                    item.Link    = AppConfig.WebUrl + "/" + Common.AppConfig.PathImageCollections + "/" + obj.id + "/" + Common.Functions.GetSafeFileName(item.Link);
                }
                obj.content = obj.content.Replace("[~" + item.id.ToString() + "]", item.Link);
            }
            foreach (var item in DeleteImageList)
            {
                if (!item.IsLocal)
                {
                    FTPAction.deleteFile(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword,
                                         FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + obj.id, Common.Functions.GetSafeFileName(item.Link));
                }
            }
            return(result);
        }
Ejemplo n.º 11
0
        public bool Delete(Web_Collections_Model Obj)
        {
            bool result = false;

            try
            {
                if (DBHandler.deleteDataBase(ref conn,
                                             "`web_collections`",
                                             "`id` = " + Obj.id))
                {
                    result = true;
                    DeleteFileCollection(Obj);
                }
            }
            catch (Exception ex)
            {
                LogFile.writeLog(LogFile.DIR, "Exception" + LogFile.getTimeStringNow() + ".txt", LogFile.Filemode.GHIDE, ex.Message);
            }

            return(result);
        }
        public CollectionsActionView(CollectionsAction Action, ref CollectionsController Controller, Web_Collections_Model obj)
        {
            InitializeComponent();

            action     = Action;
            controller = Controller;
            if (obj != null)
            {
                Obj = new Web_Collections_Model()
                {
                    id           = obj.id,
                    content      = obj.content,
                    createdDate  = obj.createdDate,
                    description  = obj.description,
                    featureimage = obj.featureimage,
                    name         = obj.name,
                    relatedmenu  = obj.relatedmenu,
                    title        = obj.title,
                    isdraft      = obj.isdraft
                };
            }
            this.Load += CollectionsActionView_Load;
        }
Ejemplo n.º 13
0
        public bool GetCollectionbyName(ref Web_Collections_Model collection, string name)
        {
            bool result = false;

            try
            {
                DataTable dt;
                if ((dt = DBHandler.selectDataBase(ref conn,
                                                   "`web_collections`",
                                                   "*",
                                                   "`name` = '" + name + "'",
                                                   "LIMIT 1")) != null)
                {
                    if (dt.Rows.Count == 1)
                    {
                        collection = new Web_Collections_Model()
                        {
                            id           = (long)dt.Rows[0]["id"],
                            name         = (string)dt.Rows[0]["name"],
                            featureimage = (string)dt.Rows[0]["featureimage"],
                            title        = (string)dt.Rows[0]["title"],
                            description  = (string)dt.Rows[0]["description"],
                            content      = (string)dt.Rows[0]["content"],
                            relatedmenu  = (int)dt.Rows[0]["relatedmenu"],
                            createdDate  = (DateTime)dt.Rows[0]["createdDate"],
                            isdraft      = (bool)dt.Rows[0]["isdraft"],
                        };
                        result = true;
                    }
                }
            }
            catch (Exception ex)
            {
                LogFile.writeLog(LogFile.DIR, "Exception" + LogFile.getTimeStringNow() + ".txt", LogFile.Filemode.GHIDE, ex.Message);
            }
            return(result);
        }
        private void btn_action_Click(object sender, EventArgs e)
        {
            if (tb_name.Equals(string.Empty))
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"name\"");
                return;
            }
            if (tb_title.Equals(string.Empty))
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"title\"");
                return;
            }
            if (rtb_description.Equals(string.Empty))
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"description\"");
                return;
            }
            if (rtb_content.Equals(string.Empty))
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"content\"");
                return;
            }
            if (FeatureImage.Equals(null))
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"Feature Image\"");
                return;
            }
            if (chlb_catogary.CheckedItems.Count == 0)
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"catogary\"");
                return;
            }

            string CollectionLink = string.Empty;

            if (Obj == null)
            {
                CollectionLink = CheckExistCollectionLink(Common.Functions.getWebNameValid(tb_name.Text));
                if (CollectionLink.Equals(string.Empty))
                {
                    Common.Functions.ShowMessgeError("Không có kết nối đến máy chủ");
                    return;
                }
            }
            else
            {
                CollectionLink = Obj.name;
            }

            var lstImage = pn_imageattach.GetImageAttachList();
            var DeletedImageAttachList = pn_imageattach.DeletedImageAttachList;

            Web_Collections_Model obj = new Web_Collections_Model()
            {
                id           = (Obj == null) ? -1 : Obj.id,
                name         = CollectionLink,
                title        = tb_title.Text,
                content      = rtb_content.Text,
                featureimage = FeatureImage.Link,
                description  = rtb_description.Text,
                relatedmenu  = (int)(chlb_catogary.CheckedItems[0] as Web_Menu_Model).id,
                isdraft      = false
            };
            long id = -1;

            if (controller.Save(obj, ref id))
            {
                obj.id = id;
                if (SendImage(ref obj, ref lstImage, ref DeletedImageAttachList))
                {
                    controller.Update(obj);
                    pn_imageattach.ClearDeletedImageAttachList();
                    //pn_imageattach.StoreImageAttachList(lstImage);
                    Obj = obj;
                    Common.Functions.ShowMessgeInfo("Success");
                }
                else
                {
                    controller.Delete(obj);
                    Common.Functions.ShowMessgeInfo("Fail");
                }
            }
            else
            {
                Common.Functions.ShowMessgeInfo("Fail");
            }
        }