public async Task <IActionResult> UpdateItemDetail(Guid employeeId, [FromBody] ItemDetailModel itemDetail)
        {
            ItemDetail updateItemDetail = new ItemDetail(); // need for catch part

            try
            {
                updateItemDetail         = context.ItemDetail.Find(itemDetail.itemDetailId);
                updateItemDetail.ItemId  = itemDetail.itemId;
                updateItemDetail.SizeId  = itemDetail.sizeId;
                updateItemDetail.ColorId = itemDetail.colorId;
                // if Sold (2) or Lost (6) then quantity is negative
                updateItemDetail.Quantity     = (itemDetail.itemActionId == 2 || itemDetail.itemActionId == 6) ? (-1) * Math.Abs(itemDetail.quantity) : Math.Abs(itemDetail.quantity); // not null
                updateItemDetail.ItemActionId = itemDetail.itemActionId;
                // if Sold (2) or Returned (3) then add CustomerId
                updateItemDetail.CustomerId = (itemDetail.itemActionId == 2 || itemDetail.itemActionId == 3) ? itemDetail.customerId : null;

                await context.SaveChangesAsync();

                #region AdminLog

                AdminLog adminLog = new AdminLog();
                adminLog.TableName        = "ItemDetail";
                adminLog.FieldName        = "ItemDetailId";
                adminLog.FieldValue       = itemDetail.itemDetailId.ToString();
                adminLog.AdminLogActionId = (int)AdminLogActionEnum.Update;
                adminLog.Notes            = null;
                adminLog.EmployeeId       = employeeId;
                adminLog.Timestamp        = DateTime.Now;
                analyticsRepo.InsertAdminLog(adminLog);

                #endregion

                return(NoContent());
            }
            catch (Exception ex)
            {
                #region ErrorLog

                ErrorLog errorLog = new ErrorLog();
                errorLog.Namespace       = "PapaJohnsCloneApi.Controllers";
                errorLog.Class           = "AnalyticsController";
                errorLog.Method          = "UpdateItemDetail";
                errorLog.MethodParams    = "(Guid employeeId, [FromBody] ItemDetailModel itemDetail)";
                errorLog.ErrorLogTypeId  = (int)ErrorLogTypeEnum.Error;
                errorLog.ShortComment    = "Failed to update ItemDetail";
                errorLog.DetailedComment = ex.InnerException.Message;
                errorLog.Exception       = XmlManipulation.ConvertObjectToXml <Exception>(ex.InnerException);
                errorLog.EmployeeId      = employeeId;
                errorLog.Timestamp       = DateTime.Now;
                // clean Exception before saving AdminLog in db
                context.Entry(updateItemDetail).State = EntityState.Detached;
                analyticsRepo.InsertErrorLog(errorLog);

                #endregion
                return(BadRequest());
            }
        }
        public async Task <IActionResult> DeleteItemDetail(Guid employeeId, Guid itemDetailId)
        {
            ItemDetail itemDetail = new ItemDetail(); // need for catch part

            try
            {
                itemDetail = await context.ItemDetail
                             .Where(x => x.ItemDetailId == itemDetailId)
                             .FirstOrDefaultAsync();

                context.ItemDetail.Remove(itemDetail);
                context.SaveChanges();

                #region AdminLog

                AdminLog adminLog = new AdminLog();
                adminLog.TableName        = "ItemDetail";
                adminLog.FieldName        = "ItemDetailId";
                adminLog.FieldValue       = itemDetailId.ToString();
                adminLog.AdminLogActionId = (int)AdminLogActionEnum.Delete;
                adminLog.Notes            = "Delete single row from ItemDetail by ItemDetailId";
                adminLog.EmployeeId       = employeeId;
                adminLog.Timestamp        = DateTime.Now;
                analyticsRepo.InsertAdminLog(adminLog);

                #endregion

                return(NoContent());
            }
            catch (Exception ex)
            {
                #region ErrorLog

                ErrorLog errorLog = new ErrorLog();
                errorLog.Namespace       = "PapaJohnsCloneApi.Controllers";
                errorLog.Class           = "AnalyticsController";
                errorLog.Method          = "DeleteItemDetail";
                errorLog.MethodParams    = "(Guid employeeId, Guid itemDetailId)";
                errorLog.ErrorLogTypeId  = (int)ErrorLogTypeEnum.Error;
                errorLog.ShortComment    = "Failed to delete row from ItemDetail";
                errorLog.DetailedComment = "ItemDetailId: " + itemDetailId.ToString() + ". Message:" + ex.InnerException.Message;
                errorLog.Exception       = XmlManipulation.ConvertObjectToXml <Exception>(ex.InnerException);
                errorLog.EmployeeId      = employeeId;
                errorLog.Timestamp       = DateTime.Now;
                // clean Exception before saving AdminLog in db
                context.Entry(itemDetail).State = EntityState.Detached;
                analyticsRepo.InsertErrorLog(errorLog);

                #endregion ErrorLog
                return(BadRequest());
            }
        }
