예제 #1
0
        private void CloseAllOpenConnections(LinqDataContext ctx)
        {
            ctx.Log = new StringWriter();

            if (ctx.DatabaseExists())
            {
                //drop all connections by disabling multi-user (and immediatly abort all current transactions)
                ctx.ExecuteCommand("ALTER DATABASE " + _databaseName + " SET SINGLE_USER WITH ROLLBACK IMMEDIATE");
                //re-enable multi-user
                ctx.ExecuteCommand("ALTER DATABASE " + _databaseName + " SET MULTI_USER");
            }
        }
예제 #2
0
 private void DeleteExsistingOrder()
 {
     using (var ctx = new System.Data.Linq.DataContext(Central.SpecialConnStr))
     {
         ctx.ExecuteCommand("delete from objects where id={0}", _bar.Id);
     }
 }
예제 #3
0
        static CreateTable()
        {
            var context = new System.Data.Linq.DataContext(Conexion.Connection);

            // Crear Tabla Por la Aplicacion.

            // CREATE TABLE[TAcciones]
            context.ExecuteCommand("CREATE TABLE[TAcciones] ([idAcciones] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,[fkCliente] INTEGER NOT NULL,[fkTipoAccion] INTEGER NOT NULL,[FechaAccion] DATE DEFAULT CURRENT_DATE NULL,[FechaRecordar] DATE DEFAULT CURRENT_DATE NULL,[Comentario] TEXT NULL);");
            // CREATE TABLE[TCliente]
            context.ExecuteCommand("CREATE TABLE [TCliente] ([idCliente] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,[Nombre] varCHAR(30)  NOT NULL,[Apellido] VARCHAR(30)  NOT NULL,[Cedula] VARCHAR(30)  UNIQUE NULL,[fkDireccion] INTEGER  NULL,[Telefono] varchar(30)  NULL,[Email] varCHAR(30)  NULL,[Estatu] INTEGER  NULL);");
            // CREATE TABLE[TDireccion]
            context.ExecuteCommand("CREATE TABLE[TDireccion] ([idDireccion] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,[pais] varCHAR(30)  NOT NULL,[Ciudad] VARCHAR(30)  NOT NULL,[Municipio] vaRCHAR(30)  NULL,[Barrio] vaRCHAR(30)  NULL,[Calle] varCHAR(15)  NULL,[numCasa] INTEGER(4)  NULL,[Detalles] varchar(9)  NULL); ");
            // CREATE TABLE[TTipoAccion]
            context.ExecuteCommand("CREATE TABLE[TTipoAccion] ([idTipoAccion] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,[Descripcion] VARCHAR(60)  NOT NULL); ");
            // CREATE TABLE[TUsuario]
            context.ExecuteCommand("CREATE TABLE[TUsuario] ([idUsuario] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,[Usuario] VARCHAR(30)  UNIQUE NOT NULL,[Clave] VARCHAR(30)  NOT NULL,[fkUsuario] INTEGER Null); ");
        }
예제 #4
0
        public void DeleteAll()
        {
            System.Configuration.ConnectionStringSettingsCollection connectionStrings =
                WebConfigurationManager.ConnectionStrings as ConnectionStringSettingsCollection;

            if (connectionStrings.Count > 0)
            {
                System.Data.Linq.DataContext db = new System.Data.Linq.DataContext(connectionStrings["ConnectionString"].ConnectionString);

                db.ExecuteCommand("TRUNCATE TABLE Employees");
            }
        }
예제 #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            Dates  = dtpFrom.Value;
            Motivo = textBox1.Text;

            using (var ctx = new System.Data.Linq.DataContext(Central.ConnStr))
            {
                ctx.ExecuteCommand("update comenzi set DateControlled={0}, Motivo={1} where Id={2}", Dates, Motivo, Id);
            }
            DialogResult = DialogResult.OK;
            Close();
        }
예제 #6
0
        /// <summary>
        /// Execute an SQL command directly to the database.
        /// </summary>
        /// <param name="dataContext">The data context to the database.</param>
        /// <param name="sqlCommand">The sql command to execute to the database.</param>
        /// <param name="values">The parameter values for the command, can be null.</param>
        /// <returns>A value indicating the result of the command.</returns>
        /// <exception cref="System.ArgumentNullException"></exception>
        public static Int32 ExecuteCommand(System.Data.Linq.DataContext dataContext,
                                           string sqlCommand, params object[] values)
        {
            // Check to see if the critical parameters
            // have been set, throw exception on each.
            if (sqlCommand == null)
            {
                throw new ArgumentNullException("sqlCommand");
            }

            // Execute the command and return
            // the result from the command.
            return(dataContext.ExecuteCommand(sqlCommand, values));
        }
예제 #7
0
        public void DeleteAll()
        {
            using (PersonsDBEntities pb = conn.GetContext())
            {
                System.Configuration.ConnectionStringSettingsCollection connectionStrings =
                    WebConfigurationManager.ConnectionStrings as ConnectionStringSettingsCollection;

                if (connectionStrings.Count > 0)
                {
                    System.Data.Linq.DataContext db = new System.Data.Linq.DataContext(connectionStrings["ConnectionString"].ConnectionString);

                    db.ExecuteCommand("TRUNCATE TABLE Department");
                }
            }
        }