Example #3
0
        private void ReadAppConfig_Tick(object sender, EventArgs e)
        {
            var temp = XmlManipulation.GetValue("FocusActivate");

            if (temp == "ON")
            {
                timContrôleFocus.Enabled = true;
            }
            else
            {
                timContrôleFocus.Enabled = false;
            }
        }
Example #4
0
 private void chbSaveDiscussionOn_CheckedChanged(object sender, EventArgs e)
 {
     //Management Checked - not checked
     if (chbSaveDiscussionOn.Checked == false && chbSaveDiscussionOff.Checked == false)
     {
         chbSaveDiscussionOff.Checked = true;
     }
     if (chbSaveDiscussionOn.Checked == true)
     {
         chbSaveDiscussionOff.Checked = false;
         //Change value on App.config
         XmlManipulation.ModifyElementXml("SaveDiscussion", "ON");
     }
 }
Example #5
0
 private void chbLastIpRecipientOn_CheckedChanged(object sender, EventArgs e)
 {
     //Management Checked - not checked
     if (chbLastIpRecipientOn.Checked == false && chbLastIpRecipientOff.Checked == false)
     {
         chbLastIpRecipientOff.Checked = true;
     }
     if (chbLastIpRecipientOn.Checked == true)
     {
         chbLastIpRecipientOff.Checked = false;
         //Change value on App.config
         XmlManipulation.ModifyElementXml("EnableLastIpConnexion", "ON");
     }
 }
Example #6
0
 private void chbEnableNotificationsOff_CheckedChanged(object sender, EventArgs e)
 {
     //Management Checked - not checked
     if (chbEnableNotificationsOn.Checked == false && chbEnableNotificationsOff.Checked == false)
     {
         chbEnableNotificationsOn.Checked = true;
     }
     if (chbEnableNotificationsOff.Checked == true)
     {
         chbEnableNotificationsOn.Checked = false;
         //Change value on App.config
         XmlManipulation.ModifyElementXml("NotificationsEnable", "OFF");
     }
 }
        public async Task <IActionResult> UpdateItemActivity(Guid employeeId, Guid itemId, bool isActive)
        {
            Item updateItem = new Item(); // need for catch part

            try
            {
                updateItem          = context.Item.Find(itemId);
                updateItem.IsActive = isActive;
                await context.SaveChangesAsync();

                #region AdminLog

                AdminLog adminLog = new AdminLog();
                adminLog.TableName        = "Item";
                adminLog.FieldName        = "ItemId";
                adminLog.FieldValue       = itemId.ToString();
                adminLog.AdminLogActionId = (int)AdminLogActionEnum.Update;
                adminLog.Notes            = (isActive) ? "Item was activated" : "Item was deactivated";
                adminLog.EmployeeId       = employeeId;
                adminLog.Timestamp        = DateTime.Now;
                analyticsRepo.InsertAdminLog(adminLog);

                #endregion

                return(NoContent());
            }
            catch (Exception ex)
            {
                #region ErrorLog

                ErrorLog errorLog = new ErrorLog();
                errorLog.Namespace       = "PapaJohnsCloneApi.Controllers";
                errorLog.Class           = "AnalyticsController";
                errorLog.Method          = "UpdateItemActivity";
                errorLog.MethodParams    = "(Guid employeeId, Guid itemId, bool isActive)";
                errorLog.ErrorLogTypeId  = (int)ErrorLogTypeEnum.Error;
                errorLog.ShortComment    = "Failed to update item's isActive field";
                errorLog.DetailedComment = ex.InnerException.Message;
                errorLog.Exception       = XmlManipulation.ConvertObjectToXml <Exception>(ex.InnerException);
                errorLog.EmployeeId      = employeeId;
                errorLog.Timestamp       = DateTime.Now;
                // clean Exception before saving AdminLog in db
                context.Entry(updateItem).State = EntityState.Detached;
                analyticsRepo.InsertErrorLog(errorLog);

                #endregion
                return(BadRequest());
            }
        }
Example #8
0
 private void chbSaveDiscussionOff_CheckedChanged(object sender, EventArgs e)
 {
     //Management Checked - not checked
     if (chbSaveDiscussionOn.Checked == false && chbSaveDiscussionOff.Checked == false)
     {
         chbSaveDiscussionOn.Checked = true;
     }
     if (chbSaveDiscussionOff.Checked == true)
     {
         chbSaveDiscussionOn.Checked = false;
         //Change value on App.config
         XmlManipulation.ModifyElementXml("SaveDiscussion", "OFF");
     }
     // Objects.KNotification.Show("The saving of discussions is cancelled.\r\n!!! Old backups are not deleted !!!");
 }
Example #9
0
        // At start-up
        private void FrmMain_Load(object sender, EventArgs e)
        {
            //==============================AtStartUp===================================================
            lblDescription2.Visible = false;                                                   //Hidden label
            _sck = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); //Socket creation
            _sck.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            lblIPPersonnel.Text        = GetLocalIp();                                         //Show personnal Ip
            tbxMessageEnvoit.MaxLength = 72;                                                   //Limit max lenght
            pbxLogoPetit.Visible       = false;                                                //Don't show logo
            NomDestinataireToolStripMenuItem.Visible = false;
            NomDestinataireToolStripMenuItem.Text    = lblIPPersonnel.Text;
            iPPersonnelToolStripMenuItem.Visible     = false;
            MaximizeBox = false;             //Don't show maximize button on form
            //GESTIONFOCUS====================================================================================
            timContrôleFocus.Enabled = true; //Start timer focus
            lblNomPCDest.Visible     = false;
            lblEtatPing.Visible      = false;

            //==============SearchUpdate================================================================
            UpdateApplication.VersionVerification(AppInfo.GetChainFormattedVersion());//ApplicationVersionWeb
            //================================================================================================
            //UpdateAppYear===================================================================================
            lblDescription.Text  = $"Kubeah! {DateTime.Now.Year.ToString()}";
            lblDescription2.Text = $"Kubeah! {DateTime.Now.Year.ToString()}";
            //Create and read config==========================================================================
            var recipientIp = XmlManipulation.GetValue("LastIpConnexion");

            if (recipientIp != "")
            {
                IpSeparationString(recipientIp, true);
            }
            else
            {
                IpSeparationString(lblIPPersonnel.Text, false);
            }
            var focusState = XmlManipulation.GetValue("FocusActivate");

            if (focusState != "ON")
            {
                timContrôleFocus.Enabled = false;
            }
            if (XmlManipulation.GetValue("EnableLastIpConnexion") != "ON")
            {
                XmlManipulation.ModifyElementXml("LastIpConnexion", "");
            }
            //================================================================================================
        }