예제 #8
0
        private void PbCloseOrder_Click(object sender, EventArgs e)
        {
            if (Workflow.TargetClosedByUser)
            {
                var dr = MessageBox.Show("Are you sure you want to recover this order?", "Workflow controller", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (dr == DialogResult.Yes)
                {
                    using (var ctx = new System.Data.Linq.DataContext(Central.SpecialConnStr))
                    {
                        ctx.ExecuteCommand("update objects set closedord='false' where ordername={0} and aim={1} and department={2}",
                                           Workflow.TargetOrder, Workflow.TargetLine, Workflow.TargetDepartment);
                    }
                    var c = new Central();
                    c.GetBase();

                    Close();
                }
            }
            else
            {
                var dr = MessageBox.Show("Are you sure you want to close this order?", "Workflow controller", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (dr == DialogResult.Yes)
                {
                    using (var ctx = new System.Data.Linq.DataContext(Central.SpecialConnStr))
                    {
                        ctx.ExecuteCommand("update objects set closedord='true' where ordername={0} and aim={1}",
                                           Workflow.TargetOrder, Workflow.TargetLine);
                    }
                    var c = new Central();
                    c.GetBase();

                    Close();
                }
            }
        }
예제 #9
0
 public int ExecuteCommand(string sql)
 {
     UserEngine.SessionTimeOut();
     return(Standard.ExecuteCommand(sql));
 }
예제 #10
0
        private void SaveData()
        {
            var selectedDate = dtpCommData.Value;

            tableView1.Invalidate();
            tableView1.EndEdit();
            var groupForDelete = from prod in Tables.Productions
                                 where prod.Commessa == Workflow.TargetOrder &&
                                 prod.Line == Workflow.TargetLine &&
                                 prod.Department == Workflow.TargetDepartment
                                 select prod;
            var items = groupForDelete.ToList();

            foreach (var item in items)
            {
                Tables.Productions.DeleteOnSubmit(item);
            }
            Config.GetGanttConn().SubmitChanges();
            if (!string.IsNullOrEmpty(txtCommCapi.Text) && !string.IsNullOrEmpty(txtPersone.Text))
            {
                bool wantToSave = true;
                if (!_deleting && selectedDate.DayOfWeek == DayOfWeek.Saturday || selectedDate.DayOfWeek == DayOfWeek.Sunday)
                {
                    var diag = MessageBox.Show("Are you sure you want to add production for " +
                                               selectedDate.DayOfWeek.ToString() + "?", "Workflow controller", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    wantToSave = diag == DialogResult.Yes ? true : false;
                }
                if (!wantToSave)
                {
                    return;
                }
                InsertNewRecord();
                txtCommCapi.Text = "";
                txtCommCapi.Focus();
            }

            lblSavedInfo.Visible  = true;
            lblSavedInfo.Location = new Point(Width / 2 - lblSavedInfo.Width / 2, lblSavedInfo.Location.Y);
            lblSavedInfo.BringToFront();
            lblSavedInfo.Refresh();

            foreach (DataRow dr in _dtComm.Rows)
            {
                int.TryParse(dr[9].ToString(), out var dQ);
                double.TryParse(dr[10].ToString(), out var price);
                bool.TryParse(dr[11].ToString(), out var incHours);
                int.TryParse(dr[12].ToString(), out var abatim);
                double.TryParse(dr[13].ToString(), out var qtyH);
                var shift = dr[14].ToString();
                double.TryParse(dr[15].ToString(), out var settingHours);

                var pd = new Production
                {
                    Data         = Convert.ToDateTime(dr[1].ToString()),
                    Commessa     = dr[2].ToString(),
                    Capi         = Convert.ToInt32(dr[3]),
                    Line         = dr[4].ToString(),
                    Members      = Convert.ToInt32(dr[5]),
                    Department   = dr[6].ToString(),
                    Abovenormal  = Convert.ToBoolean(dr[7]),
                    Times        = Convert.ToDateTime(dr[8].ToString()),
                    Dailyqty     = dQ,
                    Price        = price,
                    IncludeHours = incHours,
                    Abatim       = abatim,
                    QtyH         = qtyH,
                    Shift        = shift,
                    SettingHours = settingHours,
                };
                Tables.Productions.InsertOnSubmit(pd);
            }
            try
            {
                Config.GetGanttConn().SubmitChanges();
                if (tableView1.Rows.Count <= 0)
                {
                    using (var context = new System.Data.Linq.DataContext(Central.SpecialConnStr))
                    {
                        context.ExecuteCommand("update objects set " +
                                               "startprod={0},endprod={1},prodqty={2},delayts={3}, delaystart={4},delayend={5} " +
                                               "where ordername={6} and aim={7} and department={8}",
                                               0L,
                                               0L,
                                               0L, 0L, 0L, 0L,
                                               Workflow.TargetOrder, Workflow.TargetLine, Workflow.TargetDepartment);
                    }
                }
                else
                {
                    var jMod = new JobModel();
                    jMod.GetJobContinum(Workflow.TargetOrder, Workflow.TargetLine, Workflow.TargetDepartment);
                }

                var menu = new Central();
                menu.GetBase();
            }
            catch (Exception ex)
            {
                lblSavedInfo.Visible = false;
                lblSavedInfo.Refresh();
                MessageBox.Show(ex.Message);
            }
            if (Width < 700)
            {
                Close();
            }
            else
            {
                ShowProductionDateRange();
                System.Threading.Thread.Sleep(200);
                lblSavedInfo.Visible = false;
                lblSavedInfo.Refresh();
            }
        }
예제 #11
0
        public object[] GetJobContinum(string job,
                                       string aim, string dept)
        {
            //object[] obj = new object[] { };
            var production = from prod in Models.Tables.Productions
                             where prod.Commessa == job &&
                             prod.Line == aim && prod.Department == dept
                             orderby prod.Data
                             select prod;

            var jobMod = Central.TaskList.SingleOrDefault(x => x.Name == job && x.Aim == aim && x.Department == dept);
            var jobModEndProduction = jobMod.ProductionEndDate.Date;

            int.TryParse(jobMod.WorkingDays.ToString(), out var jobWorkingDays);

            var prodStart = production.ToList().Count > 0 ?
                            production.ToList().First().Data : new DateTime();
            var prodEnd = production.ToList().Count > 0 ?
                          production.ToList().Last().Times : new DateTime();

            if (production.ToList().Count == 0)
            {
                return(new object[] { prodStart, prodEnd,
                                      0, 0, 0, new TimeSpan(0, 0, 0, 0, 0), new TimeSpan(0, 0, 0, 0, 0) });
            }
            var prodOverDays = 0.0;
            var lastDate     = DateTime.MinValue;
            var startShift   = Central.ShiftFrom.Hours;
            var endShift     = Central.ShiftTo.Hours;
            var shiftRange   = Central.ShiftTo.Subtract(Central.ShiftTo).TotalHours;
            var dymDailyQty  = 0;
            var dymQty       = 0.0;
            var dymOverQty   = 0.0;
            var dymAlertTime = new TimeSpan(0, 0, 0, 0, 0);
            var dymOverTime  = new TimeSpan(0, 0, 0, 0, 0);

            foreach (var prod in production)
            {
                if (lastDate != prod.Data.Date)
                {
                    int.TryParse(prod.Dailyqty.ToString(), out var q);
                    dymDailyQty += q;
                }
                lastDate = prod.Data.Date;
                dymQty  += prod.Capi;
            }
            var restQty = 0.0;

            restQty = (dymDailyQty - dymQty);
            if (restQty <= 0)
            {
                dymAlertTime = new TimeSpan(0, 0, 0, 0, 0);
            }
            else
            {
                var hour = Convert.ToInt32(GetHoursBySector());
                var r    = Convert.ToInt32(restQty / 60);
                var dd   = r / hour;
                var hh   = r % hour;
                if (Math.Floor(Convert.ToDecimal(dd)) == 0)
                {
                    dd = 0;
                }
                dymAlertTime = new TimeSpan(dd, startShift + hh, 0, 0, 0);
                if (dd == 0 && hh == 0)
                {
                    dymAlertTime = new TimeSpan(0, 0, 0, 0, 0);
                }
            }

            var obj = new object[]
            {
                prodStart, prodEnd, dymQty, prodOverDays, dymOverQty, dymOverTime, dymAlertTime
            };

            DateTime.TryParse(prodEnd.ToString(), out var endDate);
            if (endDate.Date > jobModEndProduction)
            {
                jobWorkingDays += 1;
            }
            using (var context = new System.Data.Linq.DataContext(Central.SpecialConnStr))
            {
                context.ExecuteCommand("update objects set " +
                                       "startprod={0},endprod={1},prodqty={2},delayts={3}, delaystart={4},delayend={5}, workingdays={9} " +
                                       "where ordername={6} and aim={7} and department={8}",
                                       GetLSpan(prodStart),
                                       GetLSpan(endDate),
                                       dymQty,
                                       dymAlertTime.Ticks,
                                       GetLSpan(endDate),
                                       GetLSpan(endDate) + dymAlertTime.Ticks,
                                       job, aim, dept, jobWorkingDays);
            }
            return(obj);
        }
예제 #12
0
        private void CloseAllOpenConnections(LinqDataContext ctx)
        {
            ctx.Log = new StringWriter();

            if (ctx.DatabaseExists())
            {
                //drop all connections by disabling multi-user (and immediatly abort all current transactions)
                ctx.ExecuteCommand("ALTER DATABASE " + _databaseName + " SET SINGLE_USER WITH ROLLBACK IMMEDIATE");
                //re-enable multi-user
                ctx.ExecuteCommand("ALTER DATABASE " + _databaseName + " SET MULTI_USER");
            }

        }