Example #10
0
        //FINGestionNbrCaractères===================================================================FIN====================
        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            //Envoi la clé pour dire à l'autre client qu'il est absent
            //Que si la conversation à démmarée
            if (!btnSart.Visible)
            {
                EnvoiDuMessage("789ZCFZTiniwjZTUvjkas79012798", KMessage.Type.Init());//Clé Absent

                var status = XmlManipulation.GetValue("SaveDiscussion");
                if (status == "ON")
                {
                    var text = "";
                    foreach (var item in lbxTchat.Items)
                    {
                        text += item + "\r\n";
                    }
                    ChatData.Export(_recipientIp, text);
                    // Why one line?
                }
            }
        }
        public async Task <IActionResult> DeleteItem(Guid employeeId, Guid itemId)
        {
            Item item = new Item(); // need for catch part

            try
            {
                List <ItemDetail> itemDetails = await context.ItemDetail
                                                .Where(x => x.ItemId == itemId)
                                                .ToListAsync();

                List <ItemImage> itemImages = await context.ItemImage
                                              .Where(x => x.ItemId == itemId)
                                              .ToListAsync();

                item = await context.Item
                       .Where(x => x.ItemId == itemId)
                       .FirstOrDefaultAsync();

                context.ItemDetail.RemoveRange(itemDetails);
                context.ItemImage.RemoveRange(itemImages);
                context.Item.Remove(item);
                context.SaveChanges();

                #region AdminLog

                AdminLog adminLog1 = new AdminLog();
                adminLog1.TableName        = "ItemDetail";
                adminLog1.FieldName        = "ItemId";
                adminLog1.FieldValue       = itemId.ToString();
                adminLog1.AdminLogActionId = (int)AdminLogActionEnum.Delete;
                adminLog1.Notes            = "Delete from ItemDetail, ItemImage and Item simultaneously";
                adminLog1.EmployeeId       = employeeId;
                adminLog1.Timestamp        = DateTime.Now;
                analyticsRepo.InsertAdminLog(adminLog1);

                AdminLog adminLog2 = new AdminLog();
                adminLog2.TableName        = "ItemImage";
                adminLog2.FieldName        = adminLog1.FieldName;
                adminLog2.FieldValue       = adminLog1.FieldValue;
                adminLog2.AdminLogActionId = adminLog1.AdminLogActionId;
                adminLog2.Notes            = adminLog1.Notes;
                adminLog2.EmployeeId       = adminLog1.EmployeeId;
                adminLog2.Timestamp        = adminLog1.Timestamp;
                analyticsRepo.InsertAdminLog(adminLog2);

                AdminLog adminLog3 = new AdminLog();
                adminLog3.TableName        = "Item";
                adminLog3.FieldName        = adminLog1.FieldName;
                adminLog3.FieldValue       = adminLog1.FieldValue;
                adminLog3.AdminLogActionId = adminLog1.AdminLogActionId;
                adminLog3.Notes            = adminLog1.Notes;
                adminLog3.EmployeeId       = adminLog1.EmployeeId;
                adminLog3.Timestamp        = adminLog1.Timestamp;
                analyticsRepo.InsertAdminLog(adminLog3);

                #endregion

                return(NoContent());
            }
            catch (Exception ex)
            {
                #region ErrorLog

                ErrorLog errorLog = new ErrorLog();
                errorLog.Namespace       = "PapaJohnsCloneApi.Controllers";
                errorLog.Class           = "AnalyticsController";
                errorLog.Method          = "DeleteItem";
                errorLog.MethodParams    = "(Guid employeeId, Guid itemId)";
                errorLog.ErrorLogTypeId  = (int)ErrorLogTypeEnum.Error;
                errorLog.ShortComment    = "Failed to delete item from Item, ItemDetail and ItemImage";
                errorLog.DetailedComment = "ItemId: " + itemId.ToString() + ". Message:" + ex.InnerException.Message;
                errorLog.Exception       = XmlManipulation.ConvertObjectToXml <Exception>(ex.InnerException);
                errorLog.EmployeeId      = employeeId;
                errorLog.Timestamp       = DateTime.Now;
                // clean Exception before saving AdminLog in db
                context.Entry(item).State = EntityState.Detached;
                analyticsRepo.InsertErrorLog(errorLog);


                #endregion ErrorLog
                return(BadRequest());
            }
        }
        public async Task <IActionResult> UpdateItem(Guid employeeId, [FromBody] ItemModel item)
        {
            #region serverside validation
            if (String.IsNullOrWhiteSpace(item.name))
            {
                return(BadRequest("Name can't be empty"));
            }
            if (item.name.Length > 50)
            {
                return(BadRequest("Name shouldn't exceed 50 characters"));
            }
            if (String.IsNullOrWhiteSpace(item.description))
            {
                return(BadRequest("Description can't be empty"));
            }
            if (item.description.Length > 2000)
            {
                return(BadRequest("Description shouldn't exceed 2000 characters"));
            }

            #endregion

            Item updateItem = new Item(); // need for catch part
            try
            {
                updateItem             = context.Item.Find(item.itemId);
                updateItem.Name        = item.name;        // not null
                updateItem.Description = item.description; // not null
                updateItem.BrandId     = item.brandId;     // not null
                updateItem.CategoryId  = item.categoryId;  // not null
                updateItem.GenderId    = item.genderId;    // not null
                updateItem.Price       = item.price;       // not null
                await context.SaveChangesAsync();

                #region AdminLog

                AdminLog adminLog = new AdminLog();
                adminLog.TableName        = "Item";
                adminLog.FieldName        = "ItemId";
                adminLog.FieldValue       = item.itemId.ToString();
                adminLog.AdminLogActionId = (int)AdminLogActionEnum.Update;
                adminLog.Notes            = null;
                adminLog.EmployeeId       = employeeId;
                adminLog.Timestamp        = DateTime.Now;
                analyticsRepo.InsertAdminLog(adminLog);

                #endregion

                return(NoContent());
            }
            catch (Exception ex)
            {
                #region ErrorLog

                ErrorLog errorLog = new ErrorLog();
                errorLog.Namespace       = "PapaJohnsCloneApi.Controllers";
                errorLog.Class           = "AnalyticsController";
                errorLog.Method          = "UpdateItem";
                errorLog.MethodParams    = "(Guid employeeId, [FromBody] ItemModel item)";
                errorLog.ErrorLogTypeId  = (int)ErrorLogTypeEnum.Error;
                errorLog.ShortComment    = "Failed to update Item";
                errorLog.DetailedComment = ex.InnerException.Message;
                errorLog.Exception       = XmlManipulation.ConvertObjectToXml <Exception>(ex.InnerException);
                errorLog.EmployeeId      = employeeId;
                errorLog.Timestamp       = DateTime.Now;
                // clean Exception before saving AdminLog in db
                context.Entry(updateItem).State = EntityState.Detached;
                analyticsRepo.InsertErrorLog(errorLog);

                #endregion
                return(BadRequest());
            }
        }
        public async Task <IActionResult> InsertItemImage(Guid employeeId, [FromBody] ItemImageModel[] itemImage)
        {
            int       count        = 0;
            ItemImage newItemImage = new ItemImage(); // need it for catch part

            try
            {
                Guid?itemId = itemImage.Select(x => x.itemId).First();
                // Step 1. Delete all old images
                List <ItemImage> itemImages = await context.ItemImage
                                              .Where(x => x.ItemId == itemId)
                                              .ToListAsync();

                context.ItemImage.RemoveRange(itemImages);
                context.SaveChanges();
                // Step 2. Add/readd images
                foreach (ItemImageModel img in itemImage)
                {
                    #region serverside validation

                    // skip images if size exceedes  100 MB
                    if (img.size > 104857600) // 100 MB = 104 857 600 KB
                    {
                        continue;
                    }
                    // skip if type is not image
                    if (!img.imageType.StartsWith("image"))
                    {
                        continue;
                    }

                    #endregion serverside validation

                    newItemImage = new ItemImage();// emptify for each new image
                    // newItemImage.ItemImageId will be generated by default
                    newItemImage.ItemId    = (Guid)itemId;
                    newItemImage.Src       = img.src;
                    newItemImage.IsMain    = (bool)img.isMain;
                    newItemImage.Size      = img.size;
                    newItemImage.ImageType = img.imageType;

                    context.ItemImage.Add(newItemImage);
                    await context.SaveChangesAsync();

                    count++;

                    #region AdminLog

                    AdminLog adminLog = new AdminLog();
                    adminLog.TableName        = "ItemImage";
                    adminLog.FieldName        = "ItemImageId";
                    adminLog.FieldValue       = newItemImage.ItemImageId.ToString();
                    adminLog.AdminLogActionId = (int)AdminLogActionEnum.Create;
                    adminLog.Notes            = null;
                    adminLog.EmployeeId       = employeeId;
                    adminLog.Timestamp        = DateTime.Now;
                    analyticsRepo.InsertAdminLog(adminLog);

                    #endregion
                }

                return(Ok("Number of successfully save images is " + count));
            }
            catch (Exception ex)
            {
                #region ErrorLog

                ErrorLog errorLog = new ErrorLog();
                errorLog.Namespace       = "PapaJohnsCloneApi.Controllers";
                errorLog.Class           = "AnalyticsController";
                errorLog.Method          = "InsertItemImage";
                errorLog.MethodParams    = "(Guid employeeId, [FromBody] ItemImageModel[] itemImage)";
                errorLog.ErrorLogTypeId  = (int)ErrorLogTypeEnum.Error;
                errorLog.ShortComment    = "Failed to insert into ItemImage";
                errorLog.DetailedComment = ex.InnerException.Message;
                errorLog.Exception       = XmlManipulation.ConvertObjectToXml <Exception>(ex.InnerException);
                errorLog.EmployeeId      = employeeId;
                errorLog.Timestamp       = DateTime.Now;
                // clean Exception before saving AdminLog in db
                context.Entry(newItemImage).State = EntityState.Detached;
                analyticsRepo.InsertErrorLog(errorLog);

                #endregion
                return(BadRequest());
            }
        }
        public async Task <IActionResult> InsertItemDetail(Guid employeeId, [FromBody] ItemDetailModel itemDetail)
        {
            #region serverside validation

            if (itemDetail.quantity > 1000000000 || itemDetail.quantity < -1000000000)
            {
                return(BadRequest("Quantity must fall within range between minus billion and plus billion"));
            }

            #endregion

            ItemDetail newItemDetail = new ItemDetail();
            try
            {
                // newItemDetail.ItemDetailId will be generated by default
                newItemDetail.ItemId  = itemDetail.itemId;                                                                                                    // not null
                newItemDetail.SizeId  = itemDetail.sizeId;                                                                                                    // not null
                newItemDetail.ColorId = itemDetail.colorId;                                                                                                   // not null
                // if Sold (2) or Lost (6) then quantity is negative
                newItemDetail.Quantity     = (itemDetail.itemActionId == 2 || itemDetail.itemActionId == 6)? (-1) * itemDetail.quantity: itemDetail.quantity; // not null
                newItemDetail.ItemActionId = itemDetail.itemActionId;                                                                                         // not null
                // if Sold (2) or Returned (3) then add CustomerId
                newItemDetail.CustomerId = (itemDetail.itemActionId == 2 || itemDetail.itemActionId == 3) ? itemDetail.customerId : null;
                context.ItemDetail.Add(newItemDetail);
                await context.SaveChangesAsync();

                #region AdminLog

                AdminLog adminLog = new AdminLog();
                adminLog.TableName        = "ItemDetail";
                adminLog.FieldName        = "ItemDetailId";
                adminLog.FieldValue       = newItemDetail.ItemDetailId.ToString();
                adminLog.AdminLogActionId = (int)AdminLogActionEnum.Create;
                adminLog.Notes            = null;
                adminLog.EmployeeId       = employeeId;
                adminLog.Timestamp        = DateTime.Now;
                analyticsRepo.InsertAdminLog(adminLog);

                #endregion

                return(Ok(newItemDetail.ItemDetailId));
            }
            catch (Exception ex)
            {
                #region ErrorLog

                ErrorLog errorLog = new ErrorLog();
                errorLog.Namespace       = "PapaJohnsCloneApi.Controllers";
                errorLog.Class           = "AnalyticsController";
                errorLog.Method          = "InsertItemDetail";
                errorLog.MethodParams    = "(Guid employeeId, [FromBody] ItemDetailModel itemDetail)";
                errorLog.ErrorLogTypeId  = (int)ErrorLogTypeEnum.Error;
                errorLog.ShortComment    = "Failed to insert into ItemDetail";
                errorLog.DetailedComment = ex.InnerException.Message;
                errorLog.Exception       = XmlManipulation.ConvertObjectToXml <Exception>(ex.InnerException);
                errorLog.EmployeeId      = employeeId;
                errorLog.Timestamp       = DateTime.Now;
                // clean Exception before saving AdminLog in db
                context.Entry(newItemDetail).State = EntityState.Detached;
                analyticsRepo.InsertErrorLog(errorLog);

                #endregion
                return(BadRequest());
            }
        }
Example #15
0
 private void FrmMain_Deactivate(object sender, EventArgs e)
 {
     _bNotificationsEnable = (XmlManipulation.GetValue("NotificationsEnable") == "ON") ? true : false;
 }
Example #16
0
        private void frmConfig_Load(object sender, EventArgs e)
        {
            //Display all settings with App.config
            var temp = "";

            temp = XmlManipulation.GetValue("FocusActivate");
            if (temp == "")
            {
            }
            else
            {
                if (temp == "ON")
                {
                    chbFocusOn.Checked = true;
                }
                else
                {
                    chbFocusOff.Checked = true;
                }
            }

            temp = XmlManipulation.GetValue("EnableLastIpConnexion");
            if (temp == "")
            {
            }
            else
            {
                if (temp == "ON")
                {
                    chbLastIpRecipientOn.Checked = true;
                }
                else
                {
                    chbLastIpRecipientOff.Checked = true;
                }
            }

            temp = XmlManipulation.GetValue("SaveDiscussion");
            if (temp == "")
            {
            }
            else
            {
                if (temp == "ON")
                {
                    chbSaveDiscussionOn.Checked = true;
                }
                else
                {
                    chbSaveDiscussionOff.Checked = true;
                }
            }

            temp = XmlManipulation.GetValue("NotificationsEnable");
            if (temp == "")
            {
            }
            else
            {
                if (temp == "ON")
                {
                    chbEnableNotificationsOn.Checked = true;
                }
                else
                {
                    chbEnableNotificationsOff.Checked = true;
                }
            }
        }
Example #17
0
        //=====================================================================================================================/
        //====================================================================================================================/

        //=====================BTNSTART=============================================================================
        private async void btnSart_ClickAsync(object sender, EventArgs e)
        {
            lblPatience.Visible = true;
            var sIpDestinataire = tbxIP1.Text + "." + tbxIP2.Text + "." + tbxIP3.Text + "." + tbxIP4.Text;

            if (sIpDestinataire == lblIPPersonnel.Text)
            {
                tbxIP4.BackColor = Color.Red;
            }
            if (tbxIP1.BackColor != Color.Red)
            {
                if (tbxIP2.BackColor != Color.Red)
                {
                    if (tbxIP3.BackColor != Color.Red)
                    {
                        if (tbxIP4.BackColor != Color.Red)
                        {
                            if (tbxIP4.BackColor != Color.PaleGreen)
                            {
                                lblPatience.Visible  = true;
                                lblEtatPing.Visible  = false;
                                lblNomPCDest.Visible = false;
                                lblEtatPing.Visible  = true;
                                var sNameDestinataire = Ip.GetHostName(sIpDestinataire);
                                var bResultPing       = await Task.Run(() => Ip.PingDest(sIpDestinataire));

                                if (bResultPing)
                                {
                                    lblEtatPing.Text      = @"Ping : OK";
                                    lblEtatPing.ForeColor = Color.Green;
                                    if (btnSart.Text == @"Check IP")
                                    {
                                        if (sNameDestinataire == "")
                                        {
                                            lblNomPCDest.Text      = "Name :" + "\r\n" + "Not found";
                                            lblNomPCDest.ForeColor = Color.Red;
                                            lblNomPCDest.Visible   = true;
                                            tbxIP4.BackColor       = Color.Red;
                                        }
                                        else
                                        {
                                            btnSart.Text           = "Start";
                                            lblNomPCDest.Visible   = true;
                                            lblNomPCDest.Text      = "Name :" + "\r\n" + sNameDestinataire;
                                            lblNomPCDest.ForeColor = Color.Black;
                                        }
                                    }
                                    else
                                    {
                                        //___________MinimiserLaFenetre________________
                                        this.Width                = 620;
                                        lblDescription.Visible    = false;
                                        btnSart.Visible           = false;
                                        lblDescription2.Visible   = true;
                                        lblIPDESTINATAIRE.Visible = false;
                                        pbxLogo1.Visible          = false;
                                        pbxLogoPetit.Visible      = true;
                                        lblIPPersonnel.Visible    = false;
                                        lblFixeCePC.Visible       = false;
                                        NomDestinataireToolStripMenuItem.Visible = true;
                                        tbxIP1.Visible = false;
                                        tbxIP2.Visible = false;
                                        tbxIP3.Visible = false;
                                        tbxIP4.Visible = false;
                                        NomDestinataireToolStripMenuItem.Text = "Recipient : " + sNameDestinataire;
                                        lblNomPCDest.Visible = false;
                                        iPPersonnelToolStripMenuItem.Text    = "My IP : " + lblIPPersonnel.Text;
                                        iPPersonnelToolStripMenuItem.Visible = true;
                                        //______________________________________________
                                        //FichierConfig---------------------------------
                                        if (XmlManipulation.GetValue("EnableLastIpConnexion") == "ON")
                                        {
                                            XmlManipulation.ModifyElementXml("LastIpConnexion", sIpDestinataire);
                                        }
                                        else
                                        {
                                            XmlManipulation.ModifyElementXml("LastIpConnexion", "");
                                        }
                                        _recipientIp = sIpDestinataire;
                                        try
                                        {
                                            _epLocal = new IPEndPoint(IPAddress.Parse(lblIPPersonnel.Text), 3056);//Use 3056 port
                                            _sck.Bind(_epLocal);

                                            _epRemote = new IPEndPoint(IPAddress.Parse(sIpDestinataire), 3056);
                                            _sck.Connect(_epRemote);

                                            var buffer = new byte[1500];
                                            _sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref _epRemote, MessageReceived, buffer);

                                            btnSart.Text     = @"Connected";
                                            btnSart.Enabled  = false;
                                            btnEnvoi.Enabled = true;
                                            tbxMessageEnvoit.Focus();
                                            EnvoiDuMessage("tuiFZCz56786casdcssdcvuivgboRTSDetre67Rz7463178", KMessage.Type.Init());
                                            if (XmlManipulation.GetValue("SaveDiscussion") == "ON")
                                            {
                                                var temp = ChatData.Import(_recipientIp);
                                                if (temp.Count() != 0)
                                                {
                                                    foreach (var element in temp)
                                                    {
                                                        lbxTchat.Items.Add(element);
                                                    }
                                                }
                                            }
                                        }
                                        catch
                                        {
                                            MessageBox.Show("An error occured. \r\nPlease restart Kubeah Chat" + "\r\n" + "\r\n", "An error occurred");
                                            Application.Exit();
                                        }
                                        //Send the key to the other client to connect
                                    }
                                }
                                else
                                {
                                    lblEtatPing.Text      = "Ping : Fail";
                                    lblEtatPing.ForeColor = Color.Red;
                                    lblNomPCDest.Visible  = false;
                                    tbxIP4.BackColor      = Color.Red;
                                }
                            }
                        }
                    }
                }
            }
            lblPatience.Visible = false;
        }